phase1,phase2: s/master/main for phase{1,2}
[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.9.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@v4
32
33 - uses: actions/setup-python@v5
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: Lint with flake8
44 run: flake8 phase*/master.cfg
45
46 - name: Stylecheck with black
47 run: black phase1/master.cfg
48
49 build-test:
50 name: Build and Test container
51 runs-on: ubuntu-latest
52 needs: test-lint
53
54 permissions:
55 packages: write
56
57 strategy:
58 fail-fast: ${{ github.event_name == 'pull_request' }}
59 matrix:
60 include:
61 - container_flavor: master
62 container_verify_string: "buildmaster configured in /master"
63 - container_flavor: worker
64 container_test_command: "--env BUILDWORKER_NAME=X --env BUILDWORKER_PASSWORD=Y"
65 container_verify_string: "worker configured in /builder"
66
67 steps:
68 - name: Checkout
69 uses: actions/checkout@v4
70
71 - name: Environment variables
72 run: |
73 echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
74
75 - name: Build container and export it to local Docker
76 uses: docker/build-push-action@v5
77 with:
78 load: true
79 tags: local/${{ matrix.container_flavor }}
80 file: docker/build${{ matrix.container_flavor }}/Dockerfile
81 build-args: |
82 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
83 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}
84
85 - name: Test ${{ matrix.container_flavor }} Docker container
86 run: |
87 docker run --detach ${{ matrix.container_test_command }} --name test-${{ matrix.container_flavor }} local/${{ matrix.container_flavor }}
88 sleep 5
89 pip install cram
90 cram --verbose "tests/cram/${{ matrix.container_flavor }}"
91
92 deploy:
93 name: Push Container
94 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
95 runs-on: ubuntu-latest
96 needs: build-test
97
98 environment: production
99
100 permissions:
101 packages: write
102
103 strategy:
104 matrix:
105 container_flavor:
106 - master
107 - worker
108
109 steps:
110 - name: Checkout
111 uses: actions/checkout@v4
112
113 - name: Environment variables
114 run: |
115 echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
116
117 - name: Docker meta
118 id: meta
119 uses: docker/metadata-action@v5
120 with:
121 images: name=ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
122
123 - name: Login to GitHub Container Registry
124 uses: docker/login-action@v3
125 with:
126 registry: ghcr.io
127 username: ${{ github.actor }}
128 password: ${{ secrets.GITHUB_TOKEN }}
129
130 - name: Build container again and push it
131 uses: docker/build-push-action@v5
132 with:
133 push: true
134 tags: ${{ steps.meta.outputs.tags }}
135 labels: ${{ steps.meta.outputs.labels }}
136 file: docker/build${{ matrix.container_flavor }}/Dockerfile
137 build-args: |
138 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
139 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}