ci: split container push steps to separate job and add deploy tag
[buildbot.git] / .github / workflows / build-push.yml
1 name: Build and push containers
2 on:
3 push:
4 branches:
5 - master
6 tags:
7 - 'v*'
8 pull_request:
9
10 env:
11 BUILDBOT_VERSION: 3.8.0
12 GITHUB_SHA_LEN: 8
13
14 concurrency:
15 group: ${{ github.workflow }}-${{ github.ref }}
16 cancel-in-progress: ${{ github.event_name == 'pull_request' }}
17
18 jobs:
19 test-lint:
20 name: Test with Python ${{ matrix.python-version }}
21 runs-on: ubuntu-latest
22
23 strategy:
24 matrix:
25 python-version:
26 - "3.9"
27 - "3.10"
28
29 steps:
30 - name: Checkout
31 uses: actions/checkout@v3
32
33 - uses: actions/setup-python@v4
34 with:
35 python-version: ${{ matrix.python-version }}
36
37 - name: Install dependencies
38 run: pip install -r requirements-dev.txt
39
40 - name: Lint with ruff
41 run: ruff phase*/master.cfg
42
43 - name: Stylecheck with black
44 run: black phase1/master.cfg
45
46 build-test:
47 name: Build and Test container
48 runs-on: ubuntu-latest
49 needs: test-lint
50
51 permissions:
52 packages: write
53
54 strategy:
55 fail-fast: ${{ github.event_name == 'pull_request' }}
56 matrix:
57 include:
58 - container_flavor: master
59 container_verify_string: "buildmaster configured in /master"
60 - container_flavor: worker
61 container_test_command: "--env BUILDWORKER_NAME=X --env BUILDWORKER_PASSWORD=Y"
62 container_verify_string: "worker configured in /builder"
63
64 steps:
65 - name: Checkout
66 uses: actions/checkout@v3
67
68 - name: Environment variables
69 run: |
70 echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
71
72 - name: Build container and export it to local Docker
73 uses: docker/build-push-action@v4
74 with:
75 load: true
76 tags: local/${{ matrix.container_flavor }}
77 file: docker/build${{ matrix.container_flavor }}/Dockerfile
78 build-args: |
79 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
80 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}
81
82 - name: Test ${{ matrix.container_flavor }} Docker container
83 run: |
84 docker run --detach ${{ matrix.container_test_command }} --name test-${{ matrix.container_flavor }} local/${{ matrix.container_flavor }}
85 sleep 5
86 docker logs test-${{ matrix.container_flavor }} | tee ${{ matrix.container_flavor }}.log
87 grep "${{ matrix.container_verify_string }}" ${{ matrix.container_flavor }}.log
88
89 deploy:
90 name: Push Container
91 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
92 runs-on: ubuntu-latest
93 needs: build-test
94
95 environment: production
96
97 permissions:
98 packages: write
99
100 strategy:
101 matrix:
102 container_flavor:
103 - master
104 - worker
105
106 steps:
107 - name: Checkout
108 uses: actions/checkout@v3
109
110 - name: Environment variables
111 run: |
112 echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
113
114 - name: Docker meta
115 id: meta
116 uses: docker/metadata-action@v4
117 with:
118 images: name=ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
119
120 - name: Login to GitHub Container Registry
121 uses: docker/login-action@v2
122 with:
123 registry: ghcr.io
124 username: ${{ github.actor }}
125 password: ${{ secrets.GITHUB_TOKEN }}
126
127 - name: Build container again and push it
128 uses: docker/build-push-action@v4
129 with:
130 push: true
131 tags: ${{ steps.meta.outputs.tags }}
132 labels: ${{ steps.meta.outputs.labels }}
133 file: docker/build${{ matrix.container_flavor }}/Dockerfile
134 build-args: |
135 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
136 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}