|
| 1 | +name: Publish |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: |
| 5 | + - closed |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - "v**" |
| 9 | + workflow_dispatch: |
| 10 | +jobs: |
| 11 | + publish: |
| 12 | + if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.event.pull_request.head.label == 'fetchet:release') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + id-token: write |
| 17 | + steps: |
| 18 | + - name: "Release PR info" |
| 19 | + if: github.event_name != 'workflow_dispatch' |
| 20 | + run: echo "PR ${{ github.event.number }}" |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + - name: git config |
| 23 | + run: | |
| 24 | + git config user.name "${GITHUB_ACTOR}" |
| 25 | + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 26 | + - uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 18 |
| 29 | + registry-url: https://registry.npmjs.org/ |
| 30 | + - run: npm ci |
| 31 | + - name: get-npm-version |
| 32 | + id: package-version |
| 33 | + uses: martinbeentjes/npm-get-version-action@main |
| 34 | + - name: Extract release notes |
| 35 | + id: extract-release-notes |
| 36 | + uses: ffurrer2/extract-release-notes@v2 |
| 37 | + # TODO: Check/verify versions |
| 38 | + # Tag Release |
| 39 | + - name: "Push tag v${{ steps.package-version.outputs.current-version }}" |
| 40 | + uses: rickstaa/action-create-tag@v1 |
| 41 | + id: tag_version |
| 42 | + with: |
| 43 | + tag: "v${{ steps.package-version.outputs.current-version }}" |
| 44 | + # Resolve NPM Tag |
| 45 | + - name: NPM TAG |
| 46 | + id: "npm_tag" |
| 47 | + run: | |
| 48 | + version="${{ steps.package-version.outputs.current-version }}" |
| 49 | + if [[ "$version" == *-* ]]; then |
| 50 | + echo "tag=beta" >> $GITHUB_OUTPUT |
| 51 | + else |
| 52 | + echo "tag=latest" >> $GITHUB_OUTPUT |
| 53 | + fi |
| 54 | + - name: Set fallback tag if empty |
| 55 | + id: fallback_tag |
| 56 | + run: | |
| 57 | + echo "tag=${{ steps.npm_tag.outputs.tag || 'latest' }}" >> $GITHUB_OUTPUT |
| 58 | + # GitHub Release |
| 59 | + - name: "Create a GitHub release v${{ steps.package-version.outputs.current-version }}" |
| 60 | + uses: ncipollo/release-action@v1 |
| 61 | + with: |
| 62 | + tag: "v${{ steps.package-version.outputs.current-version }}" |
| 63 | + name: "Release v${{ steps.package-version.outputs.current-version }}" |
| 64 | + body: | |
| 65 | + ## Release notes: |
| 66 | + ${{ steps.extract-release-notes.outputs.release_notes }} |
| 67 | + # NPM Release |
| 68 | + - name: Publish the release to NPM |
| 69 | + run: npm publish --provenance --access public --tag ${{ steps.fallback_tag.outputs.tag }} |
| 70 | + env: |
| 71 | + NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
| 72 | + # TODO: notify release notify - add release comments and tags to published PRs: |
0 commit comments