-
Notifications
You must be signed in to change notification settings - Fork 28
287 lines (265 loc) · 11.4 KB
/
build.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
name: Build, test and publish
on:
push:
branches: '**'
release:
types: [created]
schedule:
# Daily 5am australian/brisbane time (7pm UTC)
- cron: '0 19 * * *'
workflow_dispatch:
jobs:
build:
name: Build and unit test code
runs-on: windows-latest
# conditionally skip build on PR merge of release-please, because the release creation is going to trigger the real build
if: ${{ github.ref_name != github.event.repository.default_branch || github.event.head_commit.author.username != 'team-integrations-fnm-bot' }}
outputs:
version: ${{ steps.nuke-build.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Run Nuke Build 🏗
id: nuke-build
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
OCTOVERSION_CurrentBranch: ${{ (github.event_name == 'schedule' && 'nightly') || github.head_ref || github.ref }} # For pull_request events we override the /refs/pull/xx/merge branch to the PR's head branch
RunNumber: ${{ github.run_number }}
AzureKeyVaultUrl: ${{ secrets.AZURE_KEYVAULT_URL }}
AzureKeyVaultAppId: ${{ secrets.AZURE_KEYVAULT_CLIENT_ID }}
AzureKeyVaultTenantId: ${{ secrets.AZURE_KEYVAULT_TENANT_ID }}
AzureKeyVaultAppSecret: ${{ secrets.AZURE_KEYVAULT_CLIENT_SECRET }}
AzureKeyVaultCertificateName: ${{ secrets.AZURE_KEYVAULT_CERTIFICATE_NAME }}
run: |
./build.cmd
- uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts/
docker-build:
name: Create and test Docker image
needs: build
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.build.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Build Docker image
id: build-docker-image
run: |
PLATFORM="alpine"
TAG="octopusdeploy/octo-prerelease:${VERSION}-${PLATFORM}"
LATEST="octopusdeploy/octo-prerelease:latest-${PLATFORM}"
echo "DOCKER_IMAGE_TAG=${TAG}" >> $GITHUB_OUTPUT
docker build \
--build-arg OCTO_TOOLS_VERSION=${VERSION} \
--file "${{ github.workspace }}/Dockerfiles/${PLATFORM}/Dockerfile" \
--tag ${TAG} \
--tag ${LATEST} \
${{ github.workspace }}/artifacts
- name: Test Docker image
run: |
OCTO_RESPONSE="$(docker run --rm ${{ steps.build-docker-image.outputs.DOCKER_IMAGE_TAG }} version)"
if [[ "$OCTO_RESPONSE" == "$VERSION" ]]
then
echo "Image successfully created - running 'docker run --rm ${DOCKER_IMAGE_TAG} version' returned ${OCTO_RESPONSE}"
else
echo "Built image did not return expected version ${VERSION} - it returned ${OCTO_RESPONSE}" >&2 && exit 1
fi
- name: Package Docker image
run: |
tarFile="Octo.Docker.Image.$VERSION.tar"
gzipFile="${tarFile}.gz"
docker save \
--output "${{ github.workspace }}/artifacts/${tarFile}" \
octopusdeploy/octo-prerelease
gzip -c "${{ github.workspace }}/artifacts/${tarFile}" > "${{ github.workspace }}/artifacts/${gzipFile}"
rm "${{ github.workspace }}/artifacts/${tarFile}"
- uses: actions/upload-artifact@v3
with:
name: docker-image
path: artifacts/Octo.Docker.Image.*.tar.gz
linux-distro-packages-build:
name: Create Linux distro packages
needs: build
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.build.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: OctopusDeploy/linux-package-feeds
token: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
path: linux-package-feeds-repo
- run: |
ln -s linux-package-feeds-repo/source linux-package-feeds
- uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Extract linux-x64 package
run: |
mkdir -p artifacts/OctopusTools.$VERSION.linux-x64.extracted
tar -xf artifacts/OctopusTools.$VERSION.linux-x64.tar.gz -C artifacts/OctopusTools.$VERSION.linux-x64.extracted
- name: Build the distro images
env:
SIGN_PRIVATE_KEY: ${{ secrets.SIGN_LINUX_DISTRO_PRIVATE_KEY }}
SIGN_PASSPHRASE: ${{ secrets.SIGN_LINUX_DISTRO_PASSPHRASE }}
run: |
docker run --env VERSION=$VERSION --env BINARIES_PATH=/artifacts/OctopusTools.$VERSION.linux-x64.extracted/ \
--env PACKAGES_PATH=/artifacts --env SIGN_PRIVATE_KEY --env SIGN_PASSPHRASE \
--volume ${{ github.workspace }}/BuildAssets:/BuildAssets \
--volume ${{ github.workspace }}/linux-package-feeds:/opt/linux-package-feeds \
--volume ${{ github.workspace }}/artifacts:/artifacts \
--rm --tty \
octopusdeploy/package-linux-docker:latest \
bash -c /BuildAssets/create-octopuscli-linux-packages.sh
- name: Re-compress result
run: |
rm -rf ${{ github.workspace }}/artifacts/OctopusTools.$VERSION.linux-x64.extracted
mkdir -p ${{ github.workspace }}/artifacts/linuxpackages
mv ${{ github.workspace }}/artifacts/*.deb ${{ github.workspace }}/artifacts/linuxpackages
mv ${{ github.workspace }}/artifacts/*.rpm ${{ github.workspace }}/artifacts/linuxpackages
cp ${{ github.workspace }}/linux-package-feeds/publish-apt.sh \
${{ github.workspace }}/linux-package-feeds/publish-rpm.sh \
${{ github.workspace }}/BuildAssets/repos/test-linux-package-from-feed-in-dists.sh \
${{ github.workspace }}/BuildAssets/repos/test-linux-package-from-feed.sh \
${{ github.workspace }}/BuildAssets/test-linux-package.sh \
${{ github.workspace }}/linux-package-feeds/install-linux-package.sh \
${{ github.workspace }}/linux-package-feeds/install-linux-feed-package.sh \
${{ github.workspace }}/artifacts/linuxpackages
zip -rj ${{ github.workspace }}/artifacts/OctopusTools.Packages.linux-x64.$VERSION.zip ${{ github.workspace }}/artifacts/linuxpackages
rm -rf ${{ github.workspace }}/artifacts/linuxpackages
- uses: actions/upload-artifact@v3
with:
name: packages-linux
path: artifacts/OctopusTools.Packages.linux-x64.${{ needs.build.outputs.version }}.zip
linux-distro-packages-test:
name: Test Linux distro packages
needs: [build, linux-distro-packages-build, docker-build]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.build.outputs.version }}
strategy:
matrix:
distro: [
'debian:stable-slim',
'debian:oldstable-slim',
'ubuntu:latest',
'ubuntu:focal',
'ubuntu:bionic',
'ubuntu:xenial',
'ubuntu:trusty',
'fedora:32',
'linuxmintd/mint19.3-amd64',
'roboxes/rhel8',
'roboxes/rhel7'
]
steps:
- uses: actions/download-artifact@v3
with:
name: packages-linux
path: artifacts
- name: Extract package
run: unzip ${{ github.workspace }}/artifacts/OctopusTools.Packages.linux-x64.$VERSION.zip -d ${{ github.workspace }}/artifacts/OctopusTools.Packages
- name: Test the distro image
env:
OCTOPUS_CLI_SERVER: ${{ secrets.OCTOPUS_URL }}
OCTOPUS_CLI_API_KEY: ${{ secrets.OCTOPUS_API_KEY }}
REDHAT_SUBSCRIPTION_USERNAME: ${{ secrets.REDHAT_SUBSCRIPTION_USERNAME }}
REDHAT_SUBSCRIPTION_PASSWORD: ${{ secrets.REDHAT_SUBSCRIPTION_PASSWORD }}
run: |
docker run --env OCTOPUS_SPACE=Integrations --env "OCTOPUS_EXPECT_ENV=Components - Internal" --env PKG_PATH_PREFIX=octopuscli \
--env REDHAT_SUBSCRIPTION_USERNAME --env REDHAT_SUBSCRIPTION_PASSWORD --env OCTOPUS_CLI_SERVER --env OCTOPUS_CLI_API_KEY \
--volume ${{ github.workspace }}/artifacts/OctopusTools.Packages:/working \
--rm --tty \
${{ matrix.distro }} \
bash -c "cd /working && bash ./test-linux-package.sh"
publish:
name: Publish the packages
needs: [build, docker-build, linux-distro-packages-test]
runs-on: ubuntu-latest
env:
OCTOPUS_URL: ${{ secrets.OCTOPUS_URL }}
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_KEY }}
VERSION: ${{ needs.build.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- uses: actions/download-artifact@v3
with:
name: packages-linux
path: artifacts
- uses: actions/download-artifact@v3
with:
name: docker-image
path: artifacts
- name: Generate sha256 checksums
if: github.event_name == 'release'
run: |
releaseVersion=${{ needs.build.outputs.version }}
for filePath in $(find artifacts/* -name "OctopusTools.${releaseVersion}.*.tar.gz" -or -name "OctopusTools.${releaseVersion}.*.zip")
do
fileName="$(basename -- $filePath)"
newSha=$(sha256sum "$filePath" | awk '{ print $1 }')
echo "$newSha $fileName" >> artifacts/OctopusTools.${releaseVersion}.SHA256SUMS
done
- name: Upload binaries and checksum file to release
if: github.event_name == 'release'
run: |
releaseVersion=${{ needs.build.outputs.version }}
args=("v$releaseVersion")
for filePath in $(find artifacts/* -name "OctopusTools.${releaseVersion}.*.tar.gz" -or -name "OctopusTools.${releaseVersion}.*.zip" -or -name '*.SHA256SUMS')
do
args+=($filePath)
done
gh release upload ${args[@]}
- name: Compress packages
id: compress-packages
run: |
cd artifacts
tar -xf OctopusTools.$VERSION.linux-x64.tar.gz
zip OctopusTools.Zips.$VERSION.zip *.zip *.tar.gz
- name: Push a package to Octopus Deploy 🐙
uses: OctopusDeploy/push-package-action@v3
with:
space: Integrations
packages: |
artifacts/Octopus.DotNet.Cli.${{ needs.build.outputs.version }}.nupkg
artifacts/OctopusTools.${{ needs.build.outputs.version }}.nupkg
artifacts/Octo.Docker.Image.${{ needs.build.outputs.version }}.tar.gz
artifacts/OctopusTools.Packages.linux-x64.${{ needs.build.outputs.version }}.zip
artifacts/OctopusTools.Zips.${{ needs.build.outputs.version }}.zip
- name: Fetch Release Notes
id: fetch-release-notes
if: github.event_name == 'release'
run: |
echo "::debug::${{github.event_name}}"
OUTPUT_FILE="release_notes.txt"
jq --raw-output '.release.body' ${{ github.event_path }} | sed 's#\r# #g' > $OUTPUT_FILE
echo "release-note-file=$OUTPUT_FILE" >> $GITHUB_OUTPUT
- name: Create a release in Octopus Deploy 🐙
uses: OctopusDeploy/create-release-action@v3
with:
space: Integrations
project: 'Octopus CLI'
package_version: ${{ needs.build.outputs.version }}
packages: '*:NuGet.CommandLine:4.4.1'
release_notes_file: ${{ (github.event_name == 'release' && steps.fetch-release-notes.outputs.release-note-file) || ''}}
git_ref: ${{ (github.ref_type == 'tag' && github.event.repository.default_branch ) || (github.head_ref || github.ref) }}
git_commit: ${{ github.event.after || github.event.pull_request.head.sha }}