From d3196aa143d73909f908b5ff424306ee38759158 Mon Sep 17 00:00:00 2001 From: Mathieu BARLEON Date: Wed, 8 Jul 2026 14:38:14 +0200 Subject: [PATCH] fix: use reusable workflow to release --- .github/workflows/release.yml | 113 ++++++++++++++++++++--------- .github/workflows/tag-on-merge.yml | 38 +++++++++- 2 files changed, 113 insertions(+), 38 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8d05b17..3cdb622 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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" @@ -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' }} diff --git a/.github/workflows/tag-on-merge.yml b/.github/workflows/tag-on-merge.yml index dd8c731..cf5d99b 100644 --- a/.github/workflows/tag-on-merge.yml +++ b/.github/workflows/tag-on-merge.yml @@ -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 @@ -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" @@ -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 && @@ -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 @@ -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" @@ -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