-
Notifications
You must be signed in to change notification settings - Fork 96
348 lines (305 loc) · 12.9 KB
/
release.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
name: Release (epicchain-cli)
# Trigger the workflow on a release event when a new release is published
on:
release:
types: [published]
# Define environment variables
env:
DOTNET_VERSION: 8.0.x
CONFIGURATION: Release
DIST_PATH: /tmp/dist
OUTPUT_PATH: /tmp/out
jobs:
build-leveldb:
name: Build leveldb win-${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
arch: [x64, arm64]
steps:
# Step to lookup cache for the LevelDB build distribution
- name: Lookup Cache Distribution
id: cache-leveldb
uses: actions/cache@v4
with:
path: ./leveldb/build/Release/*
key: leveldb-${{ matrix.os }}-${{ matrix.arch }}
enableCrossOsArchive: true
lookup-only: true
# Conditionally checkout LevelDB repository if cache is not found
- if: ${{ steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Checkout Repository Code (leveldb)
uses: actions/checkout@v4
with:
repository: google/leveldb
path: leveldb
submodules: true
fetch-depth: 0
# Conditionally setup MSBuild if cache is not found
- if: ${{ matrix.os == 'windows-latest' && steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
# Conditionally setup LevelDB build directory if cache is not found
- if: ${{ steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Setup LevelDb
working-directory: ./leveldb
run: mkdir -p ./build/Release
# Conditionally create build files for LevelDB if cache is not found
- if: ${{ steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Create Build Files (win-${{ matrix.arch }})
working-directory: ./leveldb/build
run: cmake -DBUILD_SHARED_LIBS=ON -A ${{ matrix.arch }} ..
# Conditionally build LevelDB using MSBuild if cache is not found
- if: ${{ matrix.os == 'windows-latest' && steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Build (MSBuild)
working-directory: ./leveldb/build
run: msbuild ./leveldb.sln /p:Configuration=Release
# Conditionally cache the LevelDB distribution if it was built
- if: ${{ steps.cache-leveldb.outputs.cache-hit != 'true' }}
name: Cache Distribution
uses: actions/cache/save@v4
with:
path: ./leveldb/build/Release/*
key: leveldb-${{ matrix.os }}-${{ matrix.arch }}
enableCrossOsArchive: true
build-epicchain-cli:
needs: [build-leveldb]
name: ${{ matrix.runtime }}
runs-on: ubuntu-latest
strategy:
matrix:
runtime: [linux-x64, linux-arm64, win-x64, win-arm64, osx-x64, osx-arm64]
steps:
# Step to set the application version from the release tag
- name: Set Application Version (Environment Variable)
run: |
APP_VERSION=$(echo '${{ github.event.release.tag_name }}' | cut -d 'v' -f 2)
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
# Checkout the epicchain-cli repository code
- name: Checkout Repository Code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Setup .NET environment
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Publish the epicchain-cli project
- name: .NET Publish (epicchain-cli)
run: |
dotnet publish ./src/EpicChain.CLI \
--version-suffix ${{ matrix.runtime }} \
--framework net8.0 \
--configuration ${{ env.CONFIGURATION }} \
--runtime ${{ matrix.runtime }} \
--self-contained true \
--output ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }} \
--verbosity normal \
-p:VersionPrefix=${{ env.APP_VERSION }} \
-p:RuntimeIdentifier=${{ matrix.runtime }} \
-p:SelfContained=true \
-p:IncludeNativeLibrariesForSelfExtract=false \
-p:PublishTrimmed=false \
-p:PublishSingleFile=true \
-p:PublishReadyToRun=true \
-p:EnableCompressionInSingleFile=true \
-p:DebugType=embedded \
-p:ServerGarbageCollection=true
# Build the LevelDBStore plugin
- name: .NET Build (LevelDBStore)
run: |
dotnet build ./src/Plugins/LevelDBStore \
--version-suffix ${{ matrix.runtime }} \
--framework net8.0 \
--configuration ${{ env.CONFIGURATION }} \
--output ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}/Plugins/LevelDBStore \
--verbosity normal \
-p:VersionPrefix=${{ env.APP_VERSION }}
# Remove unnecessary files from the LevelDBStore plugin output
- name: Remove files (junk)
working-directory: ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}/Plugins/LevelDBStore
run: |
rm -v EpicChain*
rm -v *.pdb
rm -v *.xml
# Remove XML comment files from the epicchain-cli output
- name: Remove Xml Comment Files
working-directory: ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}
run: rm -v *.xml
# Get cached LevelDB distribution for Windows x64 if applicable
- if: ${{ startsWith(matrix.runtime, 'win-x64') }}
name: Get Distribution Caches (win-x64)
uses: actions/cache@v4
with:
path: ./leveldb/build/Release/*
key: leveldb-windows-latest-x64
enableCrossOsArchive: true
fail-on-cache-miss: true
# Get cached LevelDB distribution for Windows arm64 if applicable
- if: ${{ startsWith(matrix.runtime, 'win-arm64') }}
name: Get Distribution Caches (win-arm64)
uses: actions/cache@v4
with:
path: ./leveldb/build/Release/*
key: leveldb-windows-latest-arm64
enableCrossOsArchive: true
fail-on-cache-miss: true
# Copy LevelDB files to the output directory for Windows
- if: ${{ startsWith(matrix.runtime, 'win') }}
name: Copy Files (leveldb) (win)
run: cp -v ./leveldb/build/Release/leveldb.dll ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}/libleveldb.dll
# Create the distribution directory
- name: Create Distribution Directory
run: mkdir -p ${{ env.DIST_PATH }}
# Create a tarball file for Linux distributions
- name: Create Tarball File (linux)
if: ${{ startsWith(matrix.runtime, 'linux') }}
working-directory: ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}
run: tar -czvf ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.tar.gz .
# Create a tarball file for macOS distributions
- name: Cache Distribution
uses: actions/cache/save@v4
with:
path: ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}/*
key: epicchain-${{ matrix.runtime }}
enableCrossOsArchive: true
# Create a zip file for Windows distributions
- name: Create Zip File (win)
if: ${{ startsWith(matrix.runtime, 'win') }}
working-directory: ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}
run: zip ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.zip -r *
# Create checksum files for Linux distributions
- name: Create Checksum Files (linux)
if: ${{ startsWith(matrix.runtime, 'linux') }}
working-directory: ${{ env.DIST_PATH }}
env:
FILENAME: epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}
run: |
sha256sum ${{ env.FILENAME }}.tar.gz > ${{ env.FILENAME }}.sha256
# Create checksum files for Windows distributions
- name: Create Checksum Files (win)
if: ${{ startsWith(matrix.runtime, 'win') }}
working-directory: ${{ env.DIST_PATH }}
env:
FILENAME: epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}
run: |
sha256sum ${{ env.FILENAME }}.zip > ${{ env.FILENAME }}.sha256
# List the contents of the distribution and output directories
- name: Output/Distribution Directory Contents
run: |
ls -la ${{ env.DIST_PATH }}
ls -la ${{ env.OUTPUT_PATH }}/${{ matrix.runtime }}
# Upload tarball files for Linux distributions
- name: Upload Tarball File (linux)
if: ${{ startsWith(matrix.runtime, 'linux') }}
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.tar.gz
asset_name: epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.tar.gz
asset_content_type: application/x-gtar
# Upload zip files for Windows distributions
- name: Upload Zip File (win)
if: ${{ startsWith(matrix.runtime, 'win') }}
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.zip
asset_name: epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.zip
asset_content_type: application/zip
# Upload checksum files for all distributions
- name: Upload Checksum File (all)
if: ${{ startsWith(matrix.runtime, 'osx') == false }}
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.sha256
asset_name: epicchain-cli.v${{ env.APP_VERSION }}-${{ matrix.runtime }}.sha256
asset_content_type: text/plain
code-sign:
needs: [build-epicchain-cli]
name: CodeSign & Publish (epicchain-cli) ${{ matrix.arch }}
runs-on: macos-latest
strategy:
matrix:
arch: [x64, arm64]
steps:
# Step to set the application version from the release tag
- name: Set Application Version (Environment Variable)
run: |
APP_VERSION=$(echo '${{ github.event.release.tag_name }}' | cut -d 'v' -f 2)
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
- name: Get Distribution Caches (win-${{ matrix.arch}})
uses: actions/cache@v4
with:
path: ${{ env.OUTPUT_PATH }}/osx-${{ matrix.arch }}/*
key: epicchain-osx-${{ matrix.arch }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Sign (epicchain-cli)
working-directory: ${{ env.OUTPUT_PATH }}/osx-${{ matrix.arch }}
run: codesign --force --deep -s - epicchain-cli
# Create the distribution directory
- name: Create Distribution Directory
run: mkdir -p ${{ env.DIST_PATH }}
# Create a tarball file for macOS distributions
- name: Create Tarball File (osx)
working-directory: ${{ env.OUTPUT_PATH }}/osx-${{ matrix.arch }}
run: tar -cJf ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}.tar.xz .
# Create checksum files for macOS distributions
- name: Create Checksum Files (osx)
working-directory: ${{ env.DIST_PATH }}
env:
FILENAME: epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}
run: |
shasum -a 256 ${{ env.FILENAME }}.tar.xz > ${{ env.FILENAME }}.sha256
# Upload tarball files for macOS distributions
- name: Upload Tarball File (osx)
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}.tar.xz
asset_name: epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}.tar.xz
asset_content_type: application/x-gtar
# Upload checksum files for all distributions
- name: Upload Checksum File (all)
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.DIST_PATH }}/epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}.sha256
asset_name: epicchain-cli.v${{ env.APP_VERSION }}-osx-${{ matrix.arch }}.sha256
asset_content_type: text/plain
cleanup:
needs: [build-epicchain-cli, code-sign]
runs-on: ubuntu-latest
steps:
# Cleanup step to delete old caches
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref }}