From d49ad1b5ba409d137d6b2ee7eab9b3de09134b91 Mon Sep 17 00:00:00 2001 From: Alex Thomson Date: Fri, 18 Aug 2023 23:08:49 +1200 Subject: [PATCH] Update dotnet workflow --- .github/workflows/dotnet.yml | 50 +++++++++++++++++------------------- Directory.Build.targets | 20 +++++++++++++++ 2 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 Directory.Build.targets diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a05697a..46a8f3f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -8,51 +8,49 @@ on: pull_request: branches: [ main ] +permissions: + contents: write + +env: + CONFIGURATION: Release + DOTNET_VERSION: 7.0.x + jobs: dotnet: name: .NET runs-on: ubuntu-latest - permissions: - contents: write steps: - name: Checkout uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: ${{ env.DOTNET_VERSION }} + - name: Setup Quill + run: curl -sSfL https://raw.githubusercontent.com/anchore/quill/main/install.sh | sh -s -- -b /usr/local/bin + - name: Setup Release + if: github.event_name == 'create' && github.event.ref_type == 'tag' + run: echo "RELEASE_NAME=${GITHUB_REPOSITORY#*/} ${GITHUB_REF_NAME}" >> $GITHUB_ENV - name: Restore run: dotnet restore - name: Test - run: dotnet test --configuration Release --no-restore --verbosity normal - - name: Publish linux-x64 - run: dotnet publish --configuration Release --no-restore --output ./dist/linux-x64 --runtime linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + run: dotnet test --configuration "$CONFIGURATION" --no-restore --verbosity normal - name: Publish linux-arm64 - run: dotnet publish --configuration Release --no-restore --output ./dist/linux-arm64 --runtime linux-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - - name: Publish osx-x64 - run: dotnet publish --configuration Release --no-restore --output ./dist/osx-x64 --runtime osx-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime linux-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + - name: Publish linux-x64 + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - name: Publish osx-arm64 - run: dotnet publish --configuration Release --no-restore --output ./dist/osx-arm64 --runtime osx-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - - name: Publish win-x64 - run: dotnet publish --configuration Release --no-restore --output ./dist/win-x64 --runtime win-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime osx-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + - name: Publish osx-x64 + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime osx-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - name: Publish win-arm64 - run: dotnet publish --configuration Release --no-restore --output ./dist/win-arm64 --runtime win-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - - name: Archive Binaries - if: github.event_name == 'create' && github.event.ref_type == 'tag' - run: | - cd $GITHUB_WORKSPACE/dist/linux-x64 && zip -mr ../${GITHUB_REPOSITORY#*/}-linux-x64.zip . - cd $GITHUB_WORKSPACE/dist/linux-arm64 && zip -mr ../${GITHUB_REPOSITORY#*/}-linux-arm64.zip . - cd $GITHUB_WORKSPACE/dist/osx-x64 && zip -mr ../${GITHUB_REPOSITORY#*/}-osx-x64.zip . - cd $GITHUB_WORKSPACE/dist/osx-arm64 && zip -mr ../${GITHUB_REPOSITORY#*/}-osx-arm64.zip . - cd $GITHUB_WORKSPACE/dist/win-x64 && zip -mr ../${GITHUB_REPOSITORY#*/}-win-x64.zip . - cd $GITHUB_WORKSPACE/dist/win-arm64 && zip -mr ../${GITHUB_REPOSITORY#*/}-win-arm64.zip . - - name: Setup Release - if: github.event_name == 'create' && github.event.ref_type == 'tag' - run: echo "release_name=${GITHUB_REPOSITORY#*/} ${GITHUB_REF_NAME}" >> $GITHUB_ENV + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime win-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial + - name: Publish win-x64 + run: dotnet publish --configuration "$CONFIGURATION" --no-restore --runtime win-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:SuppressTrimAnalysisWarnings=true /p:TrimMode=partial - name: Release if: github.event_name == 'create' && github.event.ref_type == 'tag' uses: softprops/action-gh-release@v1 with: files: ./dist/* generate_release_notes: true - name: ${{ env.release_name }} \ No newline at end of file + name: ${{ env.RELEASE_NAME }} \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..2b9b689 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,20 @@ + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), "dist")) + $(ProjectName.Substring($([MSBuild]::Add($(ProjectName.IndexOf('.')), 1))))-$(RuntimeIdentifier) + $([System.IO.Path]::Combine($(ArchiveDir), "$(ArchiveName).zip")) + + + + + \ No newline at end of file