# Adapted from https://github.com/joshka/github-workflows/blob/main/.github/workflows/rust-release-plz.yml # Thanks to joshka for permission to use this template! name: Create release permissions: pull-requests: write contents: write on: workflow_dispatch: inputs: bump_type: description: "Specify the type of version bump" required: true default: "patch" type: choice options: - patch - minor - major start_from: description: "Specify the job to start from" required: false default: "bump" type: choice options: - bump - release-plz jobs: bump: runs-on: ubuntu-latest if: ${{ github.event.inputs.start_from == 'bump' || github.event.inputs.start_from == '' }} steps: - name: Configure SSH for Git run: | mkdir -p ~/.ssh echo "${{ secrets.RELEASE_BOT_SSH_KEY }}" > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H github.com >> ~/.ssh/known_hosts - name: Checkout repository uses: actions/checkout@v3 with: ssh-key: ${{ secrets.RELEASE_BOT_SSH_KEY }} fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.10" - name: Install Commitizen run: | python -m pip install --upgrade pip pip install commitizen npm install -g conventional-changelog-cli - name: Configure Git user run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Bump version with Commitizen run: | cz bump --yes --increment ${{ github.event.inputs.bump_type }} - name: Amend commit message to include '[skip ci]' run: | git commit --amend --no-edit -m "$(git log -1 --pretty=%B) [skip ci]" - name: Get the new version tag id: version run: | NEW_TAG=$(cz version --project) echo "New version: $NEW_TAG" echo "version=$NEW_TAG" >> $GITHUB_ENV - name: Get the previous version tag id: prev_version run: | PREV_TAG=$(git describe --tags --abbrev=0 ${GITHUB_SHA}^) echo "Previous tag: $PREV_TAG" echo "prev_version=$PREV_TAG" >> $GITHUB_ENV - name: Generate changelog for the version bump id: changelog run: | changelog=$(conventional-changelog -p angular -i CHANGELOG.md -s --from ${{ env.prev_version }} --to ${{ env.version }}) echo "$changelog" > changelog.md echo "changelog_body=$(cat changelog.md)" >> $GITHUB_ENV - name: Create a GitHub Release uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ env.version }} name: "Release ${{ env.version }}" body: ${{ env.changelog_body }} draft: false prerelease: false - name: Push changes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git tag ${{ env.version }} git push origin --follow-tags release-plz: # see https://release-plz.ieni.dev/docs/github # for more information needs: bump name: Release-plz if: ${{ github.event.inputs.start_from == 'release-plz' || github.event.inputs.start_from == '' }} runs-on: ubuntu-latest steps: - name: Check if actor is repository owner if: ${{ github.actor != github.repository_owner }} run: | echo "You are not authorized to run this workflow." exit 1 - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install Rust stable uses: dtolnay/rust-toolchain@stable - name: Run release-plz uses: MarcoIeni/release-plz-action@v0.5 with: command: release tag_name: ${{ env.VERSION }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}