|
| 1 | +name: Release and publish |
| 2 | + |
| 3 | +# Inspired by https://github.com/MylesBorins/node-osc/blob/959b9c83972a67390a351d333b23db3972ca7b46/.github/workflows/bump-version.yml and |
| 4 | +# https://github.com/MylesBorins/node-osc/blob/74b563c83736a04c4a37acbff9d7bb1f01a00f57/.github/workflows/create-release.yml |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: Semver descriptor for new version ("major", "minor", or "patch") |
| 11 | + type: choice |
| 12 | + options: ["major", "minor", "patch"] |
| 13 | + required: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + bump-version: |
| 17 | + name: Bump package version |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + new-tag: ${{ steps.new-tag.outputs.new-tag }} |
| 21 | + steps: |
| 22 | + - name: Checkout ref |
| 23 | + uses: actions/checkout@v2 |
| 24 | + - name: Preparation |
| 25 | + uses: ./.github/actions/setup |
| 26 | + - name: Perform last-minute tests |
| 27 | + run: npm test |
| 28 | + - name: Configure Git |
| 29 | + run: | |
| 30 | + git config user.name "GitHub Actions" |
| 31 | + git config user.email "[email protected]" |
| 32 | + - name: Bump package version |
| 33 | + run: npm version ${{ github.event.inputs.version }} |
| 34 | + - name: Push back to GitHub |
| 35 | + run: git push origin main --follow-tags |
| 36 | + - name: Set output to new version |
| 37 | + id: new-tag |
| 38 | + run: | |
| 39 | + version=$(jq -r .version < package.json) |
| 40 | + echo "::set-output name=new-tag::v$version" |
| 41 | + create-release: |
| 42 | + name: Create GitHub release |
| 43 | + runs-on: ubuntu-latest |
| 44 | + needs: bump-version |
| 45 | + steps: |
| 46 | + - name: Checkout ref |
| 47 | + uses: actions/checkout@v2 |
| 48 | + with: |
| 49 | + ref: ${{ needs.bump-version.outputs.new-tag }} |
| 50 | + - name: Preparation |
| 51 | + uses: ./.github/actions/setup |
| 52 | + - name: Create release |
| 53 | + uses: actions/github-script@v5 |
| 54 | + with: |
| 55 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + script: | |
| 57 | + await github.request(`POST /repos/${{ github.repository }}/releases`, { |
| 58 | + tag_name: "${{ needs.bump-version.outputs.new-tag }}", |
| 59 | + generate_release_notes: true |
| 60 | + }) |
| 61 | + publish: |
| 62 | + name: Publish |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [bump-version, create-release] |
| 65 | + steps: |
| 66 | + - name: Checkout ref |
| 67 | + uses: actions/checkout@v2 |
| 68 | + with: |
| 69 | + ref: ${{ needs.bump-version.outputs.new-tag }} |
| 70 | + - name: Preparation |
| 71 | + uses: ./.github/actions/setup |
| 72 | + - name: Setup npm registry |
| 73 | + uses: actions/setup-node@v2 |
| 74 | + with: |
| 75 | + registry-url: 'https://registry.npmjs.org' |
| 76 | + - name: Publish to npm |
| 77 | + run: npm publish |
| 78 | + env: |
| 79 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 80 | + - name: Setup GHPR |
| 81 | + uses: actions/setup-node@v2 |
| 82 | + with: |
| 83 | + registry-url: 'https://npm.pkg.github.com' |
| 84 | + - name: Publish to GHPR |
| 85 | + run: npm publish |
| 86 | + env: |
| 87 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments