summaryrefslogtreecommitdiffstats
path: root/.github/workflows/build-push.yml
blob: 774f7a5a93c3085221c1c84f6d92e7c0e9ec210a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build and push containers
on:
  push:
    branches:
      - main
    tags:
      - 'v*'
  pull_request:
  workflow_dispatch:
    inputs:
      pr_number:
        description: 'PR number to build and push container for'
        required: true
        type: number

env:
  GITHUB_SHA_LEN: 8

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  test-lint:
    name: Test with Python ${{ matrix.python-version }}
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version:
          - "3.11"

    steps:
      - name: Checkout
        uses: actions/checkout@v5
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/merge', inputs.pr_number) || '' }}

      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        run: pip install -r requirements-dev.txt

      - name: Lint with ruff
        run: ruff phase*/master.cfg

      - name: Lint with flake8
        run: flake8 phase*/master.cfg

      - name: Stylecheck with black
        run: black phase1/master.cfg

  build-test:
    name: Build and Test container
    runs-on: ubuntu-latest
    needs: test-lint

    permissions:
      packages: write

    strategy:
      fail-fast: ${{ github.event_name == 'pull_request' }}
      matrix:
        include:
          - container_flavor: master
          - container_flavor: worker
            container_test_command: "--env BUILDWORKER_TLS=1 --env BUILDWORKER_MASTER=Z:1922 --env BUILDWORKER_NAME=X --env BUILDWORKER_PASSWORD=Y"

    steps:
      - name: Checkout
        uses: actions/checkout@v5
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/merge', inputs.pr_number) || '' }}

      - name: Environment variables
        run: |
          echo "BUILDBOT_VERSION=$(cat .github/buildbot-version)" >> $GITHUB_ENV
          echo "GIT_SHA_SHORT=$(git rev-parse --short=${{ env.GITHUB_SHA_LEN }} HEAD)" >> $GITHUB_ENV
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "CONTAINER_TAG=pr-${{ inputs.pr_number }}" >> $GITHUB_ENV
          elif [ "${{ startsWith(github.ref, 'refs/tags/') }}" = "true" ]; then
            echo "CONTAINER_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
          else
            echo "CONTAINER_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
          fi

      - name: Build container and export it to local Docker
        uses: docker/build-push-action@v6
        with:
          context: .
          load: true
          tags: local/${{ matrix.container_flavor }}
          file: docker/build${{ matrix.container_flavor }}/Dockerfile
          build-args: |
            BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
            BUILDBOT_CONFIG_SHA=${{ env.GIT_SHA_SHORT }}
            CONTAINER_TAG=${{ env.CONTAINER_TAG }}

      - name: Test ${{ matrix.container_flavor }} Docker container
        run: |
          docker run --detach ${{ matrix.container_test_command }} --name test-${{ matrix.container_flavor }} local/${{ matrix.container_flavor }}
          sleep 5
          pip install cram
          cram --verbose "tests/cram/${{ matrix.container_flavor }}"

  deploy:
    name: Push Container
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    needs: build-test

    environment: production

    permissions:
      packages: write

    strategy:
      matrix:
        container_flavor:
          - master
          - worker

    steps:
      - name: Checkout
        uses: actions/checkout@v5
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/merge', inputs.pr_number) || '' }}

      - name: Environment variables
        run: |
          echo "BUILDBOT_VERSION=$(cat .github/buildbot-version)" >> $GITHUB_ENV
          echo "GIT_SHA_SHORT=$(git rev-parse --short=${{ env.GITHUB_SHA_LEN }} HEAD)" >> $GITHUB_ENV
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "CONTAINER_TAG=pr-${{ inputs.pr_number }}" >> $GITHUB_ENV
          elif [ "${{ startsWith(github.ref, 'refs/tags/') }}" = "true" ]; then
            echo "CONTAINER_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
          else
            echo "CONTAINER_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
          fi

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
          tags: |
            type=raw,value=pr-${{ inputs.pr_number }},enable=${{ github.event_name == 'workflow_dispatch' }}
            type=ref,event=branch,enable=${{ github.event_name != 'workflow_dispatch' }}
            type=ref,event=tag,enable=${{ github.event_name != 'workflow_dispatch' }}
            type=sha,prefix=sha-,enable=${{ github.event_name != 'workflow_dispatch' }}

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build container again and push it
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          file: docker/build${{ matrix.container_flavor }}/Dockerfile
          build-args: |
            BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
            BUILDBOT_CONFIG_SHA=${{ env.GIT_SHA_SHORT }}
            CONTAINER_TAG=${{ env.CONTAINER_TAG }}