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