Skip to content

Commit 03ec9e0

Browse files
authored
Merge pull request #318 from AArnott/githubActionsDevelopment
Add release GitHub workflow and improve others
2 parents 130ad67 + 89afbfc commit 03ec9e0

File tree

6 files changed

+167
-63
lines changed

6 files changed

+167
-63
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish artifacts
2+
description: Publish artifacts
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: 📥 Collect artifacts
8+
run: azure-pipelines/artifacts/_stage_all.ps1
9+
shell: pwsh
10+
if: always()
11+
12+
# TODO: replace this hard-coded list with a loop that utilizes the NPM package at
13+
# https://github.com/actions/toolkit/tree/main/packages/artifact (or similar) to push the artifacts.
14+
15+
- name: 📢 Upload project.assets.json files
16+
if: always()
17+
uses: actions/upload-artifact@v4
18+
with:
19+
name: projectAssetsJson-${{ runner.os }}
20+
path: ${{ runner.temp }}/_artifacts/projectAssetsJson
21+
continue-on-error: true
22+
- name: 📢 Upload variables
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: variables-${{ runner.os }}
26+
path: ${{ runner.temp }}/_artifacts/Variables
27+
continue-on-error: true
28+
- name: 📢 Upload build_logs
29+
if: always()
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: build_logs-${{ runner.os }}
33+
path: ${{ runner.temp }}/_artifacts/build_logs
34+
continue-on-error: true
35+
- name: 📢 Upload test_logs
36+
if: always()
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: test_logs-${{ runner.os }}
40+
path: ${{ runner.temp }}/_artifacts/test_logs
41+
continue-on-error: true
42+
- name: 📢 Upload testResults
43+
if: always()
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: testResults-${{ runner.os }}
47+
path: ${{ runner.temp }}/_artifacts/testResults
48+
continue-on-error: true
49+
- name: 📢 Upload coverageResults
50+
if: always()
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: coverageResults-${{ runner.os }}
54+
path: ${{ runner.temp }}/_artifacts/coverageResults
55+
continue-on-error: true
56+
- name: 📢 Upload symbols
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: symbols-${{ runner.os }}
60+
path: ${{ runner.temp }}/_artifacts/symbols
61+
continue-on-error: true
62+
- name: 📢 Upload deployables
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: deployables-${{ runner.os }}
66+
path: ${{ runner.temp }}/_artifacts/deployables
67+
if: always()

.github/workflows/build.yml

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
name: CI
1+
name: 🏭 Build
22

