From 39167e41e3ca67bfa4d6fa3038abefa19d5d19cf Mon Sep 17 00:00:00 2001 From: glopesdev Date: Thu, 18 Jul 2024 09:30:52 +0100 Subject: [PATCH 1/2] Publish packages to github on push to main --- .github/workflows/ci-audit.yml | 79 ++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci-audit.yml b/.github/workflows/ci-audit.yml index dcec2d2..c3ba676 100644 --- a/.github/workflows/ci-audit.yml +++ b/.github/workflows/ci-audit.yml @@ -5,7 +5,6 @@ on: branches: [ main ] pull_request: branches: [ main ] - workflow_dispatch: env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true @@ -29,34 +28,58 @@ jobs: collect-packages: true runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.x - - - name: Restore - run: dotnet restore - - - name: Build - run: dotnet build --no-restore --configuration ${{ matrix.configuration }} + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + + - name: Restore + run: dotnet restore + + - name: Build + run: dotnet build --no-restore --configuration ${{ matrix.configuration }} + + - name: Test + run: dotnet test --no-build --configuration ${{ matrix.configuration }} ${{ matrix.test-filter }} + + - name: Pack + id: pack + if: matrix.collect-packages + env: + CiBuildVersionSuffix: ${{ github.ref_name == 'main' && env.CiRunMainSuffix || env.CiRunPullSuffix }} + run: dotnet pack --no-build --configuration ${{ matrix.configuration }} - - name: Test - run: dotnet test --no-build --configuration ${{ matrix.configuration }} ${{ matrix.test-filter }} + - name: Collect packages + uses: actions/upload-artifact@v4 + if: matrix.collect-packages && steps.pack.outcome == 'success' && always() + with: + name: Packages + if-no-files-found: error + path: artifacts/package/${{matrix.configuration}}/** + + publish-github: + runs-on: ubuntu-latest + permissions: + packages: write + needs: [audit] + if: github.event_name == 'push' + steps: + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x - - name: Pack - id: pack - if: matrix.collect-packages - env: - CiBuildVersionSuffix: ${{ github.ref_name == 'main' && env.CiRunMainSuffix || env.CiRunPullSuffix }} - run: dotnet pack --no-build --configuration ${{ matrix.configuration }} + - name: Download packages + uses: actions/download-artifact@v4 + with: + name: Packages + path: Packages - - name: Collect packages - uses: actions/upload-artifact@v4 - if: matrix.collect-packages && steps.pack.outcome == 'success' && always() - with: - name: Packages - if-no-files-found: error - path: artifacts/package/${{matrix.configuration}}/** \ No newline at end of file + - name: Push to GitHub Packages + run: dotnet nuget push "Packages/*.nupkg" --skip-duplicate --no-symbols --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/${{github.repository_owner}} + env: + # This is a workaround for https://github.com/NuGet/Home/issues/9775 + DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0 \ No newline at end of file From 8435ab27846ecb528bde99d6c63a08a64a8a762a Mon Sep 17 00:00:00 2001 From: glopesdev Date: Thu, 18 Jul 2024 09:46:16 +0100 Subject: [PATCH 2/2] Tag CI builds with ref name on push run --- .github/workflows/ci-audit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-audit.yml b/.github/workflows/ci-audit.yml index c3ba676..544d200 100644 --- a/.github/workflows/ci-audit.yml +++ b/.github/workflows/ci-audit.yml @@ -11,7 +11,7 @@ env: DOTNET_GENERATE_ASPNET_CERTIFICATE: false ContinuousIntegrationBuild: true CiRunNumber: ${{ github.run_number }} - CiRunMainSuffix: ci${{ github.run_number }} + CiRunPushSuffix: ${{ github.ref_name }}-ci${{ github.run_number }} CiRunPullSuffix: pull-${{ github.event.number }}-ci${{ github.run_number }} jobs: audit: @@ -49,7 +49,7 @@ jobs: id: pack if: matrix.collect-packages env: - CiBuildVersionSuffix: ${{ github.ref_name == 'main' && env.CiRunMainSuffix || env.CiRunPullSuffix }} + CiBuildVersionSuffix: ${{ github.event_name == 'push' && env.CiRunPushSuffix || env.CiRunPullSuffix }} run: dotnet pack --no-build --configuration ${{ matrix.configuration }} - name: Collect packages