Skip to content

Commit 4d97399

Browse files
authored
Set up dotnet in dependent workflows and misc workflow adjustments (#75)
* Set up dotnet in dependent workflows * Cleanup and add dotnet setup * Rename file for brevity * Cleanup and rename * Update threshholds for coverage * Rename and add workflow files * Trim whitespace * Separate documentation workflow * Test upload docs * Test build docs workflow * Run on commit * Publish docs when enabled * Run tests and allow docs upload * Better name * Add permissions token * consolidate vars * Fix double $ * Only on main branch * Add on develop * Set workflow triggers
1 parent 13aea4b commit 4d97399

9 files changed

+142
-111
lines changed

.github/workflows/build-and-publish-after-merge.yml .github/workflows/build-and-publish.yml

+38-76
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: Build and publish artifacts from main and develop
15+
name: Build and publish
1616

1717
# Triggers build on pushes to the main and develop branches.
1818
on:
1919
push:
2020
branches:
21-
- main
22-
- 'develop**'
21+
- 'main'
22+
- 'develop'
23+
paths:
24+
- '**.h'
25+
- '**.c'
26+
- '**.cs'
27+
- '**.csproj'
28+
- '**.sln'
29+
- '.github/workflows/build-and-publish.yml'
30+
2331
workflow_dispatch:
2432
inputs:
2533
push-to-dev:
2634
description: 'Push to internal NuGet'
27-
required: true
35+
required: false
36+
default: false
2837
type: boolean
2938
version:
3039
description: 'Version'
@@ -39,18 +48,16 @@ permissions:
3948

4049
jobs:
4150
build:
42-
# Give this job a friendly name to show in GitHub UI.
43-
name: Build + Test the SDK
44-
45-
# Even though we build for multiple platforms, we only need to run
46-
# on a single host operating system. This is because we utilize cross-
47-
# build functionality of the dotnet build system.
51+
name: Build
4852
runs-on: windows-2019
4953

5054
steps:
5155
# Checkout the local repository
5256
- uses: actions/checkout@v4
53-
57+
- uses: actions/setup-dotnet@v4
58+
with:
59+
global-json-file: global.json
60+
5461
- name: Add local NuGet repository
5562
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
5663

@@ -65,15 +72,17 @@ jobs:
6572
$versionProp.Save($file.FullName)
6673
6774
# Build the project
68-
# The default GitHub runners seem to have N and N-1 versions of .NET Framework installed. In practice, they seem
69-
# to have even more installed than that, but at a minimum N and N-1 seem like safe assumptions. We can therefore
70-
# save some time and use the pre-installed version rather than downloading a fresh copy.
71-
7275
- name: Build Yubico.NET.SDK.sln
7376
run: dotnet build --configuration ReleaseWithDocs --nologo --verbosity normal Yubico.NET.SDK.sln
7477

75-
# Upload artifacts
78+
# Run tests
79+
- name: Test Yubico.YubiKey
80+
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
81+
82+
- name: Test Yubico.Core
83+
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.Core/tests/Yubico.Core.UnitTests.csproj
7684

85+
# Upload artifacts
7786
- name: Save documentation artifacts
7887
uses: actions/upload-artifact@v4
7988
with:
@@ -88,6 +97,15 @@ jobs:
8897
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.nupkg
8998
Yubico.Core/src/bin/ReleaseWithDocs/*.nupkg
9099
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.nupkg
100+
101+
- name: Save build artifacts
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: Symbols Packages
105+
path: |
106+
Yubico.DotNetPolyfills/src/bin/ReleaseWithDocs/*.snupkg
107+
Yubico.Core/src/bin/ReleaseWithDocs/*.snupkg
108+
Yubico.YubiKey/src/bin/ReleaseWithDocs/*.snupkg
91109
92110
- name: Save build artifacts
93111
uses: actions/upload-artifact@v4
@@ -115,72 +133,16 @@ jobs:
115133
path: |
116134
Yubico.YubiKey/examples/PivSampleCode
117135
Yubico.YubiKey/examples/SharedSampleCode
118-
119-
# Test the project
120-
#
121-
# Here we call `dotnet test` on each individual test project that we want to have run as part of CI. We do this
122-
# to skip running the integration tests which require actual YubiKeys to be present. We have tried using the filter
123-
# capabilities of the `dotnet test` runner tool, however we have found that failures don't always register with
124-
# GitHub when that is done.
125-
126-
- name: Test Yubico.YubiKey
127-
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
128-
129-
- name: Test Yubico.Core
130-
run: dotnet test --configuration ReleaseWithDocs --verbosity normal --no-build --nologo Yubico.Core/tests/Yubico.Core.UnitTests.csproj
131-
132-
publish_docs:
133-
# Give this job a friendly name to show in GitHub UI.
134-
name: Publish documentation
135-
136-
# Publish the docs using Ubuntu as the docker image we want to create is linux-based.
137-
runs-on: ubuntu-latest
138-
139-
# Don't run this step until build completes.
140-
needs: build
141-
142-
# Connection information for our docker image registry
143-
env:
144-
IMAGE_REGISTRY_URL: us-docker.pkg.dev
145-
IMAGE_REGISTRY_PROJECT: support-cluster-769001
146-
IMAGE_REPOSITORY: yesdk
147-
IMAGE_NAME: yesdk-docserver
148-
149-
steps:
150-
# Checkout the local repository as we need the Dockerfile and other things even for this step.
151-
- uses: actions/checkout@v4
152-
153-
# Grab the just-built documentation artifact and inflate the archive at the expected location.
154-
- uses: actions/download-artifact@v4
155-
with:
156-
name: Documentation
157-
path: Yubico.YubiKey/docs/_site/
158-
159-
# Construct the docker image
160-
- name: Docker build
161-
run: |
162-
docker build -t "${IMAGE_NAME}:${{ github.sha }}" .
163136
164-
# Authenticate to Google Cloud
165-
- name: Authenticate
166-
uses: google-github-actions/auth@v2
167-
with:
168-
workload_identity_provider: ${{ vars.GLOBAL_GCP_WORKLOAD_IDENTITY_PROVIDER }}
169-
service_account: [email protected]
170-
171-
# Push our docker image to GCP
172-
- name: Push Docker image
173-
run: |
174-
gcloud auth configure-docker ${IMAGE_REGISTRY_URL} --project ${IMAGE_REGISTRY_PROJECT}
175-
docker tag "${IMAGE_NAME}:${{ github.sha }}" "${IMAGE_REGISTRY_URL}/${IMAGE_REGISTRY_PROJECT}/${IMAGE_REPOSITORY}/${IMAGE_NAME}:${{ github.sha }}"
176-
docker push "${IMAGE_REGISTRY_URL}/${IMAGE_REGISTRY_PROJECT}/${IMAGE_REPOSITORY}/${IMAGE_NAME}:${{ github.sha }}"
177-
echo "New image tag: ${{ github.sha }}"
137+
upload-docs:
138+
name: Upload docs
139+
uses: ./.github/workflows/upload-docs.yml
140+
needs: build
178141

179142
publish-internal:
180143
name: Publish to internal NuGet
181144
runs-on: windows-2019
182145
needs: build
183-
environment: Internal NuGet feed
184146
if: ${{ github.event.inputs.push-to-dev }}
185147
steps:
186148
- uses: actions/download-artifact@v4

.github/workflows/pull-requests.yml .github/workflows/build-pull-requests.yml

+9-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: CI build for pull requests into main and develop
15+
name: Build pull request
1616

1717
# Triggers build on pull requests and pushes to the main and develop branches.
1818
on:
@@ -21,18 +21,18 @@ on:
2121
- main
2222
- 'develop**'
2323
- 'release/**'
24-
push:
25-
branches:
26-
- 'release/**'
24+
paths:
25+
- '**.h'
26+
- '**.c'
27+
- '**.cs'
28+
- '**.csproj'
29+
- '**.sln'
30+
- '.github/workflows/build-pull-requests.yml'
2731

2832
jobs:
2933
build:
3034
# Give this job a friendly name to show in GitHub UI.
31-
name: Build + Test the SDK
32-
33-
# Even though we build for multiple platforms, we only need to run
34-
# on a single host operating system. This is because we utilize cross-
35-
# build functionality of the dotnet build system.
35+
name: Build and test
3636
runs-on: windows-latest
3737
# Build both Debug and ReleaseWithDocs configurations. Most people are probably building 'Debug' the most often. We
3838
# should be sure that Release also builds, and that our documentation also compiles successfully.
@@ -47,9 +47,6 @@ jobs:
4747
with:
4848
global-json-file: global.json
4949

50-
- name: run dotnet version
51-
run: dotnet --version
52-
5350
- name: Add local NuGet repository
5451
run: dotnet nuget add source --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Yubico/index.json"
5552

@@ -77,12 +74,6 @@ jobs:
7774
Yubico.YubiKey/src/bin/${{matrix.configuration}}/**/*.dll
7875
7976
# Test the project
80-
#
81-
# Here we call `dotnet test` on each individual test project that we want to have run as part of CI. We do this
82-
# to skip running the integration tests which require actual YubiKeys to be present. We have tried using the filter
83-
# capabilities of the `dotnet test` runner tool, however we have found that failures don't always register with
84-
# GitHub when that is done.
85-
8677
- name: Test Yubico.YubiKey
8778
run: dotnet test --configuration ${{matrix.configuration}} --verbosity normal --no-build --nologo Yubico.YubiKey/tests/unit/Yubico.YubiKey.UnitTests.csproj
8879

.github/workflows/check-code-formatting.yml

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ on:
2020
- main
2121
- 'develop**'
2222
- 'release/**'
23+
paths:
24+
- '**.h'
25+
- '**.c'
26+
- '**.cs'
27+
- '**.csproj'
28+
- '**.sln'
29+
- '.github/workflows/check-code-formatting.yml'
2330

2431
jobs:
2532
check-code-formatting:

.github/workflows/codeql-analysis.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ on:
2424
branches:
2525
- main
2626
- 'develop**'
27-
paths-ignore:
28-
- '**/*.md'
29-
- '**/*.txt'
30-
- '**/*.xml'
31-
- '**/*.yml'
27+
paths:
28+
- '**.h'
29+
- '**.c'
30+
- '**.cs'
31+
- '**.csproj'
32+
- '**.sln'
33+
- '.github/workflows/codeql-analysis.yml'
3234

3335
permissions:
3436
# required for all workflows

.github/workflows/test-and-cover.yml

+16-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@ on:
2020
- main
2121
- 'develop**'
2222
- 'release/**'
23+
paths:
24+
- '**.h'
25+
- '**.c'
26+
- '**.cs'
27+
- '**.csproj'
28+
- '**.sln'
29+
- '.github/workflows/test-and-cover.yml'
2330
push:
2431
branches:
2532
- main
26-
- 'develop**'
33+
paths:
34+
- '**.h'
35+
- '**.c'
36+
- '**.cs'
37+
- '**.csproj'
38+
- '**.sln'
39+
- '.github/workflows/test-and-cover.yml'
2740

2841
jobs:
2942
test:
@@ -89,7 +102,7 @@ jobs:
89102
hide_complexity: false
90103
indicators: true
91104
output: both
92-
thresholds: "50 70"
105+
thresholds: "33 66"
93106

94107
- name: Add Coverage PR Comment
95108
uses: marocchino/[email protected]
@@ -103,3 +116,4 @@ jobs:
103116
if: always()
104117
with:
105118
trx_files: "${{ github.workspace }}/**/*.trx"
119+
check_name: publish test results

.github/workflows/upload-docs.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2021 Yubico AB
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Upload documentation to GCP
16+
17+
on:
18+
workflow_call:
19+
20+
permissions:
21+
id-token: write
22+
contents: read
23+
24+
env:
25+
image_tag: 'yesdk-docserver'
26+
registry_url: 'us-docker.pkg.dev'
27+
project_id: 'support-cluster-769001'
28+
repository_name: 'yesdk'
29+
service_account: '[email protected]'
30+
31+
jobs:
32+
upload_docs:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/download-artifact@v4
37+
with:
38+
name: Documentation
39+
path: Yubico.YubiKey/docs/_site/
40+
- name: Build nginx image for documentation
41+
run: |
42+
docker build -t "${{ env.image_tag }}:${{ github.sha }}" .
43+
44+
- name: Authenticate to GCP
45+
uses: google-github-actions/auth@v2
46+
with:
47+
workload_identity_provider: ${{ vars.GLOBAL_GCP_WORKLOAD_IDENTITY_PROVIDER }} # Provided at organizational level
48+
service_account: ${{ env.service_account }}
49+
50+
- name: Push Docker image to GCP
51+
run: |
52+
gcloud auth configure-docker ${{ env.registry_url }} --project ${{ env.project_id }}
53+
docker tag "${{ env.image_tag }}:${{ github.sha }}" "${{ env.registry_url }}/${{ env.project_id }}/${{ env.repository_name }}/${{ env.image_tag }}:${{ github.sha }}"
54+
docker push "${{ env.registry_url }}/${{ env.project_id }}/${{ env.repository_name }}/${{ env.image_tag }}:${{ github.sha }}"
55+
echo "New image tag: ${{ github.sha }}"

Yubico.NET.SDK.sln

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{8FFE
2626
EndProject
2727
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{14C2FBE2-2204-46A5-9FE8-A770CB5A0261}"
2828
ProjectSection(SolutionItems) = preProject
29-
.github\workflows\build-and-publish-after-merge.yml = .github\workflows\build-and-publish-after-merge.yml
3029
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
31-
.github\workflows\cross-build-nativeshims.yml = .github\workflows\cross-build-nativeshims.yml
32-
.github\workflows\pull-requests.yml = .github\workflows\pull-requests.yml
30+
.github\workflows\build-and-publish.yml = .github\workflows\build-and-publish.yml
31+
.github\workflows\build-pull-requests.yml = .github\workflows\build-pull-requests.yml
32+
.github\workflows\build-nativeshims.yml = .github\workflows\build-nativeshims.yml
33+
.github\workflows\test-and-cover.yml = .github\workflows\test-and-cover.yml
3334
EndProjectSection
3435
EndProject
3536
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Yubico.Core", "Yubico.Core", "{45D2A3BE-5111-4890-8898-2D43DB658A40}"

Yubico.YubiKey/src/Yubico.YubiKey.csproj

+6-7
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,13 @@ limitations under the License. -->
133133
<ItemGroup Label="Expose internal test hooks to Unit Test projects">
134134

135135
<!-- Expose internal test hooks -->
136+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
137+
<_Parameter1>$(AssemblyName).UnitTests,PublicKey=00240000048000001401000006020000002400005253413100080000010001003312c63e1417ad4652242148c599b55c50d3213c7610b4cc1f467b193bfb8d131de6686268a9db307fcef9efcd5e467483fe9015307e5d0cf9d2fd4df12f29a1c7a72e531d8811ca70f6c80c4aeb598c10bb7fc48742ab86aa7986b0ae9a2f4876c61e0b81eb38e5b549f1fc861c633206f5466bfde021cb08d094742922a8258b582c3bc029eab88c98d476dac6e6f60bc0016746293f5337c68b22e528931b6494acddf1c02b9ea3986754716a9f2a32c59ff3d97f1e35ee07ca2972b0269a4cde86f7b64f80e7c13152c0f84083b5cc4f06acc0efb4316ff3f08c79bc0170229007fb27c97fb494b22f9f7b07f45547e263a44d5a7fe7da6a945a5e47afc9</_Parameter1>
138+
</AssemblyAttribute>
136139

137-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
138-
<_Parameter1>$(AssemblyName).UnitTests,PublicKey=00240000048000001401000006020000002400005253413100080000010001003312c63e1417ad4652242148c599b55c50d3213c7610b4cc1f467b193bfb8d131de6686268a9db307fcef9efcd5e467483fe9015307e5d0cf9d2fd4df12f29a1c7a72e531d8811ca70f6c80c4aeb598c10bb7fc48742ab86aa7986b0ae9a2f4876c61e0b81eb38e5b549f1fc861c633206f5466bfde021cb08d094742922a8258b582c3bc029eab88c98d476dac6e6f60bc0016746293f5337c68b22e528931b6494acddf1c02b9ea3986754716a9f2a32c59ff3d97f1e35ee07ca2972b0269a4cde86f7b64f80e7c13152c0f84083b5cc4f06acc0efb4316ff3f08c79bc0170229007fb27c97fb494b22f9f7b07f45547e263a44d5a7fe7da6a945a5e47afc9</_Parameter1>
139-
</AssemblyAttribute>
140-
141-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
142-
<_Parameter1>$(AssemblyName).IntegrationTests,PublicKey=00240000048000001401000006020000002400005253413100080000010001003312c63e1417ad4652242148c599b55c50d3213c7610b4cc1f467b193bfb8d131de6686268a9db307fcef9efcd5e467483fe9015307e5d0cf9d2fd4df12f29a1c7a72e531d8811ca70f6c80c4aeb598c10bb7fc48742ab86aa7986b0ae9a2f4876c61e0b81eb38e5b549f1fc861c633206f5466bfde021cb08d094742922a8258b582c3bc029eab88c98d476dac6e6f60bc0016746293f5337c68b22e528931b6494acddf1c02b9ea3986754716a9f2a32c59ff3d97f1e35ee07ca2972b0269a4cde86f7b64f80e7c13152c0f84083b5cc4f06acc0efb4316ff3f08c79bc0170229007fb27c97fb494b22f9f7b07f45547e263a44d5a7fe7da6a945a5e47afc9</_Parameter1>
143-
</AssemblyAttribute>
140+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
141+
<_Parameter1>$(AssemblyName).IntegrationTests,PublicKey=00240000048000001401000006020000002400005253413100080000010001003312c63e1417ad4652242148c599b55c50d3213c7610b4cc1f467b193bfb8d131de6686268a9db307fcef9efcd5e467483fe9015307e5d0cf9d2fd4df12f29a1c7a72e531d8811ca70f6c80c4aeb598c10bb7fc48742ab86aa7986b0ae9a2f4876c61e0b81eb38e5b549f1fc861c633206f5466bfde021cb08d094742922a8258b582c3bc029eab88c98d476dac6e6f60bc0016746293f5337c68b22e528931b6494acddf1c02b9ea3986754716a9f2a32c59ff3d97f1e35ee07ca2972b0269a4cde86f7b64f80e7c13152c0f84083b5cc4f06acc0efb4316ff3f08c79bc0170229007fb27c97fb494b22f9f7b07f45547e263a44d5a7fe7da6a945a5e47afc9</_Parameter1>
142+
</AssemblyAttribute>
144143

145144
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
146145
<_Parameter1>$(AssemblyName).TestUtilities,PublicKey=00240000048000001401000006020000002400005253413100080000010001003312c63e1417ad4652242148c599b55c50d3213c7610b4cc1f467b193bfb8d131de6686268a9db307fcef9efcd5e467483fe9015307e5d0cf9d2fd4df12f29a1c7a72e531d8811ca70f6c80c4aeb598c10bb7fc48742ab86aa7986b0ae9a2f4876c61e0b81eb38e5b549f1fc861c633206f5466bfde021cb08d094742922a8258b582c3bc029eab88c98d476dac6e6f60bc0016746293f5337c68b22e528931b6494acddf1c02b9ea3986754716a9f2a32c59ff3d97f1e35ee07ca2972b0269a4cde86f7b64f80e7c13152c0f84083b5cc4f06acc0efb4316ff3f08c79bc0170229007fb27c97fb494b22f9f7b07f45547e263a44d5a7fe7da6a945a5e47afc9</_Parameter1>

0 commit comments

Comments
 (0)