ci: move git short sha length to ENV
[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-push:
47 name: Build, test and push containers
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 container_flavor:
58 - master
59 - worker
60
61 steps:
62 - name: Checkout
63 uses: actions/checkout@v3
64
65 - name: Environment variables
66 run: |
67 echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
68
69 - name: Build container and export it to local Docker
70 uses: docker/build-push-action@v4
71 with:
72 load: true
73 tags: local/${{ matrix.container_flavor }}
74 file: docker/build${{ matrix.container_flavor }}/Dockerfile
75 build-args: |
76 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
77 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}
78
79 - name: Test master Docker container
80 if: matrix.container_flavor == 'master'
81 run: |
82 docker run --detach --name test-master local/master
83 sleep 5
84 docker logs test-master | tee master.log
85 grep "buildmaster configured in /master" master.log
86
87 - name: Test worker Docker container
88 if: matrix.container_flavor == 'worker'
89 run: |
90 docker run --detach --env BUILDWORKER_NAME=X --env BUILDWORKER_PASSWORD=Y --name test-worker local/worker
91 sleep 5
92 docker logs test-worker | tee worker.log
93 grep "worker configured in /builder" worker.log
94
95 - name: Docker meta
96 id: meta
97 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
98 uses: docker/metadata-action@v4
99 with:
100 images: name=ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
101
102 - name: Login to GitHub Container Registry
103 uses: docker/login-action@v2
104 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
105 with:
106 registry: ghcr.io
107 username: ${{ github.actor }}
108 password: ${{ secrets.GITHUB_TOKEN }}
109
110 - name: Build container again and push it
111 uses: docker/build-push-action@v4
112 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
113 with:
114 push: true
115 tags: ${{ steps.meta.outputs.tags }}
116 labels: ${{ steps.meta.outputs.labels }}
117 file: docker/build${{ matrix.container_flavor }}/Dockerfile
118 build-args: |
119 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
120 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}