From e9371c37223c9f62dca8365167d3b25e24c1af2f Mon Sep 17 00:00:00 2001 From: Loek Duys Date: Wed, 21 Aug 2024 08:25:48 +0200 Subject: [PATCH] feat: add condition to release (only when new SF version is available) (#202) * feat: add condition to release (only when new SF version is available) * feat: move detection up - disable SF install * fix: use pwsh * fix: use master * fix: get all branches * fix: path * fix: add master * fix: add extra echo * fix: variable * fix: use GITHUB_OUTPUT --- .github/workflows/NuGetCD.yml | 58 +++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/.github/workflows/NuGetCD.yml b/.github/workflows/NuGetCD.yml index c5be1f0..65fab6e 100644 --- a/.github/workflows/NuGetCD.yml +++ b/.github/workflows/NuGetCD.yml @@ -15,7 +15,41 @@ jobs: env: Test_Project_File: \test\ServiceFabric.Mocks.NetCoreTests\ServiceFabric.Mocks.NetCoreTests.csproj steps: - - uses: actions/checkout@v3 + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup master branch locally without switching current branch + run: git fetch origin master:master + + # Check for SF updates before creating a new release + - name: Check for SF NuGet Package Version Change + id: check_version + shell: pwsh + run: | + # Specify the package you want to check + $PACKAGE_NAME="Microsoft.ServiceFabric.Actors" + $csprojPath = "./src/ServiceFabric.Mocks/ServiceFabric.Mocks.csproj" + + # Get the diff and check for the package reference + $diff = git diff master -- $csprojPath + + if ($diff -match "> $env:GITHUB_OUTPUT + } else { + Write-Host "No changes to SF package version." + echo "sf_ver_changed=false" >> $env:GITHUB_OUTPUT + } + + # Run echo + - name: Echo status + if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' }} + run: echo "This run will create a new release on GitHub and Nuget" + - name: Echo status + if: ${{ steps.check_version.outputs.sf_ver_changed == 'false' }} + run: echo "This run will NOT create a new release on GitHub and Nuget" # create version - name: Bump version and push tag @@ -32,14 +66,14 @@ jobs: dotnet-version: 6.0.x # Install SF SDK - - name: Install SF - shell: pwsh - run: | - Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser - $ProgressPreference = 'SilentlyContinue' - Invoke-RestMethod -OutFile setup.exe -Method GET -Uri https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856/MicrosoftServiceFabric.10.1.1951.9590.exe - #.\setup.exe /accepteula /force /quiet - Start-Process setup.exe -UseNewEnvironment -ArgumentList '/accepteula /force /quiet' -Wait + # - name: Install SF + # shell: pwsh + # run: | + # Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser + # $ProgressPreference = 'SilentlyContinue' + # Invoke-RestMethod -OutFile setup.exe -Method GET -Uri https://download.microsoft.com/download/b/8/a/b8a2fb98-0ec1-41e5-be98-9d8b5abf7856/MicrosoftServiceFabric.10.1.2338.9590.exe + # #.\setup.exe /accepteula /force /quiet + # Start-Process setup.exe -UseNewEnvironment -ArgumentList '/accepteula /force /quiet' -Wait # Create SNK - name: Create SNK @@ -63,11 +97,12 @@ jobs: run: dotnet build --configuration RELEASE -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} # Run dotnet release pack - - name: Run build + - name: Run pack run: dotnet pack --configuration RELEASE -p:PackageVersion=${{ steps.tag_version.outputs.new_version }} -o ${{ github.workspace }} # create GH release - name: Create a GitHub release + if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' }} uses: loekd/release-action@v1 with: tag: ${{ steps.tag_version.outputs.new_tag }} @@ -76,6 +111,7 @@ jobs: # publish nuget package artifact - name: Upload Package for Publishing + if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' }} uses: actions/upload-artifact@v3 with: name: PackedLib @@ -83,10 +119,12 @@ jobs: # publish GH nuget package artifact - name: Push Package to GitHub + if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' }} run: dotnet nuget push --api-key ${{secrets.GITHUB_TOKEN}} --source "https://nuget.pkg.github.com/loekd/index.json" ${{ github.workspace }}/ServiceFabric.Mocks.${{ steps.tag_version.outputs.new_version }}.nupkg # publish packge to nuget - name: Push Package to GitHub + if: ${{ steps.check_version.outputs.sf_ver_changed == 'true' }} run: dotnet nuget push --api-key ${{secrets.NUGETPUSH}} --source "https://api.nuget.org/v3/index.json" ${{ github.workspace }}/ServiceFabric.Mocks.${{ steps.tag_version.outputs.new_version }}.nupkg