Run npm version and push tags #243
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run npm version and push tags | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| id-token: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: What version number would you like to use? The version number should be **without** a leading `v`, e.g. `5.7.1` or `6.2.4`. | |
| bump-main: | |
| description: I'm releasing from a branch and want the version number backported to main | |
| required: true | |
| type: boolean | |
| default: false | |
| is-latest-version: | |
| description: Is this the latest version? If latest we'll update the version function, docker and npm latest | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changelog: ${{ steps.generate_changelog.outputs.changelog }} | |
| strategy: | |
| matrix: | |
| node-version: [ 20.x ] | |
| services: | |
| # Label used to access the service container | |
| postgres: | |
| # Docker Hub image | |
| image: postgres | |
| # Provide the password for postgres | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_INITDB_ARGS: "--no-sync" | |
| # Set health checks to wait until postgres has started | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GH_PUSH_TOKEN }} | |
| - name: Set up git-cliff | |
| uses: kenji-miyake/setup-git-cliff@v2 | |
| - name: setup git config | |
| run: | | |
| git config user.name "Github Actions Bot" | |
| git config user.email "<>" | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'yarn' | |
| - if: ${{ endsWith(github.event.inputs.version, '0') }} | |
| run: | | |
| PREV_COMMIT=$(git rev-list --tags --max-count=1) | |
| echo PREV=$(git describe --tags ${PREV_COMMIT}) >> $GITHUB_ENV | |
| - if: ${{ !endsWith(github.event.inputs.version, '0') }} | |
| run: echo PREV=$(git describe --abbrev=0) >> $GITHUB_ENV | |
| - name: Generate changelog from ${{ env.PREV }} | |
| continue-on-error: true | |
| if: ${{ !contains(github.event.inputs.version, '-') }} | |
| env: | |
| PREV: ${{ env.PREV }} | |
| run: | | |
| git-cliff ${{ env.PREV }}..HEAD --tag v${{ github.event.inputs.version }} --prepend CHANGELOG.md | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git commit -am "docs: Update CHANGELOG.md" | |
| else | |
| echo "No changes to CHANGELOG.md" | |
| fi | |
| - name: Output changelong from ${{ env.PREV }} | |
| continue-on-error: true | |
| id: generate_changelog | |
| if: ${{ !contains(github.event.inputs.version, '-') }} | |
| env: | |
| PREV: ${{ env.PREV }} | |
| run: | | |
| # Run git-cliff again and capture its output in a variable | |
| changelog=$(git-cliff $PREV..HEAD --tag v${{ github.event.inputs.version }}) | |
| # Set the changelog as an output for the step using the new GITHUB_OUTPUT file | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$changelog" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - run: yarn install --immutable | |
| env: | |
| YARN_ENABLE_SCRIPTS: false | |
| - name: npm version | |
| run: | | |
| npm version ${{ github.event.inputs.version }} | |
| git push origin ${{ github.ref_name }} | |
| git push --tags | |
| env: | |
| CI: true | |
| TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres | |
| update-main-version: | |
| needs: build | |
| if: ${{ github.event.inputs.bump-main == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: checkout main branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| token: ${{ secrets.GH_PUSH_TOKEN }} | |
| - name: setup git config | |
| run: | | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "<>" | |
| - name: Use Node js 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.x' | |
| cache: 'yarn' | |
| - name: upgrade package version | |
| run: | | |
| jq --arg version "${{ github.event.inputs.version }}" '.version=$version' package.json > package.json.tmp | |
| mv package.json.tmp package.json | |
| - name: checkout changelog from ${{ github.ref_name }} | |
| run: git checkout origin/${{ github.ref_name }} -- CHANGELOG.md | |
| - name: lint | |
| run: | | |
| yarn install --immutable | |
| yarn lint:fix | |
| env: | |
| YARN_ENABLE_SCRIPTS: false | |
| - name: push changes | |
| run: | | |
| git add package.json CHANGELOG.md | |
| git commit -m "chore: bump version to ${{ github.event.inputs.version }}" | |
| git push origin main | |
| publish-docker: | |
| needs: build | |
| uses: ./.github/workflows/docker_publish.yaml | |
| secrets: inherit | |
| with: | |
| version: ${{ github.event.inputs.version }} | |
| is-latest-version: ${{ github.event.inputs.is-latest-version == 'true' }} | |
| publish-npm: | |
| needs: build | |
| uses: ./.github/workflows/release.yaml | |
| secrets: inherit | |
| with: | |
| version: ${{ github.event.inputs.version }} | |
| release-changelog: # TODO this changelog is different than the git-cliff one above | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ inputs.version }} | |
| name: v${{ inputs.version }} | |
| body: ${{ needs.build.outputs.changelog }} | |
| prerelease: ${{ contains(inputs.version, 'beta') || contains(inputs.version, 'alpha') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} | |
| update-version-checker: | |
| needs: publish-docker | |
| if: ${{ github.event.inputs.is-latest-version == 'true' }} | |
| uses: ./.github/workflows/update_version_for_version_checker.yml | |
| secrets: inherit | |
| with: | |
| version: ${{ github.event.inputs.version }} |