Skip to content

Commit e1157df

Browse files
committed
fix: add update manifest action
1 parent 12937ef commit e1157df

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

.github/workflows/release.yaml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, closed]
9+
branches:
10+
- main
711

812
concurrency:
913
group: release
@@ -24,27 +28,42 @@ jobs:
2428
manifest-file: ".github/prerelease-manifest.json"
2529
fork: false
2630
token: ${{ secrets.GITHUB_TOKEN }}
27-
31+
32+
update-manifest-in-pr:
33+
runs-on: ubuntu-latest
34+
needs: release-please
35+
# Only run when a release PR is opened or updated, not when it's merged
36+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref == 'release-please--branches--main' && github.event.pull_request.closed == false }}
37+
steps:
2838
- name: Checkout PR branch
29-
if: ${{ steps.release.outputs.pr }}
3039
uses: actions/checkout@v4
3140
with:
32-
ref: release-please--branches--main
41+
ref: ${{ github.event.pull_request.head.ref }}
3342
token: ${{ secrets.GITHUB_TOKEN }}
34-
35-
- name: Update prerelease manifest
36-
if: ${{ steps.release.outputs.pr }}
43+
44+
- name: Extract new version
45+
id: extract-version
46+
run: |
47+
PR_TITLE="${{ github.event.pull_request.title }}"
48+
if [[ $PR_TITLE =~ chore\(main\):[[:space:]]release[[:space:]]([0-9]+\.[0-9]+\.[0-9]+) ]]; then
49+
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
50+
else
51+
echo "version=" >> $GITHUB_OUTPUT
52+
fi
53+
54+
- name: Update prerelease manifest with new version
55+
if: ${{ steps.extract-version.outputs.version != '' }}
3756
env:
3857
MANIFEST_PATH: .github/prerelease-manifest.json
39-
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
58+
VERSION: ${{ steps.extract-version.outputs.version }}
4059
run: |
41-
jq --arg tag "${RELEASE_TAG//v/}" '.["."] = $tag' $MANIFEST_PATH > temp.json \
60+
jq --arg tag "$VERSION" '.["."] = $tag' $MANIFEST_PATH > temp.json \
4261
&& mv temp.json $MANIFEST_PATH
4362
4463
git config user.name "github-actions[bot]"
4564
git config user.email "github-actions[bot]@users.noreply.github.com"
4665
git add $MANIFEST_PATH
47-
git commit -m "chore: sync release manifests"
66+
git commit -m "chore: update prerelease manifest with version $VERSION"
4867
git push
4968
5069
deploy-test:
@@ -97,6 +116,35 @@ jobs:
97116
98117
- name: Deploy
99118
run: echo "Deploying to production!"
119+
120+
sync-after-release:
121+
name: Sync Release Manifest
122+
runs-on: ubuntu-latest
123+
# Only run when a release is created and PR is merged (push to main)
124+
if: ${{ github.event_name == 'push' && needs.release-please.outputs.releases_created == 'true' }}
125+
needs: release-please
126+
steps:
127+
- name: Checkout main branch
128+
uses: actions/checkout@v4
129+
with:
130+
token: ${{ secrets.RELEASE_TOKEN }} # Use a token with repo scope
131+
132+
- name: Update prerelease manifest
133+
env:
134+
MANIFEST_PATH: .github/prerelease-manifest.json
135+
RELEASE_TAG: ${{ needs.release-please.outputs.tag_name }}
136+
run: |
137+
# Remove the 'v' prefix if present
138+
VERSION="${RELEASE_TAG//v/}"
139+
140+
jq --arg tag "$VERSION" '.["."] = $tag' $MANIFEST_PATH > temp.json \
141+
&& mv temp.json $MANIFEST_PATH
142+
143+
git config user.name "github-actions[bot]"
144+
git config user.email "github-actions[bot]@users.noreply.github.com"
145+
git add $MANIFEST_PATH
146+
git commit -m "chore: sync prerelease manifest with version $VERSION"
147+
git push
100148
101149
publish:
102150
name: Publish images

0 commit comments

Comments
 (0)