Skip to content

Commit a36276f

Browse files
Merge pull request #25678 from ashley-cui/mach-os-pr
GHA: Open PR to podman-machine-os on releases
2 parents 71ed3f0 + 6e28bdc commit a36276f

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

.github/workflows/machine-os-pr.yml

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: "Machine OS PR"
2+
3+
on:
4+
pull_request_target:
5+
# prevent action from running on older release-process branches
6+
# TODO: remove when we move to new release flow
7+
branches:
8+
- 'v5.5'
9+
- 'main'
10+
paths:
11+
- 'version/rawversion/version.go'
12+
13+
concurrency:
14+
# Cancel other in-progress runs on re-pushes
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
podman-image-build-pr:
20+
name: Open PR on podman-machine-os
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
issues: write
25+
pull-requests: write
26+
env:
27+
SHA: ${{github.event.pull_request.head.sha}}
28+
UPSTREAM_MACHINE_OS: "containers/podman-machine-os"
29+
PODMAN_REPO: "containers/podman"
30+
steps:
31+
32+
- name: Get version
33+
id: getversion
34+
run: |
35+
VERSION=$(curl "https://raw.githubusercontent.com/$PODMAN_REPO/$SHA/version/rawversion/version.go" | sed -n 's/^const RawVersion = \"\(.*\)\"$/\1/p')
36+
# ignore -dev version bumps unless on main
37+
if [[ ${{github.base_ref}} != "main" ]] && [[ $VERSION == *-dev ]] ; then
38+
echo "::warning:: SKIPPING: dev bump not on main"
39+
elif [[ ${{github.base_ref}} == *-rhel ]] ; then
40+
echo "::warning:: SKIPPING: rhel branch"
41+
else
42+
echo "update=true" >> "$GITHUB_OUTPUT"
43+
fi
44+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45+
46+
- name: Check machine-os-branch
47+
if: steps.getversion.outputs.update == 'true'
48+
run: |
49+
if ! (curl -s https://api.github.com/repos/$UPSTREAM_MACHINE_OS/branches| jq -e --arg branch "${{github.base_ref}}" '.[] | select(.name==$branch)') ; then
50+
echo "::error:: Release branch does not exist."
51+
echo "::error:: Please push $branch to $UPSTREAM_MACHINE_OS, then re-run this task."
52+
exit 1
53+
fi
54+
55+
- name: Label
56+
if: steps.getversion.outputs.update == 'true'
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
GH_REPO: ${{ github.repository }}
60+
run: |
61+
gh pr edit --add-label do-not-merge/wait-machine-os-build ${{github.event.number}}
62+
63+
- name: Install wait-for-copr
64+
if: steps.getversion.outputs.update == 'true'
65+
run: |
66+
pip3 install git+https://github.com/packit/wait-for-copr.git@main
67+
68+
- uses: actions/checkout@v4
69+
if: steps.getversion.outputs.update == 'true'
70+
id: checkout
71+
with:
72+
repository: containers/podman-machine-os
73+
ref: ${{github.base_ref}}
74+
token: ${{secrets.PODMANBOT_TOKEN}}
75+
76+
- name: Bump version
77+
if: steps.getversion.outputs.update == 'true'
78+
run: |
79+
echo ${{steps.getversion.outputs.version}}
80+
sed -i 's/export PODMAN_VERSION=".*"/export PODMAN_VERSION="${{steps.getversion.outputs.version}}"/g' podman-rpm-info-vars.sh
81+
sed -i 's/export PODMAN_PR_NUM=".*"/export PODMAN_PR_NUM="${{github.event.number}}"/g' podman-rpm-info-vars.sh
82+
echo "Updated file:"
83+
cat podman-rpm-info-vars.sh
84+
85+
- name: Wait for COPR build
86+
if: steps.getversion.outputs.update == 'true'
87+
run: |
88+
wait-for-copr \
89+
--owner packit \
90+
--project containers-podman-${{github.event.number}} \
91+
podman \
92+
${SHA::9}
93+
94+
- name: Push
95+
if: steps.getversion.outputs.update == 'true'
96+
run: |
97+
# Make committer the user who triggered the action, either through cutting a release or manual trigger
98+
# GitHub gives everyone a noreply email associated with their account, use that email for the sign-off
99+
git config --local user.name ${{ github.actor }}
100+
git config --local user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
101+
bumpbranch="pr${{github.event.number}}"
102+
git checkout -b $bumpbranch
103+
git add podman-rpm-info-vars.sh
104+
git commit --signoff -m "Bump Podman to v${{ steps.getversion.outputs.version }}"
105+
git remote add podmanbot https://github.com/podmanbot/podman-machine-os
106+
git push -f podmanbot "$bumpbranch"
107+
108+
- name: Check open PRs
109+
id: checkpr
110+
if: steps.getversion.outputs.update == 'true'
111+
run: |
112+
prs=$(gh pr list \
113+
--repo $UPSTREAM_MACHINE_OS \
114+
--head "pr${{github.event.number}}" \
115+
--state open \
116+
--json title \
117+
--jq 'length')
118+
if ((prs > 0)); then
119+
echo "::notice:: SKIPPING: PR already exists. Re-pushed to re-trigger build."
120+
else
121+
echo "openpr=true" >> "$GITHUB_OUTPUT"
122+
fi
123+
env:
124+
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
125+
126+
- name: Open PR
127+
if: steps.getversion.outputs.update == 'true' && steps.checkpr.outputs.openpr == 'true'
128+
id: pr
129+
run: |
130+
bumpbranch="pr${{github.event.number}}"
131+
uri=`gh pr create \
132+
--title "Bump Podman to v${{ steps.getversion.outputs.version }}" \
133+
--body "Triggered by https://github.com/$PODMAN_REPO/pull/${{github.event.number}}" \
134+
--head "podmanbot:$bumpbranch" \
135+
--base "${{github.base_ref}}" \
136+
--repo $UPSTREAM_MACHINE_OS`
137+
echo "uri=$uri" >> "$GITHUB_OUTPUT"
138+
env:
139+
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
140+
141+
- name: Comment PR link
142+
if: steps.getversion.outputs.update == 'true' && steps.checkpr.outputs.openpr == 'true'
143+
uses: thollander/actions-comment-pull-request@v3
144+
with:
145+
message: "Building images at: ${{ steps.pr.outputs.uri }}"

0 commit comments

Comments
 (0)