Skip to content

Commit 25313e8

Browse files
committed
feat(ci): release version sync
Changes: - Manual CD workflow updates manifest before creating tags - New sync workflow detects and corrects manifest drift - release-please runs sync check before creating PR
1 parent 6835ae2 commit 25313e8

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.github/workflows/cd.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ jobs:
140140
with:
141141
fetch-depth: 0
142142

143+
- name: Update release-please manifest
144+
run: |
145+
# Update .release-please-manifest.json to keep release-please in sync
146+
VERSION="${{ needs.version.outputs.version }}"
147+
VERSION_NO_V="${VERSION#v}"
148+
149+
# Update manifest file
150+
jq --arg version "$VERSION_NO_V" '."."] = $version' .release-please-manifest.json > manifest.tmp
151+
mv manifest.tmp .release-please-manifest.json
152+
153+
# Commit manifest update
154+
git config user.name "github-actions[bot]"
155+
git config user.email "github-actions[bot]@users.noreply.github.com"
156+
git add .release-please-manifest.json
157+
git commit -m "chore: sync manifest with manual release $VERSION [skip ci]"
158+
git push origin main
159+
143160
- name: Create tag
144161
run: |
145162
git config user.name "github-actions[bot]"

.github/workflows/release-please.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,26 @@ permissions:
1010
pull-requests: write
1111

1212
jobs:
13+
# First, sync manifest with actual tags to prevent drift
14+
sync-manifest:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Trigger manifest sync
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
await github.rest.actions.createWorkflowDispatch({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
workflow_id: 'sync-release-manifest.yml',
25+
ref: 'main'
26+
});
27+
28+
// Wait for sync to complete
29+
await new Promise(resolve => setTimeout(resolve, 5000));
30+
1331
release-please:
1432
runs-on: ubuntu-latest
33+
needs: sync-manifest
1534
steps:
1635
- uses: google-github-actions/release-please-action@v4
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Sync Release Manifest
2+
3+
# Auto-heal release-please manifest if it drifts from actual tags
4+
# Runs before release-please to ensure consistency
5+
6+
on:
7+
schedule:
8+
# Run daily at 00:00 UTC
9+
- cron: '0 0 * * *'
10+
workflow_dispatch: # Allow manual trigger
11+
push:
12+
branches:
13+
- main
14+
15+
jobs:
16+
sync-manifest:
17+
name: Sync Manifest with Git Tags
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
pull-requests: write
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Check for manifest drift
30+
id: check
31+
run: |
32+
# Get latest tag
33+
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || echo "v0.0.0")
34+
LATEST_VERSION="${LATEST_TAG#v}"
35+
36+
# Get manifest version
37+
MANIFEST_VERSION=$(jq -r '."."]' .release-please-manifest.json)
38+
39+
echo "Latest tag: $LATEST_TAG ($LATEST_VERSION)"
40+
echo "Manifest version: $MANIFEST_VERSION"
41+
42+
# Check if they match
43+
if [ "$LATEST_VERSION" != "$MANIFEST_VERSION" ]; then
44+
echo "drift=true" >> $GITHUB_OUTPUT
45+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
46+
echo "manifest_version=$MANIFEST_VERSION" >> $GITHUB_OUTPUT
47+
echo "⚠️ Drift detected! Manifest needs update."
48+
else
49+
echo "drift=false" >> $GITHUB_OUTPUT
50+
echo "✅ Manifest is in sync with tags."
51+
fi
52+
53+
- name: Update manifest if drifted
54+
if: steps.check.outputs.drift == 'true'
55+
run: |
56+
VERSION="${{ steps.check.outputs.latest_version }}"
57+
58+
# Update manifest
59+
jq --arg version "$VERSION" '."."] = $version' .release-please-manifest.json > manifest.tmp
60+
mv manifest.tmp .release-please-manifest.json
61+
62+
# Configure git
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
66+
# Commit and push
67+
git add .release-please-manifest.json
68+
git commit -m "chore: auto-sync manifest to $VERSION (was ${{ steps.check.outputs.manifest_version }}) [skip ci]"
69+
git push origin main
70+
71+
echo "✅ Manifest synced: ${{ steps.check.outputs.manifest_version }} → $VERSION"
72+
73+
- name: Summary
74+
run: |
75+
if [ "${{ steps.check.outputs.drift }}" == "true" ]; then
76+
echo "### 🔄 Manifest Auto-Synced" >> $GITHUB_STEP_SUMMARY
77+
echo "" >> $GITHUB_STEP_SUMMARY
78+
echo "- **Previous version:** ${{ steps.check.outputs.manifest_version }}" >> $GITHUB_STEP_SUMMARY
79+
echo "- **Latest tag:** ${{ steps.check.outputs.latest_version }}" >> $GITHUB_STEP_SUMMARY
80+
echo "- **Action:** Manifest updated automatically" >> $GITHUB_STEP_SUMMARY
81+
else
82+
echo "### ✅ Manifest In Sync" >> $GITHUB_STEP_SUMMARY
83+
echo "" >> $GITHUB_STEP_SUMMARY
84+
echo "No action needed. Manifest matches latest tag." >> $GITHUB_STEP_SUMMARY
85+
fi

0 commit comments

Comments
 (0)