Skip to content

Commit 34f6a08

Browse files
committed
wip: switch to workflow_dispatch
wip Signed-off-by: George Sapkin <[email protected]>
1 parent b3917d1 commit 34f6a08

File tree

2 files changed

+266
-18
lines changed

2 files changed

+266
-18
lines changed

.github/workflows/formal.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ on:
44
pull_request_target:
55

66
permissions:
7-
# for dispatch
8-
contents: write
7+
contents: read
98
pull-requests: write
109

1110
jobs:
@@ -24,11 +23,19 @@ jobs:
2423
steps:
2524
- name: Trigger build
2625
if: needs.formalities.result == 'success'
27-
uses: peter-evans/repository-dispatch@v3
26+
uses: actions/github-script@v8
2827
with:
29-
repository: ${{ github.repository }}
30-
event-type: run-build
31-
client-payload: '{ "pull_request": { "number": ${{ github.event.pull_request.number }} } }'
28+
github-token: ${{ secrets.DEFAULT_TOKEN }}
29+
script: |
30+
await github.rest.actions.createWorkflowDispatch({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
workflow_id: 'multi-arch-test-build.yml',
34+
ref: 'master',
35+
inputs: {
36+
pr_number: context.issue.number.toString(),
37+
},
38+
});
3239
3340
- name: Add 'not following guidelines' label
3441
if: needs.formalities.result == 'failure'
Lines changed: 253 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,77 @@
11
name: Test and Build
22

33
on:
4-
repository_dispatch:
5-
types: [run-build]
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: 'The pull request number to build'
8+
required: true
9+
type: 'string'
610

711
permissions:
812
contents: read
13+
statuses: write # To set commit statuses
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
918

