From 7060bdd2105f5cf53539a467504e9ed53d4d7e04 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 15 Sep 2023 14:39:35 +0200 Subject: [PATCH] use GH reusable workflows to reduce .yml duplication (#2037) Co-authored-by: Luis Fraile --- .../healthchecks_azurekeyvault_cd.yml | 23 ++------ .../healthchecks_azurekeyvault_cd_preview.yml | 25 +++------ .../healthchecks_azurekeyvault_ci.yml | 43 +++------------ .../healthchecks_azurekeyvault_secrets_cd.yml | 23 ++------ ...hecks_azurekeyvault_secrets_cd_preview.yml | 25 +++------ .../healthchecks_azurekeyvault_secrets_ci.yml | 44 +++------------ .../reusable_cd_preview_workflow.yml | 37 +++++++++++++ .github/workflows/reusable_cd_workflow.yml | 34 ++++++++++++ .github/workflows/reusable_ci_workflow.yml | 53 +++++++++++++++++++ 9 files changed, 161 insertions(+), 146 deletions(-) create mode 100644 .github/workflows/reusable_cd_preview_workflow.yml create mode 100644 .github/workflows/reusable_cd_workflow.yml create mode 100644 .github/workflows/reusable_ci_workflow.yml diff --git a/.github/workflows/healthchecks_azurekeyvault_cd.yml b/.github/workflows/healthchecks_azurekeyvault_cd.yml index 812ba2bf9d..c1ade34bf7 100644 --- a/.github/workflows/healthchecks_azurekeyvault_cd.yml +++ b/.github/workflows/healthchecks_azurekeyvault_cd.yml @@ -8,22 +8,9 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_workflow.yml + secrets: inherit + with: BUILD_CONFIG: Release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj -c $BUILD_CONFIG - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj -c $BUILD_CONFIG -o ./artifacts - - name: Publish - run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.AzureKeyVault.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + PROJECT_PATH: ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.AzureKeyVault diff --git a/.github/workflows/healthchecks_azurekeyvault_cd_preview.yml b/.github/workflows/healthchecks_azurekeyvault_cd_preview.yml index 03301a940c..16b7912d06 100644 --- a/.github/workflows/healthchecks_azurekeyvault_cd_preview.yml +++ b/.github/workflows/healthchecks_azurekeyvault_cd_preview.yml @@ -8,23 +8,10 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_preview_workflow.yml + secrets: inherit + with: BUILD_CONFIG: Release - VERSION_SUFFIX: rc2.${{ github.run_number }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj -c $BUILD_CONFIG - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts - - name: Publish - run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.AzureKeyVault.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + VERSION_SUFFIX_PREFIX: rc2 + PROJECT_PATH: ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.AzureKeyVault \ No newline at end of file diff --git a/.github/workflows/healthchecks_azurekeyvault_ci.yml b/.github/workflows/healthchecks_azurekeyvault_ci.yml index 4c220c5b52..b934c70f81 100644 --- a/.github/workflows/healthchecks_azurekeyvault_ci.yml +++ b/.github/workflows/healthchecks_azurekeyvault_ci.yml @@ -9,6 +9,7 @@ on: - test/HealthChecks.AzureKeyVault.Tests/** - test/_SHARED/** - .github/workflows/healthchecks_azurekeyvault_ci.yml + - .github/workflows/reusable_ci_workflow.yml - Directory.Build.props - Directory.Build.targets tags-ignore: @@ -22,44 +23,14 @@ on: - test/HealthChecks.AzureKeyVault.Tests/** - test/_SHARED/** - .github/workflows/healthchecks_azurekeyvault_ci.yml + - .github/workflows/reusable_ci_workflow.yml - Directory.Build.props - Directory.Build.targets jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: | - dotnet restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj && - dotnet restore ./test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.Tests.csproj - - name: Check formatting - run: | - dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) && - dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) - - name: Build - run: | - dotnet build --no-restore ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj - dotnet build --no-restore ./test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.Tests.csproj - - name: Test - run: > - dotnet test - ./test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.Tests.csproj - --no-restore - --no-build - --collect "XPlat Code Coverage" - --results-directory .coverage - -- - DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover - - name: Upload Coverage - uses: codecov/codecov-action@v3 - with: - flags: AzureKeyVault - directory: .coverage + uses: ./.github/workflows/reusable_ci_workflow.yml + with: + PROJECT_PATH: ./src/HealthChecks.AzureKeyVault/HealthChecks.AzureKeyVault.csproj + TEST_PROJECT_PATH: ./test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.Tests.csproj + CODECOV_FLAGS: AzureKeyVault \ No newline at end of file diff --git a/.github/workflows/healthchecks_azurekeyvault_secrets_cd.yml b/.github/workflows/healthchecks_azurekeyvault_secrets_cd.yml index b5bea2073b..bf6befe97c 100644 --- a/.github/workflows/healthchecks_azurekeyvault_secrets_cd.yml +++ b/.github/workflows/healthchecks_azurekeyvault_secrets_cd.yml @@ -8,22 +8,9 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_workflow.yml + secrets: inherit + with: BUILD_CONFIG: Release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj -c $BUILD_CONFIG - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj -c $BUILD_CONFIG -o ./artifacts - - name: Publish - run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Azure.KeyVault.Secrets.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + PROJECT_PATH: ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.Azure.KeyVault.Secrets \ No newline at end of file diff --git a/.github/workflows/healthchecks_azurekeyvault_secrets_cd_preview.yml b/.github/workflows/healthchecks_azurekeyvault_secrets_cd_preview.yml index bf8eebd64b..f5c4f1c2e9 100644 --- a/.github/workflows/healthchecks_azurekeyvault_secrets_cd_preview.yml +++ b/.github/workflows/healthchecks_azurekeyvault_secrets_cd_preview.yml @@ -8,23 +8,10 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_preview_workflow.yml + secrets: inherit + with: BUILD_CONFIG: Release - VERSION_SUFFIX: rc1.${{ github.run_number }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj -c $BUILD_CONFIG - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts - - name: Publish - run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Azure.KeyVault.Secrets.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + VERSION_SUFFIX_PREFIX: rc1 + PROJECT_PATH: ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.Azure.KeyVault.Secrets \ No newline at end of file diff --git a/.github/workflows/healthchecks_azurekeyvault_secrets_ci.yml b/.github/workflows/healthchecks_azurekeyvault_secrets_ci.yml index 826777b7ce..9c038b4597 100644 --- a/.github/workflows/healthchecks_azurekeyvault_secrets_ci.yml +++ b/.github/workflows/healthchecks_azurekeyvault_secrets_ci.yml @@ -9,6 +9,7 @@ on: - test/HealthChecks.Azure.KeyVault.Secrets.Tests/** - test/_SHARED/** - .github/workflows/healthchecks_azurekeyvault_secrets_ci.yml + - .github/workflows/reusable_ci_workflow.yml - Directory.Build.props - Directory.Build.targets tags-ignore: @@ -22,44 +23,15 @@ on: - test/HealthChecks.Azure.KeyVault.Secrets.Tests/** - test/_SHARED/** - .github/workflows/healthchecks_azurekeyvault_secrets_ci.yml + - .github/workflows/reusable_ci_workflow.yml - Directory.Build.props - Directory.Build.targets jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: | - dotnet restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj && - dotnet restore ./test/HealthChecks.Azure.KeyVault.Secrets.Tests/HealthChecks.Azure.KeyVault.Secrets.Tests.csproj - - name: Check formatting - run: | - dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) && - dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Azure.KeyVault.Secrets.Tests/HealthChecks.Azure.KeyVault.Secrets.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) - - name: Build - run: | - dotnet build --no-restore ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj - dotnet build --no-restore ./test/HealthChecks.Azure.KeyVault.Secrets.Tests/HealthChecks.Azure.KeyVault.Secrets.Tests.csproj - - name: Test - run: > - dotnet test - ./test/HealthChecks.Azure.KeyVault.Secrets.Tests/HealthChecks.Azure.KeyVault.Secrets.Tests.csproj - --no-restore - --no-build - --collect "XPlat Code Coverage" - --results-directory .coverage - -- - DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover - - name: Upload Coverage - uses: codecov/codecov-action@v3 - with: - flags: AzureKeyVault - directory: .coverage + uses: ./.github/workflows/reusable_ci_workflow.yml + with: + PROJECT_PATH: ./src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj + TEST_PROJECT_PATH: ./test/HealthChecks.Azure.KeyVault.Secrets.Tests/HealthChecks.Azure.KeyVault.Secrets.Tests.csproj + CODECOV_FLAGS: AzureKeyVault + diff --git a/.github/workflows/reusable_cd_preview_workflow.yml b/.github/workflows/reusable_cd_preview_workflow.yml new file mode 100644 index 0000000000..bc35a30b79 --- /dev/null +++ b/.github/workflows/reusable_cd_preview_workflow.yml @@ -0,0 +1,37 @@ +name: Reusable Preview CD Workflow + +on: + workflow_call: + inputs: + BUILD_CONFIG: + required: true + type: string + VERSION_SUFFIX_PREFIX: + required: true + type: string + PROJECT_PATH: + required: true + type: string + PACKAGE_NAME: + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + - name: Restore + run: dotnet restore ${{inputs.PROJECT_PATH}} + - name: Build + run: dotnet build --no-restore ${{inputs.PROJECT_PATH}} -c ${{inputs.BUILD_CONFIG}} + - name: Pack + run: dotnet pack --no-build ${{inputs.PROJECT_PATH}} --version-suffix ${{inputs.VERSION_SUFFIX_PREFIX}}.${{ github.run_number }} -c ${{inputs.BUILD_CONFIG}} -o ./artifacts + - name: Publish + run: dotnet nuget push ./artifacts/${{inputs.PACKAGE_NAME}}.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/reusable_cd_workflow.yml b/.github/workflows/reusable_cd_workflow.yml new file mode 100644 index 0000000000..59f96d4088 --- /dev/null +++ b/.github/workflows/reusable_cd_workflow.yml @@ -0,0 +1,34 @@ +name: Reusable CD Workflow + +on: + workflow_call: + inputs: + BUILD_CONFIG: + required: true + type: string + PROJECT_PATH: + required: true + type: string + PACKAGE_NAME: + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + - name: Restore + run: dotnet restore ${{inputs.PROJECT_PATH}} + - name: Build + run: dotnet build --no-restore ${{inputs.PROJECT_PATH}} -c ${{inputs.BUILD_CONFIG}} + - name: Pack + run: dotnet pack --no-build ${{inputs.PROJECT_PATH}} -c ${{inputs.BUILD_CONFIG}} -o ./artifacts + - name: Publish + run: dotnet nuget push ./artifacts/${{inputs.PACKAGE_NAME}}.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/reusable_ci_workflow.yml b/.github/workflows/reusable_ci_workflow.yml new file mode 100644 index 0000000000..352e8ab3af --- /dev/null +++ b/.github/workflows/reusable_ci_workflow.yml @@ -0,0 +1,53 @@ +name: Reusable CI workflow + +on: + workflow_call: + inputs: + PROJECT_PATH: + required: true + type: string + TEST_PROJECT_PATH: + required: true + type: string + CODECOV_FLAGS: + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + - name: Restore + run: | + dotnet restore ${{inputs.PROJECT_PATH}} && + dotnet restore ${{inputs.TEST_PROJECT_PATH}} + - name: Check formatting + run: | + dotnet format --no-restore --verify-no-changes --severity warn ${{inputs.PROJECT_PATH}} || (echo "Run 'dotnet format' to fix issues" && exit 1) && + dotnet format --no-restore --verify-no-changes --severity warn ${{inputs.TEST_PROJECT_PATH}} || (echo "Run 'dotnet format' to fix issues" && exit 1) + - name: Build + run: | + dotnet build --no-restore ${{inputs.PROJECT_PATH}} + dotnet build --no-restore ${{inputs.TEST_PROJECT_PATH}} + - name: Test + run: > + dotnet test + ${{inputs.TEST_PROJECT_PATH}} + --no-restore + --no-build + --collect "XPlat Code Coverage" + --results-directory .coverage + -- + DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover + - name: Upload Coverage + uses: codecov/codecov-action@v3 + with: + flags: ${{inputs.CODECOV_FLAGS}} + directory: .coverage