28b07244ef6c98caab6da3a54df0b0102f44378a
[openwrt/staging/jow.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
12 permissions:
13 contents: read
14
15 concurrency:
16 group: ${{ github.workflow }}
17 cancel-in-progress: true
18
19 jobs:
20 build-linux-buildbot:
21 name: Build tools with buildbot container
22 if: ${{ github.repository_owner == 'openwrt' }}
23 uses: ./.github/workflows/build-tools.yml
24 with:
25 generate_prebuilt_artifacts: true
26
27 push-tools-container:
28 needs: build-linux-buildbot
29 name: Push prebuilt tools container
30 if: ${{ github.repository_owner == 'openwrt' }}
31 runs-on: ubuntu-latest
32
33 permissions:
34 contents: read
35 packages: write
36
37 steps:
38 - name: Set lower case owner name
39 env:
40 OWNER: ${{ github.repository_owner }}
41 run: |
42 echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV"
43
44 # Per branch tools container tag
45 # By default stick to latest
46 # For official test targetting openwrt stable branch
47 # Get the branch or parse the tag and push dedicated tools containers
48 # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
49 # will refresh the tools container with the matching tag.
50 # (example branch openwrt-22.03 -> tools:openwrt-22.03)
51 # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
52 - name: Determine tools container tag
53 run: |
54 CONTAINER_TAG=latest
55
56 if [ ${{ github.ref_type }} == "branch" ]; then
57 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
58 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\).*/\1/')"
59 fi
60 elif [ ${{ github.ref_type }} == "tag" ]; then
61 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
62 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
63 fi
64 fi
65
66 echo "Tools container to push tools:$CONTAINER_TAG"
67 echo "CONTAINER_TAG=$CONTAINER_TAG" >> "$GITHUB_ENV"
68
69 - name: Checkout
70 uses: actions/checkout@v3
71 with:
72 path: 'openwrt'
73
74 - name: Download prebuilt tools from build job
75 uses: actions/download-artifact@v3
76 with:
77 name: linux-buildbot-prebuilt-tools
78 path: openwrt
79
80 - name: Extract prebuild tools
81 working-directory: openwrt
82 run: tar -xf tools.tar
83
84 - name: Login to GitHub Container Registry
85 uses: docker/login-action@v2
86 with:
87 registry: ghcr.io
88 username: ${{ github.actor }}
89 password: ${{ secrets.GITHUB_TOKEN }}
90
91 - name: Build and push
92 uses: docker/build-push-action@v3
93 with:
94 context: openwrt
95 push: true
96 tags: ghcr.io/${{ env.OWNER_LC }}/tools:${{ env.CONTAINER_TAG }}
97 file: openwrt/.github/workflows/Dockerfile.tools