1019
jobs:
11-
prepare:
12-
name: Feeds Package Test Build
20+
build:
21+
name: Test ${{ matrix.arch }}
1322
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- arch: aarch64_generic
28+
target: armsr-armv8
29+
runtime_test: true
30+
31+
- arch: arm_cortex-a15_neon-vfpv4
32+
target: armsr-armv7
33+
runtime_test: true
34+
35+
- arch: arm_cortex-a9_vfpv3-d16
36+
target: mvebu-cortexa9
37+
runtime_test: false
38+
39+
- arch: i386_pentium-mmx
40+
target: x86-geode
41+
runtime_test: true
42+
43+
- arch: mips_24kc
44+
target: ath79-generic
45+
runtime_test: true
46+
47+
- arch: mipsel_24kc
48+
target: mt7621
49+
runtime_test: false
50+
51+
- arch: powerpc_464fp
52+
target: apm821xx-nand
53+
runtime_test: false
54+
55+
- arch: powerpc_8548
56+
target: mpc85xx-p1010
57+
runtime_test: false
58+
59+
# Workaround: riscv64_riscv64 was renamed to riscv64_generic
60+
- arch: ${{ (github.base_ref == 'openwrt-24.10' || github.base_ref == 'openwrt-23.05') && 'riscv64_riscv64' || 'riscv64_generic' }}
61+
target: sifiveu-generic
62+
runtime_test: false
63+
64+
- arch: x86_64
65+
target: x86-64
66+
runtime_test: true
67+
1468
steps:
1569
- name: Extract PR Data
1670
id: get_pr_data
1771
uses: actions/github-script@v8
1872
with:
1973
script: |
20-
const prNumber = context.payload.client_payload.pull_request.number;
74+
const prNumber = ${{ github.event.inputs.pr_number }};
2175
if (!prNumber) {
2276
core.setFailed('Pull request number not found in the event payload.');
2377
return;
@@ -29,12 +83,199 @@ jobs:
2983
pull_number: prNumber,
3084
});
3185
core.setOutput('head_sha', pr.head.sha);
86+
core.setOutput('head_ref', pr.head.ref);
87+
core.setOutput('base_ref', pr.base.ref);
88+
core.setOutput('pr_number', prNumber);
3289
33-
- name: Checkout PR Code
34-
uses: actions/checkout@v4
90+
- name: Set latest commit status as pending
91+
uses: myrotvorets/set-commit-status-action@master
3592
with:
36-
ref: ${{ steps.get_pr_data.outputs.head_sha }}
37-
build:
38-
name: Feeds Package Test Build
39-
needs: prepare
40-
uses: openwrt/actions-shared-workflows/.github/workflows/multi-arch-test-build.yml@main
93+
sha: ${{ steps.get_pr_data.outputs.head_sha }}
94+
context: ${{ github.workflow }}/${{ matrix.arch }}
95+
status: pending
96+
97+
- uses: actions/checkout@v6
98+
with:
99+
ref: ${{ steps.get_pr_data.outputs.base_ref }}
100+
fetch-depth: 0
101+
102+
- name: Determine branch name
103+
run: |
104+
BRANCH="${GITHUB_BASE_REF#refs/heads/}"
105+
case "$BRANCH" in
106+
main|master|openwrt-[0-9]*\.[0-9]*)
107+
;;
108+
*)
109+
BRANCH="master"
110+
;;
111+
esac
112+
echo "Building for $BRANCH"
113+
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
114+
115+
- name: Determine changed packages
116+
run: |
117+
# only detect packages with changes
118+
PKG_ROOTS=$(find . -name Makefile | \
119+
grep -v ".*/src/Makefile" | \
120+
sed -e 's@./\(.*\)/Makefile@\1/@')
121+
CHANGES=$(git diff --diff-filter=d --name-only origin/$BRANCH...)
122+
123+
for ROOT in $PKG_ROOTS; do
124+
for CHANGE in $CHANGES; do
125+
if [[ "$CHANGE" == "$ROOT"* ]]; then
126+
PACKAGES+=$(echo "$ROOT" | sed -e 's@\(.*/\)*\(.*\)/@\2 @')
127+
break
128+
fi
129+
done
130+
done
131+
132+
# fallback to test packages if nothing explicitly changes this is
133+
# should run if other mechanics in packages.git changed
134+
REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
135+
if [ "$REPOSITORY_NAME" = "routing" ]; then
136+
PACKAGES="${PACKAGES:-bird2 cjdns olsrd}"
137+
elif [ "$REPOSITORY_NAME" = "telephony" ]; then
138+
PACKAGES="${PACKAGES:-asterisk siproxd freeswitch}"
139+
else
140+
PACKAGES="${PACKAGES:-vim attendedsysupgrade-common bmon}"
141+
fi
142+
143+
echo "Building $PACKAGES"
144+
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
145+
146+
- name: Build
147+
uses: openwrt/gh-action-sdk@v10
148+
env:
149+
ARCH: ${{ matrix.arch }}-${{ env.BRANCH }}
150+
FEEDNAME: packages_ci
151+
INDEX: 1
152+
V: s
153+
154+
- name: Move created packages to project dir
155+
if: always()
156+
run: cp -v bin/packages/${{ matrix.arch }}/packages_ci/* . || true
157+
158+
- name: Collect metadata
159+
if: always()
160+
run: |
161+
MERGE_ID=$(git rev-parse --short HEAD)
162+
echo "MERGE_ID=$MERGE_ID" >> $GITHUB_ENV
163+
echo "BASE_ID=$(git rev-parse --short HEAD^1)" >> $GITHUB_ENV
164+
echo "HEAD_ID=$(git rev-parse --short HEAD^2)" >> $GITHUB_ENV
165+
PRNUMBER=${GITHUB_REF_NAME%/merge}
166+
echo "PRNUMBER=$PRNUMBER" >> $GITHUB_ENV
167+
echo "ARCHIVE_NAME=${{matrix.arch}}-PR$PRNUMBER-$MERGE_ID" >> $GITHUB_ENV
168+
169+
- name: Generate metadata
170+
if: always()
171+
run: |
172+
cat << _EOF_ > PKG-INFO
173+
Metadata-Version: 2.1
174+
Name: ${{env.ARCHIVE_NAME}}
175+
Version: $BRANCH
176+
Author: $GITHUB_ACTOR
177+
Home-page: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$PRNUMBER
178+
Download-URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
179+
Summary: $PACKAGES
180+
Platform: ${{ matrix.arch }}
181+
182+
Packages for OpenWrt $BRANCH running on ${{matrix.arch}}, built from PR $PRNUMBER
183+
at commit $HEAD_ID, against $BRANCH at commit $BASE_ID, with merge SHA $MERGE_ID.
184+
185+
Modified packages:
186+
_EOF_
187+
for p in $PACKAGES
188+
do
189+
echo " "$p >> PKG-INFO
190+
done
191+
echo >> PKG-INFO
192+
echo Full file listing: >> PKG-INFO
193+
ls -al *.ipk >> PKG-INFO || true
194+
ls -al *.apk >> PKG-INFO || true
195+
cat PKG-INFO
196+
197+
- name: Store packages
198+
if: always()
199+
uses: actions/upload-artifact@v5
200+
with:
201+
name: ${{env.ARCHIVE_NAME}}-packages
202+
path: |
203+
Packages
204+
Packages.*
205+
*.ipk
206+
packages.adb
207+
*.apk
208+
PKG-INFO
209+
210+
- name: Store logs
211+
if: always()
212+
uses: actions/upload-artifact@v5
213+
with:
214+
name: ${{env.ARCHIVE_NAME}}-logs
215+
path: |
216+
logs/
217+
PKG-INFO
218+
219+
- name: Remove logs
220+
if: always()
221+
run: sudo rm -rf logs/ || true
222+
223+
- name: Check if any packages were built
224+
run: |
225+
if [ -n "$(find . -maxdepth 1 -type f -name '*.apk' -print -quit)" ]; then
226+
echo "Found *.apk files"
227+
HAVE_PKGS=true
228+
PKG_MANAGER=apk
229+
elif [ -n "$(find . -maxdepth 1 -type f -name '*.ipk' -print -quit)" ]; then
230+
echo "Found *.ipk files"
231+
HAVE_PKGS=true
232+
PKG_MANAGER=opkg
233+
else
234+
echo "No *.apk or *.ipk files found"
235+
HAVE_PKGS=false
236+
fi
237+
echo "HAVE_PKGS=$HAVE_PKGS" >> $GITHUB_ENV
238+
echo "PKG_MANAGER=$PKG_MANAGER" >> $GITHUB_ENV
239+
240+
- name: Register QEMU
241+
if: ${{ matrix.runtime_test && fromJSON(env.HAVE_PKGS) }}
242+
run: |
243+
sudo apt-get update
244+
sudo apt-get install -y qemu-user-static binfmt-support
245+
sudo update-binfmts --import
246+
247+
- name: Checkout
248+
if: ${{ matrix.runtime_test && fromJSON(env.HAVE_PKGS) }}
249+
uses: actions/checkout@v6
250+
with:
251+
repository: openwrt/actions-shared-workflows
252+
path: dockerfiles_feeds
253+
sparse-checkout: |
254+
.github/scripts/ci_helpers.sh
255+
.github/dockerfiles_feeds/Dockerfile
256+
.github/dockerfiles_feeds/entrypoint.sh
257+
sparse-checkout-cone-mode: false
258+
259+
- name: Build Docker container
260+
if: ${{ matrix.runtime_test && fromJSON(env.HAVE_PKGS) }}
261+
run: |
262+
docker build --platform linux/${{ matrix.arch }} -t test-container \
263+
--build-arg ARCH dockerfiles_feeds/.github/dockerfiles_feeds/
264+
env:
265+
ARCH: ${{ matrix.arch }}-${{ env.BRANCH }}
266+
267+
- name: Test via Docker container
268+
if: ${{ matrix.runtime_test && fromJSON(env.HAVE_PKGS) }}
269+
run: |
270+
docker run --platform linux/${{ matrix.arch }} --rm -v $GITHUB_WORKSPACE:/ci \
271+
-v $GITHUB_WORKSPACE/dockerfiles_feeds:/dockerfiles_feeds \
272+
-e CI_HELPER=/dockerfiles_feeds/scripts/ci_helpers.sh \
273+
-e PKG_MANAGER=${{ env.PKG_MANAGER }} \
274+
test-container
275+
276+
- name: Set final commit status
277+
uses: myrotvorets/set-commit-status-action@master
278+
with:
279+
sha: ${{ steps.get_pr_data.outputs.head_sha }}
280+
context: ${{ github.workflow }}/${{ matrix.arch }}
281+
status: ${{ job.status }}

0 commit comments

Comments
 (0)