|
| 1 | +name: Force Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Tag to release (e.g. 0.25.2)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + id-token: write |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + publish: |
| 17 | + name: Publish to npm |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + id-token: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout tag |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + ref: ${{ inputs.tag }} |
| 28 | + |
| 29 | + - name: Setup Node.js |
| 30 | + uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: '22.x' |
| 33 | + cache: 'npm' |
| 34 | + cache-dependency-path: package-lock.json |
| 35 | + registry-url: 'https://registry.npmjs.org' |
| 36 | + |
| 37 | + - name: Install deps |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + - name: Build |
| 41 | + run: npm run build |
| 42 | + |
| 43 | + - name: Verify version matches tag |
| 44 | + run: | |
| 45 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 46 | + TAG_VERSION=${{ inputs.tag }} |
| 47 | + TAG_VERSION=${TAG_VERSION#v} |
| 48 | + if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then |
| 49 | + echo "Error: package.json version ($PACKAGE_VERSION) does not match tag ($TAG_VERSION)" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + echo "Version verified: $PACKAGE_VERSION" |
| 53 | +
|
| 54 | + - name: Publish to npm |
| 55 | + run: npm publish --provenance --access public |
| 56 | + |
| 57 | + github-release: |
| 58 | + name: Create GitHub Release |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: publish |
| 61 | + permissions: |
| 62 | + contents: write |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout tag |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + ref: ${{ inputs.tag }} |
| 69 | + |
| 70 | + - name: Extract changelog for this version |
| 71 | + id: changelog |
| 72 | + run: | |
| 73 | + VERSION=${{ inputs.tag }} |
| 74 | + VERSION=${VERSION#v} |
| 75 | + CHANGELOG=$(awk "/^## \\[?${VERSION}\\]?/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md 2>/dev/null || echo "") |
| 76 | + if [ -z "$CHANGELOG" ]; then |
| 77 | + CHANGELOG="Release ${VERSION}" |
| 78 | + fi |
| 79 | + echo "content<<EOF" >> $GITHUB_OUTPUT |
| 80 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 81 | + echo "EOF" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + - name: Create GitHub Release |
| 84 | + uses: softprops/action-gh-release@v2 |
| 85 | + with: |
| 86 | + tag_name: ${{ inputs.tag }} |
| 87 | + body: ${{ steps.changelog.outputs.content }} |
| 88 | + generate_release_notes: true |
0 commit comments