CI: build: add job to remove previous ccache cache if already exist
[openwrt/staging/hauke.git] / .github / workflows / push-containers.yml
1 name: Build and Push prebuilt tools container
2
3 on:
4 push:
5 paths:
6 - 'include/version.mk'
7 - 'tools/**'
8 - '.github/workflows/build-tools.yml'
9 - '.github/workflows/push-containers.yml'
10 - '.github/workflows/Dockerfile.tools'
11 - 'toolchain/**'
12 - '.github/workflows/build.yml'
13 - '.github/workflows/toolchain.yml'
14 - '.github/workflows/Dockerfile.toolchain'
15 branches-ignore:
16 - master
17
18 permissions:
19 contents: read
20
21 concurrency:
22 group: ${{ github.workflow }}
23 cancel-in-progress: true
24
25 jobs:
26 determine-container-info:
27 name: Determine needed info to push containers
28 if: ${{ github.repository_owner == 'openwrt' }}
29 runs-on: ubuntu-latest
30 outputs:
31 owner-lc: ${{ steps.generate-owner-lc.outputs.owner-lc }}
32 container-tag: ${{ steps.determine-container-tag.outputs.container-tag }}
33
34 steps:
35 - name: Set lower case owner name
36 id: generate-owner-lc
37 env:
38 OWNER: ${{ github.repository_owner }}
39 run: |
40 echo "owner-lc=${OWNER,,}" >> "$GITHUB_OUTPUT"
41
42 # Per branch tools container tag
43 # By default stick to latest
44 # For official test targetting openwrt stable branch
45 # Get the branch or parse the tag and push dedicated tools containers
46 # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
47 # will refresh the tools container with the matching tag.
48 # (example branch openwrt-22.03 -> tools:openwrt-22.03)
49 # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
50 - name: Determine tools container tag
51 id: determine-container-tag
52 run: |
53 CONTAINER_TAG=latest
54
55 if [ ${{ github.ref_type }} == "branch" ]; then
56 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
57 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\).*/\1/')"
58 fi
59 elif [ ${{ github.ref_type }} == "tag" ]; then
60 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
61 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
62 fi
63 fi
64
65 echo "Container tag to push for tools and toolchain is $CONTAINER_TAG"
66 echo "container-tag=$CONTAINER_TAG" >> "$GITHUB_OUTPUT"
67
68 build-linux-buildbot:
69 name: Build tools with buildbot container
70 if: ${{ github.repository_owner == 'openwrt' }}
71 uses: ./.github/workflows/build-tools.yml
72 with:
73 generate_prebuilt_artifacts: true
74
75 push-tools-container:
76 needs: [ determine-container-info, build-linux-buildbot ]
77 if: ${{ github.repository_owner == 'openwrt' }}
78 name: Push prebuilt tools container
79 runs-on: ubuntu-latest
80
81 permissions:
82 contents: read
83 packages: write
84
85 steps:
86 - name: Checkout
87 uses: actions/checkout@v3
88 with:
89 path: 'openwrt'
90
91 - name: Download prebuilt tools from build job
92 uses: actions/download-artifact@v3
93 with:
94 name: linux-buildbot-prebuilt-tools
95 path: openwrt
96
97 - name: Extract prebuild tools
98 working-directory: openwrt
99 run: tar -xf tools.tar
100
101 - name: Login to GitHub Container Registry
102 uses: docker/login-action@v2
103 with:
104 registry: ghcr.io
105 username: ${{ github.actor }}
106 password: ${{ secrets.GITHUB_TOKEN }}
107
108 - name: Build and push
109 uses: docker/build-push-action@v3
110 with:
111 context: openwrt
112 push: true
113 tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/tools:${{ needs.determine-container-info.outputs.container-tag }}
114 file: openwrt/.github/workflows/Dockerfile.tools
115
116 determine-targets:
117 name: Set targets
118 if: ${{ github.repository_owner == 'openwrt' }}
119 runs-on: ubuntu-latest
120 outputs:
121 target: ${{ steps.find_targets.outputs.target }}
122
123 steps:
124 - name: Checkout
125 uses: actions/checkout@v3
126
127 - name: Set targets
128 id: find_targets
129 run: |
130 export TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null \
131 | awk '{ print $1 }')"
132
133 JSON='['
134 FIRST=1
135 for TARGET in $TARGETS; do
136 TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
137 [[ $FIRST -ne 1 ]] && JSON="$JSON"','
138 JSON="$JSON""$TUPLE"
139 FIRST=0
140 done
141 JSON="$JSON"']'
142
143 echo -e "\n---- targets ----\n"
144 echo "$JSON"
145 echo -e "\n---- targets ----\n"
146
147 echo "target=$JSON" >> $GITHUB_OUTPUT
148
149 build:
150 name: Build Target Toolchain
151 if: ${{ github.repository_owner == 'openwrt' }}
152 needs: [ determine-targets, push-tools-container ]
153 permissions:
154 contents: read
155 packages: read
156 actions: write
157 strategy:
158 fail-fast: False
159 matrix:
160 include: ${{fromJson(needs.determine-targets.outputs.target)}}
161 uses: ./.github/workflows/build.yml
162 with:
163 target: ${{ matrix.target }}
164 subtarget: ${{ matrix.subtarget }}
165 build_toolchain: true
166 build_external_toolchain: true
167 upload_external_toolchain: true
168
169 push-toolchain-container:
170 name: Push Target Toolchain container
171 if: ${{ github.repository_owner == 'openwrt' }}
172 needs: [ determine-container-info, determine-targets, build ]
173 runs-on: ubuntu-latest
174
175 strategy:
176 fail-fast: False
177 matrix:
178 include: ${{fromJson(needs.determine-targets.outputs.target)}}
179
180 permissions:
181 contents: read
182 packages: write
183
184 steps:
185 - name: Checkout
186 uses: actions/checkout@v3
187 with:
188 path: 'openwrt'
189
190 - name: Download external toolchain from build job
191 uses: actions/download-artifact@v3
192 with:
193 name: ${{ matrix.target }}-${{ matrix.subtarget }}-external-toolchain
194 path: openwrt
195
196 - name: Find external toolchain name
197 id: get-toolchain-name
198 working-directory: openwrt
199 run: |
200 TOOLCHAIN_NAME=$(ls | grep toolchain-${{ matrix.target }}-${{ matrix.subtarget }})
201 echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
202
203 - name: Login to GitHub Container Registry
204 uses: docker/login-action@v2
205 with:
206 registry: ghcr.io
207 username: ${{ github.actor }}
208 password: ${{ secrets.GITHUB_TOKEN }}
209
210 - name: Build and push
211 uses: docker/build-push-action@v3
212 with:
213 context: openwrt
214 push: true
215 tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/toolchain:${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.determine-container-info.outputs.container-tag }}
216 file: openwrt/.github/workflows/Dockerfile.toolchain
217 build-args: |
218 OWNER_LC=${{ needs.determine-container-info.outputs.owner-lc }}
219 CONTAINER_TAG=${{ needs.determine-container-info.outputs.container-tag }}
220 TOOLCHAIN_NAME=${{ steps.get-toolchain-name.outputs.toolchain-name }}