-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (141 loc) · 4.36 KB
/
backend.yml
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
name: 'PortalBrasil: Intranet - Backend CI'
on:
workflow_call:
workflow_dispatch:
env:
IMAGE_NAME_PREFIX: ghcr.io/plonegovbr/portalbrasil-intranet
IMAGE_NAME_SUFFIX: backend
PYTHON_VERSION: "3.11"
defaults:
run:
working-directory: ./backend
jobs:
config:
runs-on: ubuntu-latest
outputs:
BASE_TAG: ${{ steps.vars.outputs.BASE_TAG }}
PLONE_VERSION: ${{ steps.vars.outputs.PLONE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Env Vars
id: vars
run: |
echo "PLONE_VERSION=$(cat version.txt)" >> $GITHUB_OUTPUT
echo 'BASE_TAG=sha-'$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT
- name: Test vars
run: |
echo 'BASE_TAG=${{ steps.vars.outputs.BASE_TAG }}'
echo 'PLONE_VERSION=${{ steps.vars.outputs.PLONE_VERSION }}'
code-quality:
runs-on: ubuntu-latest
needs:
- config
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Install hatch
run: pipx install hatch
- name: Generate Constraints file
run: pipx run mxdev -c mx.ini
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: "Install Environment"
run: hatch env create
- name: "Run checks"
run: hatch run lint
test:
runs-on: ubuntu-latest
needs:
- config
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Install hatch
run: pipx install hatch
- name: Generate Constraints file
run: pipx run mxdev -c mx.ini
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: "Install Environment"
run: hatch env create
- name: "Test Codebase"
run: hatch run test
release:
runs-on: ubuntu-latest
needs:
- config
- code-quality
- test
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: backend
file: backend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PLONE_VERSION=${{ needs.config.outputs.PLONE_VERSION }}
- name: Docker meta
id: meta-demo
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-demo
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-demo:latest
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push demo
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: backend
file: backend/Dockerfile.demo
load: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-demo.outputs.tags }}
labels: ${{ steps.meta-demo.outputs.labels }}
build-args: |
SEED=${{ github.run_id }}
IMAGE_TAG=${{ needs.config.outputs.BASE_TAG }}