-
Notifications
You must be signed in to change notification settings - Fork 1
156 lines (151 loc) · 6.34 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
on:
release:
types:
- created
- edited # can remove once CI is confirmed working
- prereleased
- released
- published
push: {}
pull_request: {}
name: Build
jobs:
build:
strategy:
matrix:
cmake-preset:
- linux # normal linux tests
- linux-openssl # tests compiling OpenSSL
- linux-sanitize
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache CMake build/dl folder
uses: actions/cache@v3
with:
path: ./build/dl
key: ${{ runner.os }}-${{ matrix.cmake-preset }}-${{ hashFiles( 'lib/*' ) }}
- name: Configure
run: |
cmake --preset "${{ matrix.cmake-preset }}"
- name: Build
run: |
cmake --build --preset "${{ matrix.cmake-preset }}"
- name: Test
run: |
ctest --preset "${{ matrix.cmake-preset }}" --output-on-failure
- name: Install to ${{ runner.temp }}/brski-${{ matrix.cmake-preset }}/
run: |
cmake --install "build/${{ matrix.cmake-preset }}" --prefix "${{ runner.temp }}/brski-${{ matrix.cmake-preset }}"
- name: Escape invalid chars in artifact name
id: escape_preset
run: |
preset='${{ matrix.cmake-preset }}'
# replace `/` with `-`
escaped_preset="${preset////-}"
echo "::set-output name=ESCAPED_CMAKE_PRESET::${escaped_preset}"
- name: Archive Install Output
uses: actions/upload-artifact@v3
with:
name: brski-build-${{ steps.escape_preset.outputs.ESCAPED_CMAKE_PRESET }}
retention-days: 7
path: |
${{ runner.temp }}/brski-${{ matrix.cmake-preset }}/
build-deb:
name: Build Debian Package
# building a deb is super slow, but we're a public repo now, so it's free!!
runs-on: ubuntu-22.04
strategy:
matrix:
architecture: [arm64, amd64]
distribution:
- jammy # uses libssl3
permissions:
contents: write # needed for publishing release artifact
env:
OTHER_MIRROR:
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports ${{ matrix.distribution }} main universe | deb [arch=amd64] http://archive.ubuntu.com/ubuntu ${{ matrix.distribution }} main universe
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create pbuilder cache dir
# The actions/cache action does not have permissions to create the pbuilder
# cache folder if it doesn't exist
run: sudo mkdir -m777 -p /var/cache/pbuilder/
- name: Cache pbuilder base
id: cache-pbuilder-base
uses: actions/cache@v3
with:
path: |
/var/cache/pbuilder/base.tgz
key: ${{ runner.os }}-${{ matrix.distribution }}-${{ matrix.architecture }}
# Sometimes the cache step just freezes forever
# so put a limit on it so that we can restart it earlier on failure
timeout-minutes: 10
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install pbuilder debhelper -y
- name: Setup pdebuilderrc for cross-compiling
env:
PBUILDER_RC: |
# Enable network access, since `cmake` downloads dependencies
USENETWORK=yes
# Faster than default, and is requried if we want to do cross-compiling
PBUILDERSATISFYDEPENDSCMD="/usr/lib/pbuilder/pbuilder-satisfydepends-apt"
run: |
echo "$PBUILDER_RC" | sudo tee -a /etc/pbuilderrc
- name: Build pbuilder base.tgz
if: steps.cache-pbuilder-base.outputs.cache-hit != 'true'
run: |
sudo pbuilder create --debootstrapopts --variant=buildd --distribution ${{ matrix.distribution }} --mirror "" --othermirror "$OTHER_MIRROR"
- name: Build .deb
run: |
mkdir -p '${{ runner.temp }}/pbuilder/result'
pdebuild --buildresult '${{ runner.temp }}/pbuilder/result' --debbuildopts "-us -uc" -- --override-config --distribution ${{ matrix.distribution }} --mirror "" --othermirror "$OTHER_MIRROR" --host-arch ${{ matrix.architecture }}
- name: Archive built debs
uses: actions/upload-artifact@v3
with:
name: brski-built-debs
retention-days: 7
path: |
${{ runner.temp }}/pbuilder/result/*.deb
- name: Upload debs as Release Assets
# only run action if this is being run from a GitHub Release
if: ${{ github.event_name == 'release' }}
uses: actions/github-script@v6
env:
PBUILDER_RESULT_DIR: '${{ runner.temp }}/pbuilder/result'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises;
const {basename, join} = require("path");
const globber = await glob.create(join(process.env.PBUILDER_RESULT_DIR, "*.deb"));
const files = await globber.glob();
for (const filePath of files) {
console.log(`Uploading ${filePath}`);
const filePromise = fs.readFile(filePath);
// Determine content-length for header to upload asset
const {size: contentLength} = await fs.stat(filePath);
// Setup headers for API call, see Octokit Documentation:
// https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information
const headers = {
'content-type': "application/vnd.debian.binary-package",
'content-length': contentLength,
};
// Upload a release asset
// API Documentation: https://developer.github.com/v3/repos/releases/#upload-a-release-asset
// Octokit Documentation: https://octokit.github.io/rest.js/v18#repos-upload-release-asset
try {
const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({
url: context.payload.release.upload_url,
headers,
name: basename(filePath),
data: await filePromise,
});
} catch (error) {
// upload errors are usually since the file already exists
console.error(`[skipped] Uploading ${basename(filePath)} failed: ${error}`);
}
}