Merge pull request #2 from spectrayan/release-please--branches--main #3
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: Release | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Tag to create (e.g. v0.1.0). Leave empty to use release-please." | |
| required: false | |
| default: "" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| release-please: | |
| if: >- | |
| github.ref == 'refs/heads/main' && | |
| (github.event_name == 'push' || | |
| (github.event_name == 'workflow_dispatch' && inputs.version == '')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Run release-please | |
| id: release | |
| uses: googleapis/release-please-action@v4 | |
| with: | |
| release-type: simple | |
| - name: Checkout (for major tag update) | |
| if: ${{ steps.release.outputs.release_created == 'true' }} | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Update rolling major tag | |
| if: ${{ steps.release.outputs.release_created == 'true' }} | |
| env: | |
| TAG: ${{ steps.release.outputs.tag_name }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| echo "[release] new tag: ${TAG}" | |
| MAJOR="${TAG%%.*}" | |
| echo "[release] updating rolling major tag: ${MAJOR} -> ${TAG}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag -f "${MAJOR}" "${TAG}" | |
| git push origin "${MAJOR}" --force | |
| manual-release: | |
| if: >- | |
| github.event_name == 'workflow_dispatch' && | |
| inputs.version != '' && | |
| github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate version input | |
| env: | |
| TAG: ${{ inputs.version }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| echo "[release] requested manual tag: ${TAG}" | |
| if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then | |
| echo "::error::version must look like vMAJOR.MINOR.PATCH (e.g. v0.1.0), got: ${TAG}" | |
| exit 1 | |
| fi | |
| - name: Create tag and GitHub Release | |
| env: | |
| TAG: ${{ inputs.version }} | |
| GH_TOKEN: ${{ github.token }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| echo "[release] creating manual release: ${TAG} @ ${GITHUB_SHA}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then | |
| echo "::error::tag ${TAG} already exists on origin" | |
| exit 1 | |
| fi | |
| git tag "${TAG}" "${GITHUB_SHA}" | |
| git push origin "${TAG}" | |
| MAJOR="${TAG%%.*}" | |
| echo "[release] updating rolling major tag: ${MAJOR} -> ${TAG}" | |
| git tag -f "${MAJOR}" "${TAG}" | |
| git push origin "${MAJOR}" --force | |
| echo "[release] creating GitHub Release for ${TAG}" | |
| gh release create "${TAG}" \ | |
| --target "${GITHUB_SHA}" \ | |
| --title "${TAG}" \ | |
| --generate-notes |