Publish CLI #1
Workflow file for this run
This file contains 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: Publish CLI | |
on: | |
release: | |
types: [published] | |
env: | |
PROJECT_NAME: NationsConverterCLI | |
ARTIFACT_NAME: artifact | |
permissions: | |
contents: write # important for release description edit and asset upload | |
packages: read | |
jobs: | |
prepare-description: | |
runs-on: ubuntu-latest | |
name: Set release description | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set release information | |
run: gh release edit ${{ github.ref_name }} -n "$(echo -e '### *[Release is being automatically created, please wait...](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*\n\n${{ github.event.release.body }}')" | |
build: | |
needs: prepare-description | |
strategy: | |
matrix: | |
os: [{ os: windows-latest, runtime: win-x64 }, { os: ubuntu-latest, runtime: linux-x64 }] | |
runs-on: ${{ matrix.os.os }} | |
name: Publish with ${{ matrix.os.os }} (${{ matrix.os.runtime }}) | |
env: | |
ZIP_SUFFIX: -${{ matrix.os.runtime }}..zip | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
9.0.x | |
8.0.x | |
- name: Publish | |
run: dotnet publish Src/${{ env.PROJECT_NAME }} | |
-c Release | |
-r ${{ matrix.os.runtime }} | |
-o build/${{ env.PROJECT_NAME }} | |
-p:PublishTrimmed=true | |
-p:PublishSingleFile=true | |
-p:EnableCompressionInSingleFile=true | |
--self-contained | |
- name: Zip to ${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }} | |
uses: thedoctor0/zip-release@main | |
with: | |
directory: build | |
path: ${{ env.PROJECT_NAME }} | |
filename: ../${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }} | |
- name: Calculate SHA256 (Windows) | |
if: matrix.os.os == 'windows-latest' | |
run: | | |
$hash = Get-FileHash -Path '${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }}' -Algorithm SHA256 | |
$hashValue = $hash.Hash.ToLower() | |
Write-Host $hashValue | |
$hashValue | Out-File -FilePath "${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }}.hash.txt" | |
- name: Calculate SHA256 (Linux) | |
run: | | |
sha256sum "${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }}" | awk '{print $1}' | tee >(cat) > ${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }}.hash.txt | |
- name: Upload ${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }} to this release | |
run: gh release upload ${{ github.ref_name }} ${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }} | |
- name: Upload a Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }}-${{ matrix.os.runtime }} | |
path: ${{ env.PROJECT_NAME }}${{ env.ZIP_SUFFIX }}.hash.txt | |
if-no-files-found: error | |
finalize-description: | |
needs: build | |
runs-on: ubuntu-latest | |
name: Finalize release description | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download a Build Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: ${{ env.ARTIFACT_NAME }}-* | |
merge-multiple: true | |
- name: Read hash files | |
run: | | |
echo "HashLinuxX64=$(tr -d '\r' < ${{ env.PROJECT_NAME }}-linux-x64.${{ github.ref_name }}.zip.hash.txt)" >> $GITHUB_ENV | |
echo "HashWinX64=$(tr -d '\r' < ${{ env.PROJECT_NAME }}-win-x64.${{ github.ref_name }}.zip.hash.txt)" >> $GITHUB_ENV | |
- name: Set release information | |
run: gh release edit ${{ github.ref_name }} -n "$(echo -e '${{ github.event.release.body }}\n\n**SHA256 win-x64** `${{ env.HashWinX64 }}`\n**SHA256 linux-x64** `${{ env.HashLinuxX64 }}`\n\nAssets were automatically generated using the [publish workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).')" |