-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (204 loc) · 9.82 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# SEE: https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/versioning
# SEE: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# SEE: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: CI/CD
on:
push:
branches:
- 'main'
- 'develop'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
env:
buildConfiguration: 'Release'
moduleName: 'Algorand'
guid: 'c66dcc66-564b-45c8-8406-bac225fcdf02'
artifactName: 'module-archive'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Set version info
shell: pwsh
run: |-
$version = "${{ github.ref_name }}"
$result = $version | Select-String -Pattern "v([0-9]+).([0-9]+).([0-9]+)(-)?([A-Za-z]+)?"
if ($result.Matches.Success) {
$majorVersion = $result.Matches.Groups[1].Value
$minorVersion = $result.Matches.Groups[2].Value
$buildVersion = $result.Matches.Groups[3].Value
if ($result.Matches.Groups.Length -eq 6) {
$prerelease = $result.Matches.Groups[5].Value
}
} else {
$majorVersion = 0
$minorVersion = 0
$buildVersion = 0
}
# https://www.jamescroft.co.uk/setting-github-actions-environment-variables-in-powershell/
echo "majorVersion=$majorVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "minorVersion=$minorVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "buildVersion=$buildVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "prerelease=$prerelease" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Execute unit tests
run: >
dotnet test test/${{ env.moduleName }}.PowerShell.UnitTest/${{ env.moduleName }}.PowerShell.UnitTest.csproj
--configuration ${{ env.buildConfiguration }}
- name: Build module
run: >
dotnet publish src/${{ env.moduleName }}.PowerShell/${{ env.moduleName }}.PowerShell.csproj
--configuration ${{ env.buildConfiguration }}
--output ${{ runner.temp }}/${{ env.moduleName }}
--no-self-contained
/p:Version="${{ env.majorVersion }}.${{ env.minorVersion }}.${{ env.buildVersion }}"
/p:FileVersion="${{ env.majorVersion }}.${{ env.minorVersion }}.${{ env.buildVersion }}"
/p:AssemblyVersion="${{ env.majorVersion }}.0.0"
/p:InformationalVersion="${{ env.majorVersion }}.${{ env.minorVersion }}.${{ env.buildVersion }}+${{ github.sha }}"
- name: Arrange native assemblies
shell: pwsh
run: |-
$buildOutputPath = "${{ runner.temp }}/${{ env.moduleName }}"
$runtimesPath = Join-Path -Path $buildOutputPath -ChildPath "runtimes"
Get-ChildItem -Path $runtimesPath | ForEach-Object {
$target = New-Item -ItemType Directory -Path $buildOutputPath -Name $_.Name
Get-ChildItem -Path (Join-Path -Path $_.FullName -ChildPath "native") | ForEach-Object {
Move-Item -Path $_.FullName -Destination $target
}
if ($_.Name -eq 'osx') {
Get-ChildItem -Path $target | Copy-Item -Destination $buildOutputPath
}
}
Remove-Item -Path $runtimesPath -Recurse -Force
- name: 'Create module manifest'
shell: pwsh
run: >
./src/create-module-manifest.ps1
-Path "${{ runner.temp }}/${{ env.moduleName }}"
-Prerelease "${{ env.prerelease }}"
-Guid "${{ env.guid }}"
- name: Upload module artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifactName }}
path: "${{ runner.temp }}/${{ env.moduleName }}/"
test-osx:
name: macOS Test
runs-on: macos-latest
needs: build
permissions:
actions: read
steps:
- uses: actions/checkout@v4
- name: Download module artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.artifactName }}
path: ${{ runner.temp }}/${{ env.moduleName }}
- name: Invoke integration test
shell: pwsh
run: |-
Import-Module -Name "${{ runner.temp }}/${{ env.moduleName }}/${{ env.moduleName }}.psd1"
${{ github.workspace }}/test/workflow/Invoke-IntegrationTest.ps1 -Amount 1001 -Account01Mnemonic "${{ secrets.ACCOUNT_01_MNEMONIC }}" -Account02Mnemonic "${{ secrets.ACCOUNT_02_MNEMONIC }}" -Verbose
test-ubuntu:
name: Ubuntu Test
runs-on: ubuntu-latest
needs: build
permissions:
actions: read
steps:
- uses: actions/checkout@v4
- name: Download module artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.artifactName }}
path: ${{ runner.temp }}/${{ env.moduleName }}
- name: Invoke integration test
shell: pwsh
run: |-
Import-Module -Name "${{ runner.temp }}/${{ env.moduleName }}/${{ env.moduleName }}.psd1"
${{ github.workspace }}/test/workflow/Invoke-IntegrationTest.ps1 -Amount 1002 -Account01Mnemonic "${{ secrets.ACCOUNT_01_MNEMONIC }}" -Account02Mnemonic "${{ secrets.ACCOUNT_02_MNEMONIC }}" -Verbose
test-windows:
name: Windows Test
runs-on: windows-latest
needs: build
permissions:
actions: read
steps:
- uses: actions/checkout@v4
- name: Download module artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.artifactName }}
path: ${{ runner.temp }}/${{ env.moduleName }}
- name: Invoke integration test
shell: pwsh
run: |-
Import-Module -Name "${{ runner.temp }}/${{ env.moduleName }}/${{ env.moduleName }}.psd1"
${{ github.workspace }}/test/workflow/Invoke-IntegrationTest.ps1 -Amount 1003 -Account01Mnemonic "${{ secrets.ACCOUNT_01_MNEMONIC }}" -Account02Mnemonic "${{ secrets.ACCOUNT_02_MNEMONIC }}" -Verbose
publish:
name: Publish
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: [test-osx, test-ubuntu, test-windows]
permissions:
actions: read
packages: write
steps:
- name: Download module artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.artifactName }}
path: ${{ runner.temp }}/${{ env.moduleName }}
- name: Set prelease value
shell: pwsh
run: |-
$version = "${{ github.ref_name }}"
$result = $version | Select-String -Pattern "v([0-9]+).([0-9]+).([0-9]+)(-)?([A-Za-z]+)?"
if ($result.Matches.Success -and $result.Matches.Groups.Length -eq 6) {
$prerelease = $result.Matches.Groups[5].Value
}
# https://www.jamescroft.co.uk/setting-github-actions-environment-variables-in-powershell/
echo "prerelease=$prerelease" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Publish module to GitHub
shell: pwsh
run: |-
$user = "${{ github.actor }}"
$token = "${{ github.token }}" | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList @($user, $token)
$feed = "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
$moduleName = "${{ env.moduleName }}"
$repositoryName = "PowershellNugetServices"
$dropPath = "${{ runner.temp }}"
$modulePath = [System.IO.Path]::GetFullPath((Join-Path -Path $dropPath -ChildPath $moduleName))
## Force TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
## Register repository
$registerArgs = @{
Name = $repositoryName
SourceLocation = $feed
PublishLocation = $feed
InstallationPolicy = 'Trusted'
Credential = $creds
}
Register-PSRepository @registerArgs
## Test
Get-PackageSource
Publish-Module -Path $modulePath -Repository $repositoryName -NuGetApiKey "${{ github.token }}"
- name: Publish module to PowerShell Gallery
if: ${{ env.prerelease == '' }}
shell: pwsh
run: |-
$dropPath = "${{ runner.temp }}"
$moduleName = "${{ env.moduleName }}"
$modulePath = [System.IO.Path]::GetFullPath((Join-Path -Path $dropPath -ChildPath $moduleName))
## Force TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
## Publish to PSGallery
Publish-Module -Path "$modulePath" -Repository "PSGallery" -NuGetApiKey "${{ secrets.PSGALLERY_API_KEY }}"