-
Notifications
You must be signed in to change notification settings - Fork 0
267 lines (222 loc) · 9.03 KB
/
create-demo-app-debs.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
name: Build and Package Demo Server
on:
workflow_dispatch: # for manual testing
release:
types: [created, released]
push:
tags:
- 'v0.0.1'
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-arm64:
name: Build ARM64 Server
runs-on: ubuntu-latest
container:
image: ionutnqm/arm64-libs:latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Debug Current Path and List Files
run: |
echo "Current directory:"
pwd
echo "List of files:"
ls -l
- name: Build ARM64 Server
run: aarch64-linux-gnu-gcc -o server_arm64 debian-brski/brski-demo-app-deb/opt/demo-server/server.c -L/libmicrohttpd/src/microhttpd/.libs -L/zlib -lmicrohttpd -lz -static
- name: Upload server binary as an artifact
uses: actions/upload-artifact@v2
with:
name: server-arm64-binary
path: server_arm64
build-x86_64:
name: Build x86_64 Server
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Update package lists
run: sudo apt-get update
- name: Install libmicrohttpd
run: sudo apt-get install -y libmicrohttpd-dev
- name: Create Directory for x86_64 Binary
run: mkdir -p brski-demo-app-deb/opt/demo-server/
- name: Build x86_64 Server
run: gcc -o server_x86_64 debian-brski/brski-demo-app-deb/opt/demo-server/server.c -lmicrohttpd
- name: List files after build
run: |
echo "Current directory for x86_64:"
pwd
echo "List of files:"
ls -l
- name: Rename x86_64 binary for packaging
run: mv server_x86_64 brski-demo-app-deb/opt/demo-server/server_x86_64
- name: Upload x86_64 server binary as an artifact
uses: actions/upload-artifact@v2
with:
name: server-x86_64-binary
path: brski-demo-app-deb/opt/demo-server/server_x86_64
package-deb:
name: Package Debian
runs-on: ubuntu-latest
needs: [build-arm64, build-x86_64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download ARM64 server binary
uses: actions/download-artifact@v2
with:
name: server-arm64-binary
path: debian-brski/brski-demo-app-deb/opt/demo-server/
- name: Set execute permission on ARM64 Server Binary
run: sudo chmod +x debian-brski/brski-demo-app-deb/opt/demo-server/server_arm64
- name: Build ARM64 Debian Package
run: dpkg-deb --build debian-brski/brski-demo-app-deb brski-demo-app-deb_arm64.deb
- name: Remove ARM64 binary
run: rm debian-brski/brski-demo-app-deb/opt/demo-server/server_arm64
- name: Download x86_64 server binary
uses: actions/download-artifact@v2
with:
name: server-x86_64-binary
path: debian-brski/brski-demo-app-deb/opt/demo-server/
- name: Set execute permission on x86_64 Server Binary
run: sudo chmod +x debian-brski/brski-demo-app-deb/opt/demo-server/server_x86_64
- name: Build x86_64 Debian Package
run: dpkg-deb --build debian-brski/brski-demo-app-deb brski-demo-app-deb-x86_64.deb
- name: Upload ARM64 .deb Package to Artifacts
uses: actions/upload-artifact@v2
with:
name: brski-demo-app-deb-arm64
path: brski-demo-app-deb_arm64.deb
- name: Upload x86_64 .deb Package to Artifacts
uses: actions/upload-artifact@v2
with:
name: brski-demo-app-deb-x86_64
path: brski-demo-app-deb-x86_64.deb
# changed to only update the assets of current release instead of creating a new release
release-debs:
name: Update Release Assets for Debian Packages
runs-on: ubuntu-latest
needs: [build-arm64, build-x86_64, package-deb]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up release information
run: |
echo "RELEASE_TAG=v0.0.1" >> $GITHUB_ENV
echo "RELEASE_NAME=Brski-demo-app v0.0.1" >> $GITHUB_ENV
- name: Check if Release Exists
id: check_release
run: |
RELEASE_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.RELEASE_TAG }}")
RELEASE_ID=$(echo "$RELEASE_DATA" | jq -r '.id')
UPLOAD_URL=$(echo "$RELEASE_DATA" | jq -r '.upload_url')
if [[ "$RELEASE_ID" != "null" ]]; then
echo "UPLOAD_URL=${UPLOAD_URL}" >> $GITHUB_ENV
echo "exists=true" >> $GITHUB_ENV
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
else
echo "exists=false" >> $GITHUB_ENV
fi
echo "RELEASE_ID: $RELEASE_ID"
echo "UPLOAD_URL (masked): ${UPLOAD_URL/\{?name,label\}/}"
- name: Download ARM64 Debian Package
if: env.exists == 'true'
uses: actions/download-artifact@v2
with:
name: brski-demo-app-deb-arm64
path: .
- name: Download AMD64 Debian Package
if: env.exists == 'true'
uses: actions/download-artifact@v2
with:
name: brski-demo-app-deb-x86_64
path: .
- name: List files in current directory
run: ls -lah
- name: Upload ARM64 Debian Package to Release
if: env.exists == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const path = './brski-demo-app-deb_arm64.deb';
const asset_name = 'brski-demo-app-deb_arm64.deb';
try {
// Check if the file exists
if (!fs.existsSync(path)) {
console.error(`File not found: ${path}`);
}
const { owner, repo } = context.repo;
const release_id = process.env.RELEASE_ID;
console.log(`release_id: ${process.env.RELEASE_ID}`);
// Delete existing asset with the same name
const assets = await github.rest.repos.listReleaseAssets({ owner, repo, release_id });
const existingAsset = assets.data.find(asset => asset.name === asset_name);
console.log(`Existing assets: ${existingAsset}`);
console.log(`UPLOAD URL: ${process.env.UPLOAD_URL}`);
if (existingAsset) {
await github.rest.repos.deleteReleaseAsset({
owner,
repo,
asset_id: existingAsset.id
});
}
// Upload the new asset
const contentLength = fs.statSync(path).size;
const headers = { 'content-type': 'application/vnd.debian.binary-package', 'content-length': contentLength };
const upload_url = process.env.UPLOAD_URL;
const asset = fs.readFileSync(path);
await github.rest.repos.uploadReleaseAsset({
url: upload_url,
headers,
name: asset_name,
data: asset
});
} catch (error) {
console.error(`Error uploading ${asset_name}, ${error}`);
}
- name: Upload AMD64 Debian Package to Release
if: env.exists == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const path = './brski-demo-app-deb-x86_64.deb';
const asset_name = 'brski-demo-app-deb-x86_64.deb';
try {
// Check if the file exists
if (!fs.existsSync(path)) {
console.error(`File not found: ${path}`);
}
const { owner, repo } = context.repo;
const release_id = process.env.RELEASE_ID;
// Delete existing asset with the same name
const assets = await github.rest.repos.listReleaseAssets({ owner, repo, release_id });
const existingAsset = assets.data.find(asset => asset.name === asset_name);
if (existingAsset) {
await github.rest.repos.deleteReleaseAsset({
owner,
repo,
asset_id: existingAsset.id
});
}
// Upload the new asset
const contentLength = fs.statSync(path).size;
const headers = { 'content-type': 'application/vnd.debian.binary-package', 'content-length': contentLength };
const upload_url = process.env.UPLOAD_URL;
const asset = fs.readFileSync(path);
await github.rest.repos.uploadReleaseAsset({
url: upload_url,
headers,
name: asset_name,
data: asset
});
} catch (error) {
console.error(`Error uploading ${asset_name}, ${error}`);
}