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
96 changes: 40 additions & 56 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,8 @@ jobs:
with:
fetch-depth: 0

- name: Detect resumable release
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
id: resumable-release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_CHANNEL: ${{ inputs.release_channel }}
run: bash .github/workflows/scripts/detect-resumable-release.sh

- name: Checkout resumable release target
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run && steps.resumable-release.outputs.resume == 'true'
env:
TARGET: ${{ steps.resumable-release.outputs.target }}
run: git checkout --detach "$TARGET"

- name: Determine minimum version
if: github.event_name == 'workflow_dispatch' && (inputs.dry_run || steps.resumable-release.outputs.resume != 'true')
if: github.event_name == 'workflow_dispatch'
id: minimum-version
shell: bash
run: |
Expand All @@ -93,40 +79,14 @@ jobs:
echo "version=${minimum_major_minor}.0" >> "$GITHUB_OUTPUT"

- name: Calculate release version
if: github.event_name == 'workflow_dispatch' && (inputs.dry_run || steps.resumable-release.outputs.resume != 'true')
if: github.event_name == 'workflow_dispatch'
id: calculated-version
uses: Kralizek/github-actions/actions/calculate-next-version@v0.4
with:
bump: ${{ inputs.bump }}
channel: ${{ inputs.release_channel != 'stable' && inputs.release_channel || '' }}
minimum-version: ${{ steps.minimum-version.outputs.version }}

- name: Resolve manual release version
if: github.event_name == 'workflow_dispatch'
id: manual-release
env:
RESUME: ${{ steps.resumable-release.outputs.resume }}
RESUMED_VERSION: ${{ steps.resumable-release.outputs.version }}
RESUMED_TAG: ${{ steps.resumable-release.outputs.tag }}
CALCULATED_VERSION: ${{ steps.calculated-version.outputs.version }}
CALCULATED_TAG: ${{ steps.calculated-version.outputs.tag }}
CALCULATED_RELEASE_NOTES_START_TAG: ${{ steps.calculated-version.outputs['release-notes-start-tag'] }}
shell: bash
run: |
set -euo pipefail

if [[ "$RESUME" == "true" ]]; then
echo "resume=true" >> "$GITHUB_OUTPUT"
echo "version=$RESUMED_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$RESUMED_TAG" >> "$GITHUB_OUTPUT"
echo "release-notes-start-tag=" >> "$GITHUB_OUTPUT"
else
echo "resume=false" >> "$GITHUB_OUTPUT"
echo "version=$CALCULATED_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$CALCULATED_TAG" >> "$GITHUB_OUTPUT"
echo "release-notes-start-tag=$CALCULATED_RELEASE_NOTES_START_TAG" >> "$GITHUB_OUTPUT"
fi

- name: Validate published release
if: github.event_name == 'release'
id: published-release
Expand All @@ -138,14 +98,14 @@ jobs:
- name: Build and test
uses: Kralizek/github-actions/actions/dotnet-build@v0.3
env:
MinVerVersionOverride: ${{ github.event_name == 'workflow_dispatch' && steps.manual-release.outputs.version || '' }}
MinVerVersionOverride: ${{ github.event_name == 'workflow_dispatch' && steps.calculated-version.outputs.version || '' }}
with:
checkout: false
global_json_file: global.json

- name: Pack
env:
MinVerVersionOverride: ${{ github.event_name == 'workflow_dispatch' && steps.manual-release.outputs.version || '' }}
MinVerVersionOverride: ${{ github.event_name == 'workflow_dispatch' && steps.calculated-version.outputs.version || '' }}
run: dotnet pack --configuration $CONFIGURATION --no-build --output ./artifacts/packages

- name: Read package version
Expand All @@ -169,7 +129,7 @@ jobs:
- name: Validate package version
env:
PACKAGE_VERSION: ${{ steps.package-version.outputs.version }}
EXPECTED_VERSION: ${{ github.event_name == 'release' && steps.published-release.outputs.version || steps.manual-release.outputs.version }}
EXPECTED_VERSION: ${{ github.event_name == 'release' && steps.published-release.outputs.version || steps.calculated-version.outputs.version }}
shell: bash
run: |
set -euo pipefail
Expand All @@ -196,15 +156,39 @@ jobs:
echo "Release channel: ${{ inputs.release_channel }}"
echo "Package version: ${{ steps.package-version.outputs.version }}"

- name: Create or reuse draft GitHub release
- name: Ensure draft GitHub release
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
id: ensured-release
uses: Kralizek/github-actions/actions/ensure-github-release@v0.5
with:
tag: ${{ steps.calculated-version.outputs.tag }}
target: ${{ github.sha }}
prerelease: ${{ steps.calculated-version.outputs.prerelease }}
release-notes-start-tag: ${{ steps.calculated-version.outputs['release-notes-start-tag'] }}
draft: 'true'

- name: Validate resumable draft release
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.manual-release.outputs.tag }}
PREVIOUS_TAG: ${{ steps.manual-release.outputs['release-notes-start-tag'] }}
RELEASE_CHANNEL: ${{ inputs.release_channel }}
RESUME: ${{ steps.manual-release.outputs.resume }}
run: bash .github/workflows/scripts/create-or-reuse-draft-release.sh
TAG: ${{ steps.ensured-release.outputs.tag }}
EXPECTED_PRERELEASE: ${{ steps.calculated-version.outputs.prerelease }}
shell: bash
run: |
set -euo pipefail
release=$(gh api "repos/${{ github.repository }}/releases/tags/$TAG")
if [[ "$(jq -r .draft <<< "$release")" != true ]]; then
echo "::error::Release $TAG is already published; it cannot be resumed as a draft."
exit 1
fi
if [[ "$(jq -r .author.login <<< "$release")" != "github-actions[bot]" ]]; then
echo "::error::Draft release $TAG was not created by GitHub Actions."
exit 1
fi
if [[ "$(jq -r .prerelease <<< "$release")" != "$EXPECTED_PRERELEASE" ]]; then
echo "::error::Draft release $TAG prerelease classification differs from calculated version (expected $EXPECTED_PRERELEASE)."
exit 1
fi

- name: Configure GitHub Packages source
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)
Expand Down Expand Up @@ -245,7 +229,7 @@ jobs:
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || steps.manual-release.outputs.tag }}
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || steps.calculated-version.outputs.tag }}
run: >-
gh release upload "$RELEASE_TAG"
./artifacts/packages/*.nupkg
Expand All @@ -256,19 +240,19 @@ jobs:
- name: Fetch manual release tag
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
env:
TAG: ${{ steps.manual-release.outputs.tag }}
TAG: ${{ steps.calculated-version.outputs.tag }}
run: git fetch origin "refs/tags/$TAG:refs/tags/$TAG"

- name: Validate manual release tag
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
uses: Kralizek/github-actions/actions/validate-release@v0.3
with:
tag: ${{ steps.manual-release.outputs.tag }}
prerelease: ${{ inputs.release_channel != 'stable' }}
tag: ${{ steps.calculated-version.outputs.tag }}
prerelease: ${{ steps.calculated-version.outputs.prerelease }}

- name: Publish GitHub release
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.manual-release.outputs.tag }}
TAG: ${{ steps.calculated-version.outputs.tag }}
run: gh release edit "$TAG" --repo "${{ github.repository }}" --draft=false
33 changes: 0 additions & 33 deletions .github/workflows/scripts/create-or-reuse-draft-release.sh

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/scripts/detect-resumable-release.sh

This file was deleted.

Loading