create-release-pr #107
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: create-release-pr | |
| run-name: create-release-pr | |
| description: | | |
| Create a release PR for a project in the repository | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| project: | |
| type: choice | |
| required: true | |
| default: "jco" | |
| options: | |
| - jco | |
| - jco-transpile | |
| - jco-std | |
| - js-component-bindgen | |
| - preview2-shim | |
| - preview3-shim | |
| description: | | |
| Project to prep for release (ex. `0.1.0`) | |
| version: | |
| type: string | |
| required: true | |
| description: | | |
| Version to prep for release (ex. `0.1.0`, `0.1.0-rc.0`) | |
| permissions: | |
| contents: none | |
| jobs: | |
| create-release-pr: | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| id-token: write | |
| pull-requests: write | |
| contents: write | |
| issues: write | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| # Install Rust deps | |
| - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 | |
| - name: install just | |
| uses: taiki-e/cache-cargo-install-action@7447f04c51f2ba27ca35e7f1e28fab848c5b3ba7 # v2.3.1 | |
| with: | |
| tool: just | |
| - name: install git-cliff | |
| uses: taiki-e/cache-cargo-install-action@7447f04c51f2ba27ca35e7f1e28fab848c5b3ba7 # v2.3.1 | |
| with: | |
| tool: git-cliff | |
| - name: install cargo-get | |
| uses: taiki-e/cache-cargo-install-action@7447f04c51f2ba27ca35e7f1e28fab848c5b3ba7 # v2.3.1 | |
| with: | |
| tool: cargo-get | |
| - name: install cargo-edit | |
| uses: taiki-e/cache-cargo-install-action@7447f04c51f2ba27ca35e7f1e28fab848c5b3ba7 # v2.3.1 | |
| with: | |
| tool: cargo-edit | |
| - name: Cache npm install | |
| id: cache-node-modules | |
| uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 | |
| with: | |
| key: node-modules-dev-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('packages/**/package.json') }} | |
| path: | | |
| node_modules | |
| - name: Install debug NPM packages | |
| run: | | |
| npm install -D | |
| - name: Gather project metadata | |
| id: project-meta | |
| env: | |
| NEXT_VERSION: ${{ inputs.version }} | |
| PROJECT: ${{ inputs.project }} | |
| shell: bash | |
| run: | | |
| if [[ $NEXT_VERSION == v* ]]; then | |
| echo "::error::next version [$NEXT_VERSION] starts with 'v' -- enter only the semver version (ex. '0.1.0', not 'v0.1.0')"; | |
| exit 1; | |
| fi | |
| case $PROJECT in | |
| jco) | |
| export PROJECT_DIR="$PWD/packages/$PROJECT"; | |
| export CURRENT_VERSION=$(node -e "process.stdout.write(require(process.env.PROJECT_DIR + '/package.json').version)"); | |
| export IS_JS_PROJECT=true; | |
| ;; | |
| jco-transpile) | |
| export PROJECT_DIR="$PWD/packages/$PROJECT"; | |
| export CURRENT_VERSION=$(node -e "process.stdout.write(require(process.env.PROJECT_DIR + '/package.json').version)"); | |
| export IS_JS_PROJECT=true; | |
| ;; | |
| preview2-shim) | |
| export PROJECT_DIR="$PWD/packages/$PROJECT"; | |
| export CURRENT_VERSION=$(node -e "process.stdout.write(require(process.env.PROJECT_DIR + '/package.json').version)"); | |
| export IS_JS_PROJECT=true; | |
| ;; | |
| preview3-shim) | |
| export PROJECT_DIR="$PWD/packages/$PROJECT"; | |
| export CURRENT_VERSION=$(node -e "process.stdout.write(require(process.env.PROJECT_DIR + '/package.json').version)"); | |
| export IS_JS_PROJECT=true; | |
| ;; | |
| js-component-bindgen) | |
| export PROJECT_DIR="$PWD/crates/$PROJECT"; | |
| export CURRENT_VERSION=$(cargo get package.version --terminator Nul --entry=crates/js-component-bindgen); | |
| export IS_RUST_PROJECT=true; | |
| ;; | |
| *) | |
| echo "unexpected project type (neither Rust nor JS)"; | |
| exit 1; | |
| esac | |
| export IS_PRERELEASE=$(node scripts/semver-is-prerelease.mjs $NEXT_VERSION); | |
| echo -e "project=$PROJECT" | |
| echo -e "project-dir=$PROJECT_DIR" | |
| echo -e "current-version=$CURRENT_VERSION" | |
| echo -e "next-version=$NEXT_VERSION" | |
| echo -e "is-rust-project=$IS_RUST_PROJECT" | |
| echo -e "is-js-project=$IS_JS_PROJECT" | |
| echo -e "is-prerelease=$IS_PRERELEASE" | |
| echo -e "project=$PROJECT" >> $GITHUB_OUTPUT | |
| echo -e "project-dir=$PROJECT_DIR" >> $GITHUB_OUTPUT | |
| echo -e "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo -e "next-version=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
| echo -e "is-rust-project=$IS_RUST_PROJECT" >> $GITHUB_OUTPUT | |
| echo -e "is-js-project=$IS_JS_PROJECT" >> $GITHUB_OUTPUT | |
| echo -e "is-prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT | |
| - name: Ensure next version is after current | |
| run: | | |
| IS_AFTER=$(node scripts/semver-lt.mjs ${{ steps.project-meta.outputs.current-version }} ${{ steps.project-meta.outputs.next-version }}); | |
| if [ "$IS_AFTER" == "false" ]; then \ | |
| echo "::error::project [${{ steps.project-meta.outputs.project }}] next version [${{ steps.project-meta.outputs.next-version }}] is not after current version [${{ steps.project-meta.outputs.current-version }}]"; | |
| exit 1; | |
| fi | |
| # Set project version | |
| - name: Set project version | |
| working-directory: ${{ steps.project-meta.outputs.project-dir }} | |
| shell: bash | |
| run: | | |
| if [ "true" == "${{ steps.project-meta.outputs.is-rust-project }}" ]; then | |
| cargo set-version -p ${{ steps.project-meta.outputs.project }} ${{ steps.project-meta.outputs.next-version }}; | |
| elif [ "true" == "${{ steps.project-meta.outputs.is-js-project }}" ]; then | |
| npm pkg set version=${{ steps.project-meta.outputs.next-version }}; | |
| fi | |
| if [ "jco" == "${{ steps.project-meta.outputs.project }}" ]; then | |
| sed \ | |
| -i \ | |
| "s/version('${{ steps.project-meta.outputs.current-version }}')/version('${{ steps.project-meta.outputs.next-version }}')/" \ | |
| src/jco.js; | |
| fi | |
| # Generate changelog | |
| # | |
| # NOTE: we use the 'latest' tag here, because starting from an rc/alpha/beta release | |
| # the rc/alpha/beta release tags are ignored and the "latest" tag is the previous stable version | |
| - name: Generate changelog | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }} | |
| run: | | |
| export OPT_TAG=--tag='${{ steps.project-meta.outputs.project }}-v${{ steps.project-meta.outputs.next-version }}'; | |
| export OPT_TAG_PATTERN=--tag-pattern='^${{ steps.project-meta.outputs.project }}-v[0-9]+.[0-9]+.[0-9]+$'; | |
| if [ "true" == "${{ steps.project-meta.outputs.is-prerelease }}" ]; then | |
| export OPT_TAG_PATTERN=--tag-pattern='^${{ steps.project-meta.outputs.project }}-v[0-9]+.[0-9]+.[0-9]+(-beta|-rc|-alpha)?'; | |
| fi | |
| git cliff \ | |
| --repository=${{ github.workspace }}/.git \ | |
| --config=${{ steps.project-meta.outputs.project-dir }}/cliff.toml \ | |
| --unreleased \ | |
| $OPT_TAG \ | |
| $OPT_TAG_PATTERN \ | |
| --prepend=${{ steps.project-meta.outputs.project-dir }}/CHANGELOG.md | |
| # Create release PR | |
| - name: Create release prep PR | |
| uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 | |
| with: | |
| branch: prep-release-${{ steps.project-meta.outputs.project}}-v${{ steps.project-meta.outputs.next-version }} | |
| token: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }} | |
| commit-message: | | |
| release: ${{ steps.project-meta.outputs.project }} v${{ steps.project-meta.outputs.next-version }} | |
| title: | | |
| release: ${{ steps.project-meta.outputs.project }} v${{ steps.project-meta.outputs.next-version }} | |
| labels: | | |
| release-pr | |
| assignees: | | |
| vados-cosmonic | |
| signoff: true | |
| body: | | |
| This is a release prep branch for `${{ steps.project-meta.outputs.project }}` release `v${{ steps.project-meta.outputs.next-version }}`. | |
| To ensure this release is ready to be merged: | |
| - [ ] Review updated CHANGELOG(s) | |
| After this PR is merged tagging, artifact builds and releasing will run automatically. |