|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + packages: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + setup: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + - name: Setup base |
| 25 | + id: parse |
| 26 | + uses: ./github/actions/parse-info |
| 27 | + - name: Version to bump |
| 28 | + id: bump |
| 29 | + env: |
| 30 | + MESSAGE: ${{ steps.parse.outputs.message }} |
| 31 | + run: | |
| 32 | + regex='\[((pre)?(minor|patch|major|release))\]' |
| 33 | + if [[ $MESSAGE =~ $regex ]]; then |
| 34 | + echo "updateType=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | + outputs: |
| 37 | + updateType: ${{ steps.bump.outputs.updateType }} |
| 38 | + test: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + name: Lint & Tests |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + - name: Install dependencies |
| 45 | + uses: ./github/actions/npm-install |
| 46 | + - name: Run Test |
| 47 | + run: npm run test |
| 48 | + release: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + name: Publish |
| 51 | + needs: [setup, test] |
| 52 | + steps: |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + persist-credentials: false |
| 58 | + - name: Install dependencies |
| 59 | + uses: ./github/actions/npm-install |
| 60 | + - name: 'Generate new version' |
| 61 | + id: updatedVersion |
| 62 | + if: ${{ needs.setup.outputs.updateType }} |
| 63 | + env: |
| 64 | + TYPE: ${{ needs.setup.outputs.updateType }} |
| 65 | + run: | |
| 66 | + git config --global user.name "${{ github.actor }}" |
| 67 | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" |
| 68 | + npm version $(echo ${TYPE}) -m "v%s - [skip ci]" |
| 69 | + echo "version=$(echo $(git describe))" >> $GITHUB_OUTPUT |
| 70 | + git diff HEAD~ HEAD |
| 71 | + - name: Build |
| 72 | + shell: bash |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + run: | |
| 76 | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc |
| 77 | + NODE_ENV=production npm run build |
| 78 | + - name: Push changes |
| 79 | + uses: ad-m/github-push-action@master |
| 80 | + if: ${{ needs.setup.outputs.updateType }} |
| 81 | + with: |
| 82 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + branch: ${{ github.ref }} |
| 84 | + tags: true |
| 85 | + atomic: true |
| 86 | + - name: Generate Release |
| 87 | + uses: octokit/request-action@v2.x |
| 88 | + if: ${{ needs.setup.outputs.updateType }} |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + with: |
| 92 | + route: POST /repos/:repository/releases |
| 93 | + repository: ${{ github.repository }} |
| 94 | + tag_name: ${{ steps.updatedVersion.outputs.version }} |
| 95 | + generate_release_notes: true |
| 96 | + - name: Deploy packages |
| 97 | + if: ${{ needs.setup.outputs.updateType }} |
| 98 | + run: | |
| 99 | + npm publish |
0 commit comments