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