Sync MITRE ATT&CK Data #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/update-mitre-data.yml | |
| name: Sync MITRE ATT&CK Data | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' # Runs daily at 2:00 AM UTC | |
| workflow_dispatch: # Allows manual trigger | |
| jobs: | |
| sync-mitre: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r echo-attack-dashboard/get_mitre_data/requirements.txt | |
| - name: Run MITRE data update script | |
| run: | | |
| cd echo-attack-dashboard/get_mitre_data | |
| python main.py | |
| - name: Commit and push changes | |
| env: | |
| TOKEN: ${{ secrets.TOKEN }} | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add echo-attack-dashboard/data/*.json | |
| git diff --cached --quiet && echo "No changes to commit" && exit 0 | |
| git commit -m "Update MITRE ATT&CK group data [auto]" | |
| # Use token for authentication | |
| git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}.git | |
| set -e | |
| if ! git push origin HEAD:${GITHUB_REF#refs/heads/}; then | |
| echo "[INFO] Push to main failed. Creating a pull request." | |
| BRANCH_NAME="mitre-update-$(date +'%Y%m%d%H%M%S')" | |
| git checkout -b "$BRANCH_NAME" | |
| git push origin "$BRANCH_NAME" | |
| # Install GitHub CLI if not present | |
| if ! command -v gh &> /dev/null; then | |
| echo "Installing GitHub CLI..." | |
| sudo apt-get update && sudo apt-get install -y gh | |
| fi | |
| # Authenticate gh CLI | |
| echo "${TOKEN}" | gh auth login --with-token | |
| gh pr create \ | |
| --title "Update MITRE ATT&CK group data [auto]" \ | |
| --body "Automated update of MITRE ATT&CK group data." \ | |
| --base "${GITHUB_REF#refs/heads/}" \ | |
| --head "$BRANCH_NAME" \ | |
| --repo "${{ github.repository }}" | |
| exit 0 | |
| fi |