-
Notifications
You must be signed in to change notification settings - Fork 8
186 lines (165 loc) · 5.77 KB
/
ci-cd.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: CI/CD
on: [push]
env:
BASE_URL_PREVIEW: mailer-romainclement.vercel.app
PYTHON_VERSION: '3.11.4'
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python modules
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pipenv
pipenv install --dev --deploy
- name: Run QA
run: |
pipenv run inv qa
pipenv run coverage xml
- name: Publish code coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
build-docker:
name: Docker build
runs-on: ubuntu-latest
needs: test
env:
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/mailer
IMAGE_TAG: latest
steps:
- uses: actions/checkout@v4
- name: Select Docker image tag (production only)
if: contains(github.ref, 'tags')
run: echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Pull latest Docker image
run: docker pull $IMAGE_NAME:latest || true
- name: Build Docker image (${{ env.IMAGE_TAG }})
run: docker build -t $IMAGE_NAME:$IMAGE_TAG --cache-from $IMAGE_NAME:latest .
- name: Log into Docker Registry
if: contains(github.ref, 'master') || contains(github.ref, 'tags')
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push Docker image
if: contains(github.ref, 'master') || contains(github.ref, 'tags')
run: |
docker push $IMAGE_NAME:$IMAGE_TAG
build-docs:
name: Build Documentation
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python modules
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pipenv
pipenv install --dev --deploy
- name: Build documentation
run: |
pipenv run mkdocs build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-docs
path: site
deploy-docs:
name: Deploy Documentation
runs-on: ubuntu-latest
needs: build-docs
if: contains(github.ref, 'master')
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: build-docs
path: site
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GH_PERSONAL_TOKEN }}
publish_dir: ./site
publish_branch: gh-pages
deploy-vercel-setup:
name: Deployment setup
runs-on: ubuntu-latest
needs: build-docker
outputs:
github_ref_slug: ${{ steps.output_step.outputs.github_ref_slug }}
deployment_url: ${{ steps.output_step.outputs.deployment_url }}
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Set preview deployment url variable
if: ${{ !contains(github.ref, 'tags') }}
run: echo "DEPLOYMENT_URL=https://${GITHUB_REF_SLUG_URL}-${BASE_URL_PREVIEW}" >> $GITHUB_ENV
- name: Set production deployment url variable
if: ${{ contains(github.ref, 'tags') }}
run: echo "DEPLOYMENT_URL=${{ secrets.MAILER_URL }}" >> $GITHUB_ENV
- id: output_step
run: |
echo "::set-output name=github_ref_slug::${GITHUB_REF_SLUG_URL}"
echo "::set-output name=deployment_url::${DEPLOYMENT_URL}"
deploy-vercel-preview:
name: Vercel preview deployment
runs-on: ubuntu-latest
needs: deploy-vercel-setup
if: ${{ !contains(github.ref, 'tags') }}
environment:
name: preview/${{ needs.deploy-vercel-setup.outputs.github_ref_slug }}
url: ${{ needs.deploy-vercel-setup.outputs.deployment_url }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Deploy to Vercel
run: |
VERCEL_ALIAS=${GITHUB_REF_SLUG_URL}-${BASE_URL_PREVIEW}
VERCEL_URL=$(vercel deploy --confirm --token $VERCEL_TOKEN)
vercel alias --token $VERCEL_TOKEN set $VERCEL_URL $VERCEL_ALIAS
deploy-vercel-production:
name: Vercel production deployment
runs-on: ubuntu-latest
needs: deploy-vercel-setup
if: contains(github.ref, 'tags')
environment:
name: production
url: ${{ needs.deploy-vercel-setup.outputs.deployment_url }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Deploy to Vercel
run: |
vercel deploy --confirm --token $VERCEL_TOKEN --prod