fix: add npm-publish job to release.yml, robust backmerge (#31) #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | ||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: [main] | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| # Only run when a release/* PR is merged (not closed without merge) | ||
| check: | ||
| if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v') | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.extract.outputs.version }} | ||
| steps: | ||
| - name: Extract version from branch name | ||
| id: extract | ||
| run: | | ||
| BRANCH="${{ github.event.pull_request.head.ref }}" | ||
| VERSION="${BRANCH#release/v}" | ||
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | ||
| echo "Releasing v${VERSION}" | ||
| # ── 1. Build + test gate ───────────────────────────────────────────────── | ||
| verify: | ||
| needs: check | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [20, 22] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm ci | ||
| - run: npm run build | ||
| - run: node --test test/*.test.mjs | ||
| # ── 2. Tag + GitHub Release ─────────────────────────────────────────────── | ||
| github-release: | ||
| needs: [check, verify] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Create tag and GitHub Release | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| VERSION: ${{ needs.check.outputs.version }} | ||
| run: | | ||
| git tag "v${VERSION}" | ||
| git push origin "v${VERSION}" | ||
| gh release create "v${VERSION}" --generate-notes --title "v${VERSION}" | ||
| # ── 3. Publish to npm ──────────────────────────────────────────────────── | ||
| # publish.yml cannot be triggered by a GITHUB_TOKEN-created release, so we | ||
| # publish directly here instead. | ||
| npm-publish: | ||
| needs: [check, github-release] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| registry-url: "https://registry.npmjs.org" | ||
| - run: npm ci | ||
| - run: npm run build | ||
| - name: Publish to npm | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| # ── 4. Publish to ClawHub ───────────────────────────────────────────────── | ||
| clawhub-publish: | ||
| needs: [check, verify] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| - name: Publish skill to ClawHub | ||
| env: | ||
| CLAWHUB_TOKEN: ${{ secrets.CLAWHUB_TOKEN }} | ||
| VERSION: ${{ needs.check.outputs.version }} | ||
| run: | | ||
| npx clawhub@latest auth login --token "$CLAWHUB_TOKEN" --no-browser | ||
| npx clawhub@latest publish "$(pwd)/skills/declaw" --version "$VERSION" | ||
| # ── 5. Backmerge main → develop ────────────────────────────────────────── | ||
| # With squash-merge strategy, direct merges often conflict due to diverged | ||
| # history. Try a direct merge first; on conflict, open a PR instead. | ||
| backmerge: | ||
| needs: github-release | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Merge main into develop | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| VERSION: ${{ needs.check.outputs.version }} | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git checkout develop | ||
| if git merge main --no-edit; then | ||
| git push origin develop | ||
| echo "Backmerge pushed directly to develop" | ||
| else | ||
| git merge --abort | ||
| BRANCH="chore/backmerge-v${VERSION}" | ||
| git checkout -b "$BRANCH" | ||
| git merge main -X theirs --no-edit | ||
| git push origin "$BRANCH" | ||
| gh pr create \ | ||
| --base develop \ | ||
| --head "$BRANCH" \ | ||
| --title "chore: backmerge main into develop (v${VERSION})" \ | ||
| --body "Automated backmerge of \`main\` → \`develop\` after release v${VERSION}. | ||
| Direct merge had conflicts (expected with squash-merge strategy). This PR uses \`-X theirs\` to resolve conflicts in favour of main." | ||
| echo "Conflict detected — backmerge PR created for $BRANCH" | ||
| fi | ||