CI: Do package run-tests only if target packages were built
[feed/routing.git] / .github / workflows / multi-arch-test-build.yml
1 name: Test Build
2
3 on:
4 pull_request:
5
6 jobs:
7 build:
8 name: Test ${{ matrix.arch }}
9 runs-on: ubuntu-latest
10 strategy:
11 fail-fast: false
12 matrix:
13 include:
14 - arch: arm_cortex-a9_vfpv3-d16
15 target: mvebu-cortexa9
16 runtime_test: false
17
18 - arch: mips_24kc
19 target: ath79-generic
20 runtime_test: true
21
22 - arch: powerpc_464fp
23 target: apm821xx-nand
24 runtime_test: false
25
26 - arch: powerpc_8548
27 target: mpc85xx-p1010
28 runtime_test: false
29
30 - arch: aarch64_cortex-a53
31 target: mvebu-cortexa53
32 runtime_test: true
33
34 - arch: arm_cortex-a15_neon-vfpv4
35 target: armvirt-32
36 runtime_test: true
37
38 - arch: i386_pentium-mmx
39 target: x86-geode
40 runtime_test: true
41
42 - arch: x86_64
43 target: x86-64
44 runtime_test: true
45
46 steps:
47 - uses: actions/checkout@v3
48 with:
49 fetch-depth: 0
50
51 - name: Determine branch name
52 run: |
53 BRANCH="${GITHUB_BASE_REF#refs/heads/}"
54 echo "Building for $BRANCH"
55 echo "BRANCH=$BRANCH" >> $GITHUB_ENV
56
57 - name: Determine changed packages
58 run: |
59 # only detect packages with changes
60 PKG_ROOTS=$(find . -name Makefile | \
61 grep -v ".*/src/Makefile" | \
62 sed -e 's@./\(.*\)/Makefile@\1/@')
63 CHANGES=$(git diff --diff-filter=d --name-only origin/$BRANCH)
64
65 for ROOT in $PKG_ROOTS; do
66 for CHANGE in $CHANGES; do
67 if [[ "$CHANGE" == "$ROOT"* ]]; then
68 PACKAGES+=$(echo "$ROOT" | sed -e 's@\(.*\)/@\1 @')
69 break
70 fi
71 done
72 done
73
74 # fallback to test packages if nothing explicitly changes this is
75 # should run if other mechanics in packages.git changed
76 PACKAGES="${PACKAGES:-bird2 cjdns olsrd}"
77
78 echo "Building $PACKAGES"
79 echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
80
81 - name: Generate build keys
82 run: |
83 sudo apt-get update
84 sudo apt-get install -y signify-openbsd
85 signify-openbsd -G -n -c 'DO NOT USE - OpenWrt packages feed CI' -p packages_ci.pub -s packages_ci.sec
86 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
87 echo "KEY_BUILD<<$EOF" >> $GITHUB_ENV
88 cat packages_ci.sec >> $GITHUB_ENV
89 echo "$EOF" >> $GITHUB_ENV
90
91 - name: Build
92 uses: openwrt/gh-action-sdk@v5
93 env:
94 ARCH: ${{ matrix.arch }}-${{ env.BRANCH }}
95 FEEDNAME: packages_ci
96 INDEX: 1
97 KEY_BUILD: ${{ env.KEY_BUILD }}
98
99 - name: Move created packages to project dir
100 run: cp bin/packages/${{ matrix.arch }}/packages_ci/* . || true
101
102 - name: Store packages
103 uses: actions/upload-artifact@v3
104 with:
105 name: ${{env.ARCHIVE_NAME}}-packages
106 path: |
107 Packages
108 Packages.*
109 *.ipk
110 PKG-INFO
111
112 - name: Store logs
113 uses: actions/upload-artifact@v3
114 with:
115 name: ${{ matrix.arch}}-logs
116 path: logs/
117
118 - name: Remove logs
119 run: sudo rm -rf logs/ || true
120
121 - name: Check if any packages were built
122 run: |
123 if [ -n "$(find . -maxdepth 1 -type f -name '*.ipk' -print -quit)" ]; then
124 echo "Found *.ipk files"
125 HAVE_IPKS=true
126 else
127 echo "No *.ipk files found"
128 HAVE_IPKS=false
129 fi
130 echo "HAVE_IPKS=$HAVE_IPKS" >> $GITHUB_ENV
131
132 - name: Register QEMU
133 if: ${{ matrix.runtime_test && fromJSON(env.HAVE_IPKS) }}
134 run: |
135 sudo apt-get update
136 sudo apt-get install -y qemu-user-static binfmt-support
137 sudo update-binfmts --import
138
139 - name: Build Docker container
140 if: ${{ matrix.runtime_test && fromJSON(env.HAVE_IPKS) }}
141 run: |
142 docker build -t test-container --build-arg ARCH .github/workflows/
143 env:
144 ARCH: ${{ matrix.arch }}-${{ env.BRANCH }}
145
146 - name: Test via Docker container
147 if: ${{ matrix.runtime_test && fromJSON(env.HAVE_IPKS) }}
148 run: |
149 docker run --rm -v $GITHUB_WORKSPACE:/ci test-container