-
Notifications
You must be signed in to change notification settings - Fork 87
191 lines (163 loc) · 6.63 KB
/
build-packages.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
name: Build packages
on:
pull_request:
paths:
- 'base-*/**'
- 'core-*/**'
- 'extra-*/**'
issue_comment:
types: [created]
workflow_dispatch:
inputs:
packages:
description: 'Packages to build'
required: true
concurrency:
group: ${{github.event.pull_request.number || github.event.issue.number || github.event.inputs.packages}}
cancel-in-progress: true
permissions:
issues: write
pull-requests: write
jobs:
get-packages:
if: ${{((github.event.pull_request && startsWith(github.event.pull_request.title, '[ci]')) || (github.event.comment.body == '/build' && github.event.issue.pull_request) || startsWith(github.event.comment.body, '/build ')) || github.event.inputs.packages}}
runs-on: ubuntu-latest
steps:
- name: Add reaction to invocation comment
uses: peter-evans/create-or-update-comment@v3
if: ${{github.event.comment}}
with:
comment-id: ${{github.event.comment.id}}
reactions: rocket
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
id: create-comment
if: ${{github.event.comment}}
with:
issue-number: ${{github.event.issue.number}}
body: |
🥰 Packages are building at ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}.
- uses: actions/checkout@v4
if: ${{github.event.pull_request}}
with:
ref: 'stable'
- uses: actions/checkout@v4
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
with:
fetch-depth: 0
- name: Checkout pull request
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
env:
PR_NUMBER: ${{github.event.pull_request.number || github.event.issue.number}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
gh pr checkout $PR_NUMBER
- name: Get packages to build from repository
uses: actions/github-script@v7
id: get-packages-from-repo
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
with:
script: |
let args = "";
const options = {};
options.listeners = {
stdout: (data) => {
args += data.toString();
}
};
await exec.exec('git', ['merge-base', 'origin/stable', 'HEAD'], options);
const parent = args.split('\n');
args = "";
await exec.exec('git', ['diff', '--name-only', parent[0], 'HEAD', '*/spec'], options);
const regex = /.*\/(.*)\/.*/;
const packages = args.split('\n').map(arg => regex.exec(arg)).filter(arg => Array.isArray(arg)).map(arg => arg[1]);
if (!Array.isArray(packages) || packages.length == 0) throw "No packages to build in the repository!";
return packages;
- name: Get packages to build from command line
uses: actions/github-script@v7
id: get-packages-from-command-line
if: ${{startsWith(github.event.comment.body, '/build ')}}
with:
script: |
const args = context.payload.comment.body;
const regex = /\/build ([a-z\d\/\.\-\+ ]+)/;
const isMatched = args.match(regex);
if (!isMatched) throw "No packages found in the command!";
const packages = args.split('/build ')[1].split(' ');
return packages;
- name: Get packages to build from input
uses: actions/github-script@v7
id: get-packages-from-input
if: ${{github.event.inputs.packages}}
with:
script: |
const args = context.payload.inputs.packages;
const regex = /([a-z\d\/\.\-\+ ]+)/;
const isMatched = args.match(regex);
if (!isMatched) throw "No packages found in the command!";
const packages = args.split(' ');
return packages;
- name: Update comment
uses: peter-evans/create-or-update-comment@v3
if: ${{failure() && github.event.comment}}
with:
comment-id: ${{steps.create-comment.outputs.comment-id}}
body: |
❌ Nothing to do!
outputs:
matrix: ${{steps.get-packages-from-repo.outputs.result || steps.get-packages-from-command-line.outputs.result || steps.get-packages-from-input.outputs.result}}
comment-id: ${{steps.create-comment.outputs.comment-id}}
build:
needs: get-packages
runs-on: ubuntu-latest
container: ghcr.io/aosc-dev/aosc-os-buildkit-daily:latest
strategy:
matrix:
package: ${{fromJson(needs.get-packages.outputs.matrix)}}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Configure the container
run: |
mkdir -p /var/lib/acbs
ln -s $GITHUB_WORKSPACE /var/lib/acbs/repo
sed -i 's/Null Packager <[email protected]>/GitHub Actions <[email protected]>/' /etc/autobuild/ab3cfg.sh
apt-get update && yes | apt-get -yf full-upgrade && apt-get -y autoremove
- name: Install GitHub CLI
if: ${{github.event.pull_request || github.event.issue.pull_request}}
run: |
yes | apt-get -yf install gh
- name: Checkout pull request
if: ${{github.event.pull_request || github.event.issue.pull_request}}
env:
PR_NUMBER: ${{github.event.pull_request.number || github.event.issue.number}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
gh pr checkout $PR_NUMBER
- name: Build the package
shell: 'script -eqc "bash --noprofile --norc -eo pipefail {0}"'
env:
PACKAGE: ${{matrix.package}}
TERM: xterm-new
CARGO_TERM_COLOR: always
run: acbs-build "$PACKAGE"
- name: Upload the package
uses: actions/upload-artifact@v4
with:
name: debs_${{matrix.package}}
path: /debs
if-no-files-found: error
- name: Update comment when succeed
uses: peter-evans/create-or-update-comment@v3
if: ${{!github.event.pull_request}}
with:
comment-id: ${{needs.get-packages.outputs.comment-id}}
body: |
✅ Building `${{matrix.package}}` ends with status **${{job.status}}**.
- name: Update comment when not succeed
uses: peter-evans/create-or-update-comment@v3
if: ${{!success() && !github.event.pull_request}}
with:
comment-id: ${{needs.get-packages.outputs.comment-id}}
body: |
❌ Building `${{matrix.package}}` ends with status **${{job.status}}**.