Skip to content

Commit 7f0c37c

Browse files
committed
ci: automate release info update PRs
1 parent c93b50f commit 7f0c37c

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Update ATT&CK Release Info PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
attack_version:
7+
description: ATT&CK version to update, for example 19.1. If omitted, the latest matching STIX releases are used.
8+
required: false
9+
type: string
10+
source_repo:
11+
description: Repository that triggered this update.
12+
required: false
13+
type: string
14+
source_release_url:
15+
description: Release URL that triggered this update.
16+
required: false
17+
type: string
18+
schedule:
19+
- cron: "17 * * * *"
20+
21+
permissions:
22+
contents: read
23+
24+
concurrency:
25+
group: update-release-info-pr
26+
cancel-in-progress: false
27+
28+
jobs:
29+
update-release-info:
30+
name: Update release_info.py
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Create GitHub App token
35+
id: app-token
36+
uses: actions/create-github-app-token@v3
37+
with:
38+
client-id: ${{ vars.ATTACK_AUTOBOT_CLIENT_ID }}
39+
private-key: ${{ secrets.ATTACK_AUTOBOT_PRIVATE_KEY }}
40+
41+
- name: Check out repository
42+
uses: actions/checkout@v6
43+
with:
44+
token: ${{ steps.app-token.outputs.token }}
45+
persist-credentials: false
46+
47+
- name: Install uv
48+
uses: astral-sh/setup-uv@v7
49+
with:
50+
python-version: "3.11"
51+
52+
- name: Install dependencies
53+
run: uv sync --all-extras
54+
55+
- name: Update release info
56+
id: update
57+
env:
58+
ATTACK_VERSION: ${{ github.event.inputs.attack_version || '' }}
59+
run: |
60+
if [[ -n "${ATTACK_VERSION}" ]]; then
61+
uv run --extra dev python scripts/update_release_info.py "${ATTACK_VERSION}"
62+
else
63+
uv run --extra dev python scripts/update_release_info.py
64+
fi
65+
66+
version="$(
67+
uv run --extra dev python -c 'from mitreattack.release_info import LATEST_VERSION; print(LATEST_VERSION)'
68+
)"
69+
70+
if git diff --quiet -- mitreattack/release_info.py; then
71+
echo "changed=false" >> "${GITHUB_OUTPUT}"
72+
echo "version=${version}" >> "${GITHUB_OUTPUT}"
73+
echo "release_info.py is already current for ATT&CK v${version}."
74+
exit 0
75+
fi
76+
77+
echo "changed=true" >> "${GITHUB_OUTPUT}"
78+
echo "version=${version}" >> "${GITHUB_OUTPUT}"
79+
80+
- name: Verify updated files
81+
if: steps.update.outputs.changed == 'true'
82+
run: uv run --extra dev ruff check scripts/update_release_info.py mitreattack/release_info.py
83+
84+
- name: Create pull request
85+
if: steps.update.outputs.changed == 'true'
86+
env:
87+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
88+
VERSION: ${{ steps.update.outputs.version }}
89+
SOURCE_REPO: ${{ github.event.inputs.source_repo || '' }}
90+
SOURCE_RELEASE_URL: ${{ github.event.inputs.source_release_url || '' }}
91+
run: |
92+
branch="automation/update-release-info-${VERSION}"
93+
title="chore: update ATT&CK release metadata for ${VERSION}"
94+
95+
git config user.name "attack-autobot[bot]"
96+
git config user.email "attack-autobot[bot]@users.noreply.github.com"
97+
git checkout -B "${branch}"
98+
git add mitreattack/release_info.py
99+
git commit -m "${title}"
100+
git push --force-with-lease "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "${branch}"
101+
102+
body_file="$(mktemp)"
103+
{
104+
echo "Updates \`mitreattack/release_info.py\` for ATT&CK v${VERSION} after the STIX release assets were published."
105+
echo
106+
echo "The updater refreshed:"
107+
echo
108+
echo "- \`LATEST_VERSION\`"
109+
echo "- \`STIX20[\"enterprise\"]\`, \`STIX20[\"mobile\"]\`, and \`STIX20[\"ics\"]\`"
110+
echo "- \`STIX21[\"enterprise\"]\`, \`STIX21[\"mobile\"]\`, and \`STIX21[\"ics\"]\`"
111+
echo
112+
echo "Verification:"
113+
echo
114+
echo "- \`uv run --extra dev ruff check scripts/update_release_info.py mitreattack/release_info.py\`"
115+
if [[ -n "${SOURCE_REPO}" ]]; then
116+
echo
117+
echo "Triggered by: \`${SOURCE_REPO}\`"
118+
fi
119+
if [[ -n "${SOURCE_RELEASE_URL}" ]]; then
120+
echo "Source release: ${SOURCE_RELEASE_URL}"
121+
fi
122+
} > "${body_file}"
123+
124+
if gh pr view "${branch}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
125+
gh pr edit "${branch}" \
126+
--repo "${GITHUB_REPOSITORY}" \
127+
--title "${title}" \
128+
--body-file "${body_file}"
129+
else
130+
gh pr create \
131+
--repo "${GITHUB_REPOSITORY}" \
132+
--base main \
133+
--head "${branch}" \
134+
--title "${title}" \
135+
--body-file "${body_file}"
136+
fi

0 commit comments

Comments
 (0)