From 25313e8d48af32edd57f58fec496607c8f54ce4d Mon Sep 17 00:00:00 2001 From: MoonBoi9001 Date: Sat, 22 Nov 2025 16:08:07 -0800 Subject: [PATCH] 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 --- .github/workflows/cd.yml | 17 +++++ .github/workflows/release-please.yml | 19 +++++ .github/workflows/sync-release-manifest.yml | 85 +++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 .github/workflows/sync-release-manifest.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index addd666..f8f7e72 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -140,6 +140,23 @@ jobs: with: fetch-depth: 0 + - name: Update release-please manifest + run: | + # Update .release-please-manifest.json to keep release-please in sync + VERSION="${{ needs.version.outputs.version }}" + VERSION_NO_V="${VERSION#v}" + + # Update manifest file + jq --arg version "$VERSION_NO_V" '."."] = $version' .release-please-manifest.json > manifest.tmp + mv manifest.tmp .release-please-manifest.json + + # Commit manifest update + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add .release-please-manifest.json + git commit -m "chore: sync manifest with manual release $VERSION [skip ci]" + git push origin main + - name: Create tag run: | git config user.name "github-actions[bot]" diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 8757dca..331a049 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -10,7 +10,26 @@ permissions: pull-requests: write jobs: + # First, sync manifest with actual tags to prevent drift + sync-manifest: + runs-on: ubuntu-latest + steps: + - name: Trigger manifest sync + uses: actions/github-script@v7 + with: + script: | + await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'sync-release-manifest.yml', + ref: 'main' + }); + + // Wait for sync to complete + await new Promise(resolve => setTimeout(resolve, 5000)); + release-please: runs-on: ubuntu-latest + needs: sync-manifest steps: - uses: google-github-actions/release-please-action@v4 diff --git a/.github/workflows/sync-release-manifest.yml b/.github/workflows/sync-release-manifest.yml new file mode 100644 index 0000000..7995e6e --- /dev/null +++ b/.github/workflows/sync-release-manifest.yml @@ -0,0 +1,85 @@ +name: Sync Release Manifest + +# Auto-heal release-please manifest if it drifts from actual tags +# Runs before release-please to ensure consistency + +on: + schedule: + # Run daily at 00:00 UTC + - cron: '0 0 * * *' + workflow_dispatch: # Allow manual trigger + push: + branches: + - main + +jobs: + sync-manifest: + name: Sync Manifest with Git Tags + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Check for manifest drift + id: check + run: | + # Get latest tag + LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || echo "v0.0.0") + LATEST_VERSION="${LATEST_TAG#v}" + + # Get manifest version + MANIFEST_VERSION=$(jq -r '."."]' .release-please-manifest.json) + + echo "Latest tag: $LATEST_TAG ($LATEST_VERSION)" + echo "Manifest version: $MANIFEST_VERSION" + + # Check if they match + if [ "$LATEST_VERSION" != "$MANIFEST_VERSION" ]; then + echo "drift=true" >> $GITHUB_OUTPUT + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT + echo "manifest_version=$MANIFEST_VERSION" >> $GITHUB_OUTPUT + echo "⚠️ Drift detected! Manifest needs update." + else + echo "drift=false" >> $GITHUB_OUTPUT + echo "✅ Manifest is in sync with tags." + fi + + - name: Update manifest if drifted + if: steps.check.outputs.drift == 'true' + run: | + VERSION="${{ steps.check.outputs.latest_version }}" + + # Update manifest + jq --arg version "$VERSION" '."."] = $version' .release-please-manifest.json > manifest.tmp + mv manifest.tmp .release-please-manifest.json + + # Configure git + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Commit and push + git add .release-please-manifest.json + git commit -m "chore: auto-sync manifest to $VERSION (was ${{ steps.check.outputs.manifest_version }}) [skip ci]" + git push origin main + + echo "✅ Manifest synced: ${{ steps.check.outputs.manifest_version }} → $VERSION" + + - name: Summary + run: | + if [ "${{ steps.check.outputs.drift }}" == "true" ]; then + echo "### 🔄 Manifest Auto-Synced" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **Previous version:** ${{ steps.check.outputs.manifest_version }}" >> $GITHUB_STEP_SUMMARY + echo "- **Latest tag:** ${{ steps.check.outputs.latest_version }}" >> $GITHUB_STEP_SUMMARY + echo "- **Action:** Manifest updated automatically" >> $GITHUB_STEP_SUMMARY + else + echo "### ✅ Manifest In Sync" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "No action needed. Manifest matches latest tag." >> $GITHUB_STEP_SUMMARY + fi