bad39c2fc2c9b35985ffccc98a75576dfc8571dd
[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 if: ${{ github.repository_owner == 'openwrt' }}
22 uses: ./.github/workflows/build-tools.yml
23 with:
24 generate_prebuilt_artifacts: true
25
26 push-tools-container:
27 needs: build-linux-buildbot
28 name: Push prebuilt tools container
29 if: ${{ github.repository_owner == 'openwrt' }}
30 runs-on: ubuntu-latest
31
32 permissions:
33 contents: read
34 packages: write
35
36 steps:
37 - name: Set lower case owner name
38 env:
39 OWNER: ${{ github.repository_owner }}
40 run: |
41 echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV"
42
43 # Per branch tools container tag
44 # By default stick to latest
45 # For official test targetting openwrt stable branch
46 # Get the branch or parse the tag and push dedicated tools containers
47 # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
48 # will refresh the tools container with the matching tag.
49 # (example branch openwrt-22.03 -> tools:openwrt-22.03)
50 # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
51 - name: Determine tools 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 "Tools container to push tools:$CONTAINER_TAG"
66 echo "CONTAINER_TAG=$CONTAINER_TAG" >> "$GITHUB_ENV"
67
68 - name: Checkout
69 uses: actions/checkout@v3
70 with:
71 path: 'openwrt'
72
73 - name: Download prebuilt tools from build job
74 uses: actions/download-artifact@v3
75 with:
76 name: linux-buildbot-prebuilt-tools
77 path: openwrt
78
79 - name: Extract prebuild tools
80 working-directory: openwrt
81 run: tar -xf tools.tar
82
83 - name: Login to GitHub Container Registry
84 uses: docker/login-action@v2
85 with:
86 registry: ghcr.io
87 username: ${{ github.actor }}
88 password: ${{ secrets.GITHUB_TOKEN }}
89
90 - name: Build and push
91 uses: docker/build-push-action@v3
92 with:
93 context: openwrt
94 push: true
95 tags: ghcr.io/${{ env.OWNER_LC }}/tools:${{ env.CONTAINER_TAG }}
96 file: openwrt/.github/workflows/Dockerfile.tools