Skip to content

Commit 27f29cb

Browse files
committed
Added layered workflows
1 parent 642e988 commit 27f29cb

File tree

3 files changed

+213
-4
lines changed

3 files changed

+213
-4
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: "Build"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
projectName:
7+
description: 'The name of the project'
8+
required: true
9+
type: string
10+
sourceFolder:
11+
description: 'The name of the source directory'
12+
default: source
13+
type: string
14+
environment:
15+
description: 'The build environment'
16+
default: development
17+
type: string
18+
configuration:
19+
description: 'The build configuration'
20+
default: Release
21+
type: string
22+
outputs:
23+
artifact:
24+
description: 'Artifact name'
25+
value: ${{ jobs.build.outputs.artifact }}
26+
27+
jobs:
28+
build:
29+
name: Build
30+
runs-on: 'alpine-latest'
31+
permissions:
32+
contents: read
33+
env:
34+
configuration: ${{ inputs.configuration }}
35+
projectFile: '${{ inputs.sourceFolder }}/${{ inputs.projectName }}/${{ inputs.projectName }}.csproj'
36+
artifactName: "${{ inputs.sourceFolder }}-build"
37+
38+
outputs:
39+
artifactName: ${{ env.artifactName }}
40+
projectFile: ${{ env.projectFile }}
41+
42+
steps:
43+
- name: Download source repository artifact from the previous job
44+
id: artifacts
45+
uses: actions/download-artifact@v3
46+
with:
47+
name: ${{ inputs.sourceFolder }}
48+
path: .
49+
50+
# https://github.com/actions/setup-dotnet
51+
- name: Get .NET externals
52+
uses: actions/setup-dotnet@v3
53+
with:
54+
dotnet-version: 8.0.x
55+
dotnet-quality: 'ga'
56+
57+
# https://github.com/actions/cache/blob/main/examples.md#c---nuget
58+
- name: Get any cached NuGet packages from the last run
59+
uses: actions/cache@v3
60+
with:
61+
path: '~/.nuget/packages'
62+
key: nugetpackages-${{ runner.os }}-${{ hashFiles('source/**/*.csproj') }}
63+
restore-keys: nugetpackages-${{ runner.os }}
64+
65+
- name: Restore all project dependencies
66+
shell: pwsh
67+
run: |
68+
Get-ChildItem -Path "./${{ inputs.sourceFolder }}" -Filter "*.csproj" -File -Recurse |
69+
Select-Object -ExpandProperty BaseName | ForEach-Object {
70+
Write-Output "Restoring ${{ inputs.sourceFolder }}/$_/$_.csproj"
71+
dotnet restore "./${{ inputs.sourceFolder }}/$_/$_.csproj"
72+
}
73+
74+
- name: Build main project
75+
run: dotnet build $projectFile --configuration $configuration --no-restore
76+
77+
# https://github.com/actions/upload-artifact
78+
- name: Upload build artifacts
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: ${{ env.artifactName }}
82+
path: .
83+
retention-days: 1
84+
if-no-files-found: error # or 'ignore', defaults to `warn`
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: 🧬 Version
2+
run-name: Get version with GitVersion
3+
4+
on:
5+
workflow_call:
6+
outputs:
7+
semVer:
8+
description: 'GitVersion semantic version'
9+
value: ${{ jobs.version.outputs.majorMinorBuild }}
10+
nuGetVersion:
11+
description: 'GitVersion suffix for NuGet package'
12+
value: ${{ jobs.version.outputs.nuGetVersion }}
13+
majorMinorBuild:
14+
description: 'GitVersion major.minor.build version'
15+
value: ${{ jobs.version.outputs.majorMinorBuild }}
16+
projectName:
17+
description: 'Git repository project name'
18+
value: ${{ jobs.version.outputs.projectName }}
19+
projectFiles:
20+
description: 'Git repository project files'
21+
value: ${{ jobs.version.outputs.projectFiles }}
22+
23+
jobs:
24+
version:
25+
name: Version
26+
runs-on: 'ubuntu-latest'
27+
28+
outputs: # alternative usage: $GitVersion_<outputName>
29+
semVer: ${{ steps.gitversion.outputs.semVer }}
30+
nuGetVersion: ${{ steps.gitversion.outputs.nuGetVersion }}
31+
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
32+
projectName: ${{ steps.github_repository.outputs.basename }}
33+
projectFiles: ${{ steps.github_repository.outputs.projects }}
34+
35+
steps:
36+
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
37+
- name: Fetch all tags and branches for GitVersion
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Get Git repository project name
43+
id: github_repository
44+
run: echo "::set-output name=basename::$(basename '${{ github.repository }}')"
45+
46+
- name: List all project files in the directory
47+
shell: bash
48+
run: |
49+
shopt -s globstar
50+
projects=""
51+
for project in ./**/*.csproj; do
52+
echo "$project"
53+
projects+="::$project"
54+
done
55+
56+
# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/setup/usage-examples.md#example-1
57+
- name: Set up GitVersion
58+
uses: gittools/actions/gitversion/setup@v0
59+
with:
60+
versionSpec: '5.x'
61+
62+
# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/execute/usage-examples.md#example-5
63+
- name: Use GitVersion to determine version
64+
id: gitversion # e.g. steps.gitversion.outputs.<outputName>
65+
uses: gittools/actions/gitversion/execute@v0
66+
67+
# For a list of all GitVersion Version Variables, see https://gitversion.net/docs/reference/variables
68+
- run: |
69+
echo "Save the GitVersion outputs to a file."
70+
echo "${{ steps.gitversion.outputs }}" > version.txt
71+
72+
# pwsh> dotnet-gitversion | ConvertFrom-Json
73+
- if: contains(steps.gitversion.outputs.branchName, 'main')
74+
run: |
75+
echo "Generate release notes from the Git commit log."
76+
last_tag=$(git describe --abbrev=0 --tags)
77+
echo '## ${{ env.title }} changes up to $last_tag' > release-notes.txt
78+
git log --pretty=format:"- %s" $last_tag..HEAD >> release-notes.txt
79+
env:
80+
title: '${{ steps.github_repository.outputs.basename }} version ${{ steps.gitversion.outputs.preReleaseLabel }}'
81+
82+
# https://github.com/actions/upload-artifact
83+
- name: Upload version artifacts
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: ${{ inputs.sourceFolder }}
87+
path: |
88+
version.txt
89+
release-notes.txt
90+
${{ inputs.sourceFolder }}
91+
retention-days: 1
92+
if-no-files-found: error # or 'ignore', defaults to `warn`
93+
94+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
95+
- name: Markdown workflow job summary
96+
run: |
97+
echo '### ${{ env.WorkflowName }} build summary' >> $GITHUB_STEP_SUMMARY
98+
echo "${{ github.repository }} ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
99+
echo 'Label: ${{ steps.gitversion.outputs.preReleaseLabel }}' >> $GITHUB_STEP_SUMMARY
100+
echo 'Version: ${{ steps.gitversion.outputs.fullSemVer }}' >> $GITHUB_STEP_SUMMARY
101+
echo 'Commit Date: ${{ steps.gitversion.outputs.commitDate }}' >> $GITHUB_STEP_SUMMARY
102+
env:
103+
WorkflowName: '${{ steps.github_repository.outputs.basename }} version ${{ steps.gitversion.outputs.semVer }}'

.github/workflows/devops.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@ on:
99

1010
# Cancel any other running workflows with the same ID
1111
concurrency:
12-
group: cd-development-${{ github.ref }}
12+
group: cd-devops-${{ github.ref }}
1313
cancel-in-progress: true
1414

15+
# https://docs.github.com/en/actions/using-workflows/reusing-workflows
1516
jobs:
16-
version:
17-
name: 🧱 CI/CD
18-
uses: ./.github/workflows/_version.yml
17+
# version:
18+
# uses: ./.github/workflows/_version.yml
19+
20+
build:
21+
uses: ./.github/workflows/_build-test.yml
22+
with:
23+
environment: release
24+
configuration: Release
25+
project-name: MailKitSimplified
26+
permissions:
27+
contents: read
28+
secrets: inherit
29+
30+
deploy:
31+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
32+
needs: [ build ]
33+
uses: ./.github/workflows/_deploy-nuget.yml
34+
with:
35+
project-name: MailKitSimplified
36+
version: ${{ needs.build.outputs.version }}
37+
permissions:
38+
contents: read
39+
packages: write
40+
secrets: inherit

0 commit comments

Comments
 (0)