Skip to content

Commit 522911c

Browse files
committed
Updating kernel release workflow
We no longer like the workflow writing to our repo
1 parent f1043c4 commit 522911c

1 file changed

Lines changed: 65 additions & 11 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ on:
1919
jobs:
2020
release-packager:
2121
permissions:
22+
contents: write
23+
pull-requests: write
2224
id-token: write
2325
name: Release Packager
2426
runs-on: ubuntu-latest
@@ -31,6 +33,16 @@ jobs:
3133
env:
3234
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3335

36+
- name: Install GitHub CLI
37+
run: |
38+
command -v gh >/dev/null 2>&1 || {
39+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
40+
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
41+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
42+
sudo apt update
43+
sudo apt install gh
44+
}
45+
3446
# Currently FreeRTOS/.github/scripts houses the release script. Download it for upcoming usage
3547
- name: Checkout FreeRTOS Release Tools
3648
uses: actions/checkout@v4.1.1
@@ -52,13 +64,13 @@ jobs:
5264
git config --global user.name "$ACTOR"
5365
git config --global user.email "$ACTOR"@users.noreply.github.com
5466
55-
- name: create a new branch that references commit id
67+
- name: Create release preparation branch
5668
env:
5769
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
5870
COMMIT_ID: ${{ github.event.inputs.commit_id }}
5971
working-directory: ./local_kernel
6072
run: |
61-
git checkout -b "$VERSION_NUMBER" "$COMMIT_ID"
73+
git checkout -b "release-prep-$VERSION_NUMBER" "$COMMIT_ID"
6274
echo "COMMIT_SHA_1=$(git rev-parse HEAD)" >> $GITHUB_ENV
6375
6476
- name: Update source files with version info
@@ -73,37 +85,77 @@ jobs:
7385
./tools/.github/scripts/update_src_version.py FreeRTOS --kernel-repo-path=local_kernel --kernel-commit="$COMMIT_SHA_1" --new-kernel-version="$VERSION_NUMBER" --new-kernel-main-br-version="$MAIN_BR_VERSION_NUMBER"
7486
exit $?
7587
76-
- name : Update version number in manifest.yml
88+
- name: Update version number in manifest.yml
7789
env:
7890
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
7991
working-directory: ./local_kernel
8092
run: |
8193
./.github/scripts/manifest_updater.py -v "$VERSION_NUMBER"
8294
exit $?
8395
84-
- name : Commit version number change in manifest.yml
96+
- name: Commit and push release preparation branch
8597
env:
8698
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
8799
working-directory: ./local_kernel
88100
run: |
89101
git add .
90-
git commit -m '[AUTO][RELEASE]: Update version number in manifest.yml'
91-
git push -u origin "$VERSION_NUMBER"
102+
git commit -m '[AUTO][RELEASE]: Update version number in manifest.yml and source files'
103+
git push -u origin "release-prep-$VERSION_NUMBER"
104+
105+
- name: Create pull request
106+
env:
107+
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
108+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
working-directory: ./local_kernel
110+
run: |
111+
PR_URL=$(gh pr create \
112+
--base main \
113+
--head "release-prep-$VERSION_NUMBER" \
114+
--title "[AUTO][RELEASE]: Release $VERSION_NUMBER" \
115+
--body "Automated release preparation for $VERSION_NUMBER. Updates version numbers in source files and manifest.yml.")
116+
echo "PR_URL=$PR_URL" >> $GITHUB_ENV
117+
118+
- name: Wait for PR to be merged
119+
env:
120+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121+
working-directory: ./local_kernel
122+
run: |
123+
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
124+
while true; do
125+
STATE=$(gh pr view "$PR_NUMBER" --json state --jq .state)
126+
if [ "$STATE" = "MERGED" ]; then
127+
echo "PR merged successfully"
128+
break
129+
elif [ "$STATE" = "CLOSED" ]; then
130+
echo "Error: PR was closed without merging"
131+
exit 1
132+
fi
133+
echo "Waiting for PR to be merged... (current state: $STATE)"
134+
sleep 30
135+
done
136+
137+
- name: Re-checkout after merge
138+
uses: actions/checkout@v4.1.1
139+
with:
140+
path: local_kernel
141+
ref: main
142+
fetch-depth: 0
92143

93144
- name: Generate SBOM
94145
uses: FreeRTOS/CI-CD-Github-Actions/sbom-generator@main
95146
with:
96147
repo_path: ./local_kernel
97148
source_path: ./
98149

99-
- name: commit SBOM file
150+
- name: Commit SBOM file
100151
env:
101152
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
102153
working-directory: ./local_kernel
103154
run: |
155+
git checkout -b "release-$VERSION_NUMBER"
104156
git add .
105157
git commit -m '[AUTO][RELEASE]: Update SBOM'
106-
git push -u origin "$VERSION_NUMBER"
158+
git push -u origin "release-$VERSION_NUMBER"
107159
echo "COMMIT_SHA_2=$(git rev-parse HEAD)" >> $GITHUB_ENV
108160
109161
- name: Release
@@ -127,10 +179,12 @@ jobs:
127179
artifact_path: ./FreeRTOS-KernelV${{ github.event.inputs.version_number }}.zip
128180
release_tag: ${{ github.event.inputs.version_number }}
129181

130-
- name: Cleanup
182+
- name: Delete release preparation branch
183+
if: always()
131184
env:
132185
VERSION_NUMBER: ${{ github.event.inputs.version_number }}
186+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133187
working-directory: ./local_kernel
134188
run: |
135-
# Delete the branch created for Tag by SBOM generator
136-
git push -u origin --delete "$VERSION_NUMBER"
189+
git push origin --delete "release-prep-$VERSION_NUMBER" || true
190+
git push origin --delete "release-$VERSION_NUMBER" || true

0 commit comments

Comments
 (0)