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