33
on:
44
push:
55
branches:
66
- main
77
- validate/*
88
pull_request:
9+
workflow_dispatch:
910

1011
env:
1112
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
@@ -15,6 +16,7 @@ env:
1516

1617
jobs:
1718
build:
19+
name: 🏭 Build
1820

1921
runs-on: ${{ matrix.os }}
2022
strategy:
@@ -57,63 +59,8 @@ jobs:
5759
- name: ⚙ Update pipeline variables based on build outputs
5860
run: azure-pipelines/variables/_pipelines.ps1
5961
shell: pwsh
60-
- name: 📥 Collect artifacts
61-
run: azure-pipelines/artifacts/_stage_all.ps1
62-
shell: pwsh
63-
if: always()
64-
- name: 📢 Upload project.assets.json files
65-
if: always()
66-
uses: actions/upload-artifact@v4
67-
with:
68-
name: projectAssetsJson-${{ runner.os }}
69-
path: ${{ runner.temp }}/_artifacts/projectAssetsJson
70-
continue-on-error: true
71-
- name: 📢 Upload variables
72-
uses: actions/upload-artifact@v4
73-
with:
74-
name: variables-${{ runner.os }}
75-
path: ${{ runner.temp }}/_artifacts/Variables
76-
continue-on-error: true
77-
- name: 📢 Upload build_logs
78-
if: always()
79-
uses: actions/upload-artifact@v4
80-
with:
81-
name: build_logs-${{ runner.os }}
82-
path: ${{ runner.temp }}/_artifacts/build_logs
83-
continue-on-error: true
84-
- name: 📢 Upload test_logs
85-
if: always()
86-
uses: actions/upload-artifact@v4
87-
with:
88-
name: test_logs-${{ runner.os }}
89-
path: ${{ runner.temp }}/_artifacts/test_logs
90-
continue-on-error: true
91-
- name: 📢 Upload testResults
92-
if: always()
93-
uses: actions/upload-artifact@v4
94-
with:
95-
name: testResults-${{ runner.os }}
96-
path: ${{ runner.temp }}/_artifacts/testResults
97-
continue-on-error: true
98-
- name: 📢 Upload coverageResults
99-
if: always()
100-
uses: actions/upload-artifact@v4
101-
with:
102-
name: coverageResults-${{ runner.os }}
103-
path: ${{ runner.temp }}/_artifacts/coverageResults
104-
continue-on-error: true
105-
- name: 📢 Upload symbols
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: symbols-${{ runner.os }}
109-
path: ${{ runner.temp }}/_artifacts/symbols
110-
continue-on-error: true
111-
- name: 📢 Upload deployables
112-
uses: actions/upload-artifact@v4
113-
with:
114-
name: deployables-${{ runner.os }}
115-
path: ${{ runner.temp }}/_artifacts/deployables
116-
if: always()
62+
- name: 📢 Publish artifacts
63+
uses: ./.github/actions/publish-artifacts
11764
- name: 📢 Publish code coverage results to codecov.io
11865
run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }}"
11966
shell: pwsh

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ permissions:
1010
actions: read
1111
pages: write
1212
id-token: write
13+
contents: read
1314

1415
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
1516
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.

.github/workflows/libtemplate-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Library.Template update
1+
name: Library.Template update
22

33
# PREREQUISITE: This workflow requires the repo to be configured to allow workflows to create pull requests.
44
# Visit https://github.com/USER/REPO/settings/actions

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 🎁 Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
ship_run_id:
9+
description: ID of the GitHub workflow run to ship
10+
required: true
11+
12+
run-name: ${{ github.ref_name }}
13+
14+
permissions:
15+
actions: read
16+
contents: write
17+
18+
jobs:
19+
release:
20+
runs-on: ubuntu-22.04
21+
steps:
22+
- name: ⚙️ Initialization
23+
shell: pwsh
24+
run: |
25+
if ('${{ secrets.NUGET_API_KEY }}') {
26+
echo "NUGET_API_KEY_DEFINED=true" >> $GITHUB_ENV
27+
}
28+
29+
- name: 🔎 Search for build of ${{ github.ref }}
30+
shell: pwsh
31+
id: findrunid
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
run: |
35+
if ('${{ inputs.ship_run_id }}') {
36+
$runid = '${{ inputs.ship_run_id }}'
37+
} else {
38+
$restApiRoot = '/repos/${{ github.repository }}'
39+
40+
# Resolve the tag reference to a commit sha
41+
$resolvedRef = gh api `
42+
-H "Accept: application/vnd.github+json" `
43+
-H "X-GitHub-Api-Version: 2022-11-28" `
44+
$restApiRoot/git/ref/tags/${{ github.ref_name }} `
45+
| ConvertFrom-Json
46+
$commitSha = $resolvedRef.object.sha
47+
48+
Write-Host "Resolved ${{ github.ref_name }} to $commitSha"
49+
50+
$releases = gh run list -R ${{ github.repository }} -c $commitSha -w .github/workflows/build.yml -s success --json databaseId,startedAt `
51+
| ConvertFrom-Json | Sort-Object startedAt -Descending
52+
53+
if ($releases.length -eq 0) {
54+
Write-Error "No successful builds found for ${{ github.ref }}."
55+
} elseif ($releases.length -gt 1) {
56+
Write-Warning "More than one successful run found for ${{ github.ref }}. Artifacts from the most recent successful run will ship."
57+
}
58+
59+
$runid = $releases[0].databaseId
60+
}
61+
62+
Write-Host "Using artifacts from run-id: $runid"
63+
64+
Echo "runid=$runid" >> $env:GITHUB_OUTPUT
65+
66+
- name: 🔻 Download deployables artifacts
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: deployables-Linux
70+
path: ${{ runner.temp }}/deployables
71+
run-id: ${{ steps.findrunid.outputs.runid }}
72+
github-token: ${{ github.token }}
73+
74+
- name: 💽 Upload artifacts to release
75+
shell: pwsh
76+
if: ${{ github.event.release.assets_url }} != ''
77+
env:
78+
GH_TOKEN: ${{ github.token }}
79+
run: |
80+
Get-ChildItem '${{ runner.temp }}/deployables' |% {
81+
Write-Host "Uploading $($_.Name) to release..."
82+
gh release -R ${{ github.repository }} upload "${{ github.ref_name }}" $_.FullName
83+
}
84+
85+
- name: 🚀 Push NuGet packages
86+
run: dotnet nuget push ${{ runner.temp }}/deployables/*.nupkg --source https://api.nuget.org/v3/index.json -k '${{ secrets.NUGET_API_KEY }}'
87+
if: ${{ env.NUGET_API_KEY_DEFINED == 'true' }}

azure-pipelines/artifacts/coverageResults.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ $RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
33
$coverageFiles = @(Get-ChildItem "$RepoRoot/test/*.cobertura.xml" -Recurse | Where {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" })
44

55
# Prepare code coverage reports for merging on another machine
6-
if ($env:SYSTEM_DEFAULTWORKINGDIRECTORY) {
7-
Write-Host "Substituting $env:SYSTEM_DEFAULTWORKINGDIRECTORY with `"{reporoot}`""
6+
$repoRoot = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
7+
if (!$repoRoot) { $repoRoot = $env:GITHUB_WORKSPACE }
8+
if ($repoRoot) {
9+
Write-Host "Substituting $repoRoot with `"{reporoot}`""
810
$coverageFiles |% {
9-
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($env:SYSTEM_DEFAULTWORKINGDIRECTORY), "{reporoot}" }
11+
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" }
1012
Set-Content -LiteralPath $_ -Value $content -Encoding UTF8
1113
}
1214
} else {
13-
Write-Warning "coverageResults: Azure Pipelines not detected. Machine-neutral token replacement skipped."
15+
Write-Warning "coverageResults: Cloud build not detected. Machine-neutral token replacement skipped."
1416
}
1517

1618
if (!((Test-Path $RepoRoot\bin) -and (Test-Path $RepoRoot\obj))) { return }

0 commit comments

Comments
 (0)