Skip to content

Commit

Permalink
use GH reusable workflows to reduce .yml duplication (#2037)
Browse files Browse the repository at this point in the history
Co-authored-by: Luis Fraile <[email protected]>
  • Loading branch information
adamsitnik and lfraile authored Sep 15, 2023
1 parent 33d6641 commit 7060bdd
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 146 deletions.
23 changes: 5 additions & 18 deletions .github/workflows/healthchecks_azurekeyvault_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 6 additions & 19 deletions .github/workflows/healthchecks_azurekeyvault_cd_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 7 additions & 36 deletions .github/workflows/healthchecks_azurekeyvault_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
23 changes: 5 additions & 18 deletions .github/workflows/healthchecks_azurekeyvault_secrets_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 8 additions & 36 deletions .github/workflows/healthchecks_azurekeyvault_secrets_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

37 changes: 37 additions & 0 deletions .github/workflows/reusable_cd_preview_workflow.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/reusable_cd_workflow.yml
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions .github/workflows/reusable_ci_workflow.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7060bdd

Please sign in to comment.