|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write # Required for npm trusted publishing (OIDC) |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + environment: npm # Must match the environment configured in npm trusted publisher |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Setup pnpm |
| 23 | + uses: pnpm/action-setup@v4 |
| 24 | + |
| 25 | + - name: Setup Node.js |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: "22" |
| 29 | + cache: "pnpm" |
| 30 | + registry-url: "https://registry.npmjs.org" |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: pnpm install |
| 34 | + |
| 35 | + - name: Verify package version matches tag |
| 36 | + run: | |
| 37 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 38 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 39 | + if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then |
| 40 | + echo "Error: package.json version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Create tarball |
| 45 | + run: pnpm pack |
| 46 | + |
| 47 | + - name: Generate changelog for release |
| 48 | + id: changelog |
| 49 | + run: | |
| 50 | + # Extract version from tag |
| 51 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 52 | +
|
| 53 | + # Try to extract changelog section for this version, or use default message |
| 54 | + if [ -f "CHANGELOG.adoc" ]; then |
| 55 | + # Extract section between this version and next version header |
| 56 | + NOTES=$(awk "/^== $VERSION/,/^== [0-9]/" CHANGELOG.adoc | head -n -1 | tail -n +2) |
| 57 | + if [ -z "$NOTES" ]; then |
| 58 | + NOTES="Release v$VERSION" |
| 59 | + fi |
| 60 | + else |
| 61 | + NOTES="Release v$VERSION" |
| 62 | + fi |
| 63 | +
|
| 64 | + # Write to file to handle multiline |
| 65 | + echo "$NOTES" > release_notes.md |
| 66 | +
|
| 67 | + - name: Create GitHub Release |
| 68 | + uses: softprops/action-gh-release@v2 |
| 69 | + with: |
| 70 | + body_path: release_notes.md |
| 71 | + files: | |
| 72 | + antora-dark-theme-*.tgz |
| 73 | + generate_release_notes: true |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Publish to npm (trusted publishing) |
| 78 | + if: ${{ !contains(github.ref, '-') }} |
| 79 | + run: npm publish --access public --provenance |
0 commit comments