|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + uses: ./.github/workflows/build.yaml |
| 11 | + secrets: inherit |
| 12 | + |
| 13 | + publish: |
| 14 | + name: Publish to npmjs.org |
| 15 | + needs: [build] |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Setup .npmrc |
| 20 | + run: cp tools/_.npmrc .npmrc |
| 21 | + - uses: actions/download-artifact@v4 |
| 22 | + with: |
| 23 | + name: dist.tar |
| 24 | + - name: Unpack compilation artifact |
| 25 | + run: mkdir dist && tar -xf dist.tar -C dist |
| 26 | + - name: Configure the package.json for publishing |
| 27 | + run: jq --arg version "${REF#refs\/tags\/v}" 'del(.devDependencies,.scripts,.private) | .version=$version' package.json > dist/package.json |
| 28 | + env: |
| 29 | + REF: ${{ github.ref }} |
| 30 | + - name: Include README.md in the package |
| 31 | + run: cp README.md dist/ |
| 32 | + - name: Publish the package |
| 33 | + uses: docker://node:18.20.8-alpine3.21 |
| 34 | + with: |
| 35 | + args: yarn --cwd dist publish --no-git-tag-version |
| 36 | + env: |
| 37 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN_RW }} |
| 38 | + - name: Update compilation artifact |
| 39 | + run: tar -cf ../dist.tar * |
| 40 | + working-directory: dist |
| 41 | + - uses: actions/upload-artifact@v4 |
| 42 | + with: |
| 43 | + name: dist.tar |
| 44 | + path: dist.tar |
| 45 | + retention-days: 1 |
| 46 | + |
| 47 | + create-release: |
| 48 | + name: Create GitHub Release |
| 49 | + needs: [publish] |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: Determine version |
| 53 | + id: version |
| 54 | + run: printf "tag=%s\n" "${REF#refs\/tags\/}" >> $GITHUB_OUTPUT |
| 55 | + env: |
| 56 | + REF: ${{ github.ref }} |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + ref: ${{ steps.version.outputs.tag }} |
| 61 | + - name: Get release notes from tag |
| 62 | + id: tag-message |
| 63 | + run: | |
| 64 | + eof="$(openssl rand -hex 8)" |
| 65 | + printf "message<<%s\n%s\n%s\n" "$eof" "$(git tag -l --format='%(contents)' "${REF#refs\/tags\/}")" "$eof" >> $GITHUB_OUTPUT |
| 66 | + env: |
| 67 | + REF: ${{ github.ref }} |
| 68 | + - uses: actions/download-artifact@v4 |
| 69 | + with: |
| 70 | + name: dist.tar |
| 71 | + - name: Compress release artifact |
| 72 | + run: gzip dist.tar && mv dist.tar.gz ${{ steps.version.outputs.tag }}.tar.gz |
| 73 | + - name: Create Release |
| 74 | + uses: ncipollo/release-action@v1 |
| 75 | + with: |
| 76 | + name: ${{ steps.version.outputs.tag }} |
| 77 | + body: ${{ steps.tag-message.outputs.message }} |
| 78 | + draft: false |
| 79 | + prerelease: false |
| 80 | + artifacts: ${{ steps.version.outputs.tag }}.tar.gz |
| 81 | + artifactErrorsFailBuild: true |
| 82 | + artifactContentType: application/gzip |
0 commit comments