|
| 1 | +name: Release Creation on GitHub & NPM Publishing |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: {} |
| 8 | + |
| 9 | +jobs: |
| 10 | + check_conditions: |
| 11 | + name: Check conditions to create & release |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + outputs: |
| 16 | + run_suffix_present: ${{ steps.check_run_suffix_present.outputs.run_suffix_present }} |
| 17 | + run_suffix_force_version: ${{ steps.check_run_suffix_present.outputs.run_suffix_force_version }} |
| 18 | + steps: |
| 19 | + - name: Checkout the Codebase |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + ref: main # branch to checkout |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Get last commit message |
| 26 | + run: echo "message=$(git log -1 --pretty=%B)" >> $GITHUB_ENV |
| 27 | + |
| 28 | + - name: Check commit message suffix for `[create-release]` |
| 29 | + id: check_run_suffix_present |
| 30 | + uses: actions/github-script@v7 |
| 31 | + with: |
| 32 | + script: | |
| 33 | + let run_suffix_present = "false"; |
| 34 | + let run_suffix_force_version = ""; |
| 35 | +
|
| 36 | + const commitMessage = process.env.message; |
| 37 | + const regex = /\[create-release(?:-([a-z]+))?\]$/; |
| 38 | + const match = commitMessage.match(regex); |
| 39 | +
|
| 40 | + if (match) { |
| 41 | + run_suffix_present = "true"; |
| 42 | + if(match[1]){ |
| 43 | + run_suffix_force_version = `--${match[1]}` |
| 44 | + } |
| 45 | + } |
| 46 | +
|
| 47 | + console.dir(`Set output: run_suffix_present=${run_suffix_present}`); |
| 48 | + core.setOutput("run_suffix_present", run_suffix_present); |
| 49 | +
|
| 50 | + console.dir(`Set output: run_suffix_force_version=${run_suffix_force_version}`); |
| 51 | + core.setOutput("run_suffix_force_version", run_suffix_force_version); |
| 52 | +
|
| 53 | + dependence-lint: |
| 54 | + name: Depend on Lint |
| 55 | + uses: ./.github/workflows/lint.yml |
| 56 | + |
| 57 | + create_release: |
| 58 | + needs: |
| 59 | + - check_conditions |
| 60 | + - dependence-lint |
| 61 | + if: needs.check_conditions.outputs.run_suffix_present == 'true' |
| 62 | + name: Create GitHub Release & NPM Publish |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + steps: |
| 67 | + - name: Checkout the Codebase |
| 68 | + uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + ref: main # branch to checkout |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Setup Node.js |
| 74 | + uses: actions/setup-node@v4 |
| 75 | + with: |
| 76 | + node-version: 22 |
| 77 | + |
| 78 | + - name: Enable pnpm |
| 79 | + run: | |
| 80 | + corepack enable |
| 81 | + corepack prepare pnpm@v9.15.4 --activate |
| 82 | +
|
| 83 | + - name: Init git config for the bot by setting name & email |
| 84 | + run: | |
| 85 | + git config --global user.name "github-actions[bot]" |
| 86 | + git config --global user.email "no-reply@todde.tv" |
| 87 | +
|
| 88 | + # - name: Get old `package.json` version |
| 89 | + # id: get_package_version_old |
| 90 | + # run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT |
| 91 | + |
| 92 | + - name: Bump `package.json` version & generate changelog both from conventional commits |
| 93 | + # -from "v${{ steps.get_package_version_old.outputs.version }}" |
| 94 | + run: npx changelogen@0.5.7 --output CHANGELOG.md --bump --no-commit --no-tag ${{ needs.check_conditions.outputs.run_suffix_force_version }} |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 97 | + |
| 98 | + - name: Get new `package.json` version |
| 99 | + id: get_package_version_new |
| 100 | + run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT |
| 101 | + |
| 102 | + - name: Git add, commit & push changes made to `package.json` & `CHANGELOG.md` to `main` |
| 103 | + run: | |
| 104 | + git add . |
| 105 | + git commit -m "chore(release): v${{ steps.get_package_version_new.outputs.version }}" |
| 106 | + git push origin main |
| 107 | +
|
| 108 | + - name: Create a tag |
| 109 | + run: | |
| 110 | + git tag -a "v${{ steps.get_package_version_new.outputs.version }}" -m "Release v${{ steps.get_package_version_new.outputs.version }}" |
| 111 | + git push origin --tags |
| 112 | +
|
| 113 | + - name: Sync tags with GitHub releases & create the new release |
| 114 | + # run: npx changelogen@0.5.7 gh release "v${{ steps.get_package_version_new.outputs.version }}" |
| 115 | + # run: npx changelogen@0.5.7 gh release |
| 116 | + run: npx changelogen@0.5.7 gh release all |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Install dependencies |
| 121 | + # TODO fix this bc currently using the frozen lockfile will fail due to the patch inside `package.json` |
| 122 | + # run: pnpm install --frozen-lockfile |
| 123 | + run: pnpm install --no-frozen-lockfile |
| 124 | + |
| 125 | + - name: Build the project |
| 126 | + run: pnpm run build |
| 127 | + |
| 128 | + # - name: Publish package to NPM |
| 129 | + # if: github.ref == 'refs/heads/main' |
| 130 | + # run: pnpm publish --access public |
| 131 | + # env: |
| 132 | + # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 133 | + |
| 134 | + - name: Publish package to NPM |
| 135 | + # if: github.ref == 'refs/heads/main' |
| 136 | + uses: JS-DevTools/npm-publish@v3 |
| 137 | + with: |
| 138 | + token: ${{ secrets.NPM_TOKEN }} |
| 139 | + access: public |
| 140 | + # registry: "https://npm.pkg.github.com/" |
| 141 | + registry: https://registry.npmjs.org/ |
0 commit comments