Skip to content

Enhance release workflow to include checksum generation and update RE… #1

Enhance release workflow to include checksum generation and update RE…

Enhance release workflow to include checksum generation and update RE… #1

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
release_version:
description: "Release tag or version label, for example v1.0.1"
required: true
type: string
publish_to_github_release:
description: "Upload packaged artifacts to a GitHub release"
required: true
default: false
type: boolean
permissions:
contents: write
concurrency:
group: release-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
name: Resolve Release Context
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.resolve.outputs.release_version }}
should_upload_release: ${{ steps.resolve.outputs.should_upload_release }}
steps:
- name: Resolve release metadata
id: resolve
shell: pwsh
run: |
if ("${{ github.event_name }}" -eq "push") {
$releaseVersion = "${{ github.ref_name }}"
$shouldUpload = "true"
}
else {
$releaseVersion = "${{ inputs.release_version }}"
$shouldUpload = if ("${{ inputs.publish_to_github_release }}" -eq "true") { "true" } else { "false" }
}
if ([string]::IsNullOrWhiteSpace($releaseVersion)) {
throw "A release version could not be resolved."
}
"release_version=$releaseVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"should_upload_release=$shouldUpload" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
verify:
name: Verify Release Build
needs: prepare
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup .NET 8 SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore ApiHealthDashboard.sln
- name: Build solution
run: dotnet build ApiHealthDashboard.sln -c Release --no-restore
- name: Run tests
run: dotnet test ApiHealthDashboard.sln -c Release --no-build
publish:
name: Publish ${{ matrix.runtime }}
needs:
- prepare
- verify
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- runtime: win-x64
archive_extension: zip
- runtime: linux-x64
archive_extension: tar.gz
env:
PROJECT_PATH: src/ApiHealthDashboard/ApiHealthDashboard.csproj
RELEASE_VERSION: ${{ needs.prepare.outputs.release_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup .NET 8 SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Publish self-contained app
run: dotnet publish ${{ env.PROJECT_PATH }} -c Release -r ${{ matrix.runtime }} --self-contained true -o ./artifacts/publish/${{ matrix.runtime }}
- name: Package Windows artifact
if: ${{ matrix.archive_extension == 'zip' }}
shell: pwsh
run: Compress-Archive -Path "./artifacts/publish/${{ matrix.runtime }}/*" -DestinationPath "./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.zip" -Force
- name: Package Linux artifact
if: ${{ matrix.archive_extension == 'tar.gz' }}
run: tar -C "./artifacts/publish/${{ matrix.runtime }}" -czf "./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.tar.gz" .
- name: Generate checksum
run: sha256sum "./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}" > "./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}.sha256"
- name: Upload packaged artifact to workflow run
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.runtime }}
path: |
./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}
./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}.sha256
if-no-files-found: error
- name: Upload artifacts to GitHub Release
if: ${{ needs.prepare.outputs.should_upload_release == 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_VERSION }}
generate_release_notes: true
fail_on_unmatched_files: true
files: |
./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}
./artifacts/ApiHealthDashboard-${{ env.RELEASE_VERSION }}-${{ matrix.runtime }}.${{ matrix.archive_extension }}.sha256