Create GitHub Release #12
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 GitHub Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to release from' | |
| required: true | |
| default: 'beta' | |
| workflow_run: | |
| workflows: ['Test PR'] | |
| types: [completed] | |
| branches: ['main', 'beta'] | |
| jobs: | |
| create-release: | |
| if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ inputs.branch || github.event.workflow_run.head_branch }} | |
| - name: Generate app token | |
| id: app-token | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.RELEASE_APP_ID }} | |
| private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} | |
| - name: Read version | |
| id: version | |
| run: | | |
| VERSION=$(grep '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| if [[ "$VERSION" == *"b"* || "$VERSION" == *"rc"* || "$VERSION" == *"a"* ]]; then | |
| echo "prerelease=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "prerelease=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Validate version matches branch | |
| run: | | |
| BRANCH="${{ inputs.branch || github.event.workflow_run.head_branch }}" | |
| VERSION="${{ steps.version.outputs.version }}" | |
| PRERELEASE="${{ steps.version.outputs.prerelease }}" | |
| if [[ "$BRANCH" == "beta" && "$PRERELEASE" == "false" ]]; then | |
| echo "::error::Beta branch must have a prerelease version (e.g. 3.1.0b0), got '$VERSION'" | |
| exit 1 | |
| fi | |
| if [[ "$BRANCH" == "main" && "$PRERELEASE" == "true" ]]; then | |
| echo "::error::Main branch must not have a prerelease version, got '$VERSION'" | |
| exit 1 | |
| fi | |
| - name: Create release | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| FLAGS="" | |
| if [ "${{ steps.version.outputs.prerelease }}" = "true" ]; then | |
| FLAGS="--prerelease" | |
| fi | |
| gh release create "${{ steps.version.outputs.version }}" \ | |
| --target "${{ inputs.branch || github.event.workflow_run.head_branch }}" \ | |
| --title "${{ steps.version.outputs.version }}" \ | |
| --generate-notes \ | |
| $FLAGS |