Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 79 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,88 @@ on:
push:
tags:
- "v*"
workflow_call:
inputs:
tag_name:
required: true
type: string
prerelease:
required: true
type: boolean
environment_name:
required: true
type: string
workflow_dispatch:
inputs:
tag_name:
description: "Tag to release"
required: true
type: string
prerelease:
description: "Publish as prerelease"
required: true
type: boolean
environment_name:
description: "GitHub environment to use"
required: true
type: choice
options:
- release
- release-rc

permissions:
contents: write

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.vars.outputs.tag_name }}
prerelease: ${{ steps.vars.outputs.prerelease }}
environment_name: ${{ steps.vars.outputs.environment_name }}

steps:
- name: Resolve release parameters
id: vars
run: |
if [[ "${{ github.event_name }}" == "workflow_call" ]]; then
echo "tag_name=${{ inputs.tag_name }}" >> "$GITHUB_OUTPUT"
echo "prerelease=${{ inputs.prerelease }}" >> "$GITHUB_OUTPUT"
echo "environment_name=${{ inputs.environment_name }}" >> "$GITHUB_OUTPUT"
exit 0
fi

if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "tag_name=${{ inputs.tag_name }}" >> "$GITHUB_OUTPUT"
echo "prerelease=${{ inputs.prerelease }}" >> "$GITHUB_OUTPUT"
echo "environment_name=${{ inputs.environment_name }}" >> "$GITHUB_OUTPUT"
exit 0
fi

tag_name="${GITHUB_REF_NAME}"
if [[ "$tag_name" == *-rc.* ]]; then
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
echo "environment_name=release-rc" >> "$GITHUB_OUTPUT"
else
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
echo "environment_name=release" >> "$GITHUB_OUTPUT"
fi

build:
runs-on: ubuntu-latest
needs: prepare

steps:
- name: Check out repository
uses: actions/checkout@v7
uses: actions/checkout@v4
with:
ref: refs/tags/${{ needs.prepare.outputs.tag_name }}
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v6
uses: actions/setup-python@v5
with:
python-version: "3.12"

Expand All @@ -29,52 +95,31 @@ jobs:
python -m build

- name: Upload build artifacts
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*

publish-prerelease:
if: contains(github.ref_name, '-rc.')
runs-on: ubuntu-latest
environment:
name: release-rc
needs: build

steps:
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: dist
path: dist

- name: Create GitHub prerelease
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
files: dist/*
generate_release_notes: true
prerelease: true

publish-release:
if: ${{ !contains(github.ref_name, '-rc.') }}
publish:
runs-on: ubuntu-latest
needs: build
environment:
name: release
name: ${{ needs.prepare.outputs.environment_name }}
needs:
- prepare
- build

steps:
- name: Download build artifacts
uses: actions/download-artifact@v7
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Create GitHub release
uses: softprops/action-gh-release@v3
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
tag_name: ${{ needs.prepare.outputs.tag_name }}
name: "Release: ${{ needs.prepare.outputs.tag_name }}"
files: dist/*
generate_release_notes: true
prerelease: ${{ needs.prepare.outputs.prerelease == 'true' }}
38 changes: 34 additions & 4 deletions .github/workflows/tag-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ jobs:
environment:
name: release-rc

outputs:
tag_name: ${{ steps.version.outputs.tag }}

steps:
- name: Check out base branch
uses: actions/checkout@v7
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }}
fetch-depth: 0
Expand All @@ -36,7 +39,7 @@ jobs:
run: git fetch --force --tags origin

- name: Set up Python
uses: actions/setup-python@v6
uses: actions/setup-python@v5
with:
python-version: "3.12"

Expand Down Expand Up @@ -85,6 +88,18 @@ jobs:
git tag -a "$tag" -m "Release candidate $tag"
git push origin "$tag"

release-dev:
if: >-
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'dev'
needs: tag-dev
uses: ./.github/workflows/release.yml
secrets: inherit
with:
tag_name: ${{ needs.tag-dev.outputs.tag_name }}
prerelease: true
environment_name: release-rc

tag-main:
if: >-
github.event.pull_request.merged == true &&
Expand All @@ -93,9 +108,12 @@ jobs:
environment:
name: release

outputs:
tag_name: ${{ steps.version.outputs.tag }}

steps:
- name: Check out base branch
uses: actions/checkout@v7
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.base.ref }}
fetch-depth: 0
Expand All @@ -104,7 +122,7 @@ jobs:
run: git fetch --force --tags origin

- name: Set up Python
uses: actions/setup-python@v6
uses: actions/setup-python@v5
with:
python-version: "3.12"

Expand Down Expand Up @@ -152,3 +170,15 @@ jobs:
git fetch origin main --tags
git tag -a "$tag" -m "Release $tag"
git push origin "$tag"

release-main:
if: >-
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main'
needs: tag-main
uses: ./.github/workflows/release.yml
secrets: inherit
with:
tag_name: ${{ needs.tag-main.outputs.tag_name }}
prerelease: false
environment_name: release