CI: tools: macOS: sync with shared-actions for macOS 14
[openwrt/staging/pepe2k.git] / .github / workflows / tools.yml
1 name: Build host tools
2
3 on:
4 pull_request:
5 paths:
6 - 'tools/**'
7 - '.github/workflows/tools.yml'
8 push:
9 paths:
10 - 'tools/**'
11 - '.github/workflows/tools.yml'
12
13 permissions:
14 contents: read
15
16 jobs:
17 build-macos-latest:
18 if: github.event_name != 'push'
19 runs-on: macos-14
20
21 steps:
22 - name: Checkout
23 uses: actions/checkout@v3
24 with:
25 path: openwrt
26
27 - name: Setup MacOS
28 run: |
29 echo "WORKPATH=/Volumes/OpenWrt" >> "$GITHUB_ENV"
30 hdiutil create -size 20g -type SPARSE -fs "Case-sensitive HFS+" -volname OpenWrt OpenWrt.sparseimage
31 hdiutil attach OpenWrt.sparseimage
32 mv "$GITHUB_WORKSPACE/openwrt" /Volumes/OpenWrt/
33
34 - name: Install required prereq on MacOS
35 working-directory: ${{ env.WORKPATH }}/openwrt
36 run: |
37 brew install \
38 automake \
39 coreutils \
40 diffutils \
41 findutils \
42 gawk \
43 git-extras \
44 gnu-getopt \
45 gnu-sed \
46 grep \
47 gpatch \
48 make
49
50 echo "/bin" >> "$GITHUB_PATH"
51 echo "/sbin/Library/Apple/usr/bin" >> "$GITHUB_PATH"
52 echo "/usr/bin" >> "$GITHUB_PATH"
53 echo "/opt/homebrew/bin" >> "$GITHUB_PATH"
54 echo "/opt/homebrew/opt/coreutils/bin" >> "$GITHUB_PATH"
55 echo "/opt/homebrew/opt/findutils/libexec/gnubin" >> "$GITHUB_PATH"
56 echo "/opt/homebrew/opt/gnu-getopt/bin" >> "$GITHUB_PATH"
57 echo "/opt/homebrew/opt/make/libexec/gnubin" >> "$GITHUB_PATH"
58 echo "/usr/sbin" >> "$GITHUB_PATH"
59
60 - name: Make prereq
61 working-directory: ${{ env.WORKPATH }}/openwrt
62 run: make defconfig
63
64 - name: Build tools MacOS
65 working-directory: ${{ env.WORKPATH }}/openwrt
66 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
67
68 - name: Upload logs
69 if: always()
70 uses: actions/upload-artifact@v3
71 with:
72 name: macos-latest-logs
73 path: ${{ env.WORKPATH }}/openwrt/logs
74
75 - name: Upload config
76 if: always()
77 uses: actions/upload-artifact@v3
78 with:
79 name: macos-latest-config
80 path: ${{ env.WORKPATH }}/openwrt/.config
81
82 build-linux-buildbot:
83 runs-on: ubuntu-latest
84 container: registry.gitlab.com/openwrt/buildbot/buildworker-3.4.1
85
86 steps:
87 - name: Checkout
88 uses: actions/checkout@v3
89 with:
90 path: 'openwrt'
91
92 - name: Fix permission
93 run: |
94 chown -R buildbot:buildbot openwrt
95
96 - name: Set configs for tools container
97 if: github.event_name == 'push'
98 shell: su buildbot -c "sh -e {0}"
99 working-directory: openwrt
100 run: |
101 touch .config
102 echo CONFIG_DEVEL=y >> .config
103 echo CONFIG_AUTOREMOVE=y >> .config
104 echo CONFIG_CCACHE=y >> .config
105
106 - name: Make prereq
107 shell: su buildbot -c "sh -e {0}"
108 working-directory: openwrt
109 run: make defconfig
110
111 - name: Build tools BuildBot Container
112 shell: su buildbot -c "sh -e {0}"
113 working-directory: openwrt
114 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
115
116 - name: Upload logs
117 if: always()
118 uses: actions/upload-artifact@v3
119 with:
120 name: linux-buildbot-logs
121 path: openwrt/logs
122
123 - name: Upload config
124 if: always()
125 uses: actions/upload-artifact@v3
126 with:
127 name: linux-buildbot-config
128 path: openwrt/.config
129
130 - name: Archive prebuilt tools
131 if: github.event_name == 'push'
132 shell: su buildbot -c "sh -e {0}"
133 working-directory: openwrt
134 run: tar --mtime=now -cf tools.tar staging_dir/host build_dir/host dl
135
136 - name: Upload prebuilt tools
137 if: github.event_name == 'push'
138 uses: actions/upload-artifact@v3
139 with:
140 name: linux-buildbot-prebuilt-tools
141 path: openwrt/tools.tar
142 retention-days: 1
143
144 push-tools-container:
145 needs: build-linux-buildbot
146 runs-on: ubuntu-latest
147 if: github.event_name == 'push'
148
149 permissions:
150 contents: read
151 packages: write
152
153 steps:
154 - name: Set lower case owner name
155 env:
156 OWNER: ${{ github.repository_owner }}
157 run: |
158 echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV"
159
160 # Per branch tools container tag
161 # By default stick to latest
162 # For official test targetting openwrt stable branch
163 # Get the branch or parse the tag and push dedicated tools containers
164 # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
165 # will refresh the tools container with the matching tag.
166 # (example branch openwrt-22.03 -> tools:openwrt-22.03)
167 # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
168 - name: Determine tools container tag
169 run: |
170 CONTAINER_TAG=latest
171
172 if [ ${{ github.ref_type }} == "branch" ]; then
173 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
174 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\).*/\1/')"
175 fi
176 elif [ ${{ github.ref_type }} == "tag" ]; then
177 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
178 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
179 fi
180 fi
181
182 echo "Tools container to push tools:$CONTAINER_TAG"
183 echo "CONTAINER_TAG=$CONTAINER_TAG" >> "$GITHUB_ENV"
184
185 - name: Checkout
186 uses: actions/checkout@v3
187 with:
188 path: 'openwrt'
189
190 - name: Download prebuilt tools from build job
191 uses: actions/download-artifact@v3
192 with:
193 name: linux-buildbot-prebuilt-tools
194 path: openwrt
195
196 - name: Login to GitHub Container Registry
197 uses: docker/login-action@v2
198 with:
199 registry: ghcr.io
200 username: ${{ github.actor }}
201 password: ${{ secrets.GITHUB_TOKEN }}
202
203 - name: Build and push
204 uses: docker/build-push-action@v3
205 with:
206 context: openwrt
207 push: true
208 tags: ghcr.io/${{ env.OWNER_LC }}/tools:${{ env.CONTAINER_TAG }}
209 file: openwrt/.github/workflows/Dockerfile.tools