-
Notifications
You must be signed in to change notification settings - Fork 1
213 lines (194 loc) · 7.17 KB
/
test.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: CI Tests
on:
push:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
debug_only_this_job:
type: boolean
description: 'Run the build with tmate debugging enabled for this job only'
required: false
default: false
issue_release:
type: boolean
description: 'Issue a release'
required: false
default: false
dry_release_run:
type: boolean
description: 'Do not actually release the package, just check that it is valid.'
required: false
default: false
allow_breaking_changes:
type: boolean
description: 'Skip API compatibility check. WARNING: this will allow breaking changes to the API to be released.'
required: false
default: false
jobs:
version:
uses: ./.github/workflows/get-version.yml
secrets: inherit
run-tests:
runs-on: ubuntu-latest
outputs:
release: ${{ steps.check-tag.outputs.match }}
steps:
- uses: actions/checkout@v4
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && (inputs.debug_enabled || inputs.debug_only_this_job) }}
- name: Setup docker-compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
touch .env.secret
- name: Build container
run: docker-compose build app_test
- name: Run tests
run: docker-compose run --rm app_test
- name: Validate spec
run: |
docker-compose run --rm app_test bash -c "python manage.py spectacular --fail-on-warn --validate"
check-release-type:
runs-on: ubuntu-latest
outputs:
release: ${{ steps.check-tag.outputs.release }}
dry-run: ${{ steps.check-tag.outputs.dry-run }}
needs:
- version
steps:
- name: Dump context
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
await core.group(`GitHub needs`, async () => {
core.info(JSON.stringify(JSON.parse(`${process.env.NEEDS}`), null, 2));
});
env:
NEEDS: ${{ toJson(needs) }}
- name: Check if tagged release is required
id: check-tag
run: |
set -euxo pipefail
DRY_RUN=false
RELEASE=false
# Determine release based on whether:
# 1. We're in a workflow_dispatch event and the inputs.issue_release flag is true
# 2. We're in a workflow_dispatch event and the inputs.dry_release_run flag is true
# 3. We're on a tag and the tag is a semver tag
# 4. We're on a branch and we have an unpublished version
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.issue_release }}" == "true" ]]; then
RELEASE=true
if [[ "${{ github.event.inputs.dry_release_run }}" == "true" ]]; then
DRY_RUN=true
echo "Issuing dry-run because dry_release_run flag is true"
else
echo "Issuing release because issue_release flag is true"
fi
elif [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.dry_release_run }}" == "true" ]]; then
DRY_RUN=true
RELEASE=true # requesting dry-run implies requesting release
echo "Issuing release because dry_release_run flag is true"
elif [[ "${{ github.event_name }}" == "push" ]]; then
IS_SEMVER=$(echo "${{ github.ref }}" | grep -cE "^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$" || true)
if [[ $IS_SEMVER -gt 0 ]]; then
RELEASE=true
echo "Issuing release because we're on a tag matching semver"
elif [[ "${{ needs.version.outputs.untagged }}" == "true" ]]; then
RELEASE=true
DRY_RUN=true
echo "Issuing dry-run because we're on a branch with an unpublished version"
fi
else
echo "Release/dry-run not requested or required."
fi
echo "release=$RELEASE" >> $GITHUB_OUTPUT
echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Debug with tmate
if: ${{ github.event_name == 'workflow_dispatch' && (inputs.debug_enabled || inputs.debug_only_this_job) }}
uses: mxschmitt/action-tmate@v3
release:
needs:
- run-tests
- check-release-type
if: needs.check-release-type.outputs.release == 'true'
uses: ./.github/workflows/issue-release.yml
secrets: inherit
with:
debug_enabled: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
allow_breaking_changes: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_breaking_changes }}
dry-run: ${{ needs.check-release-type.outputs.dry-run == 'true' }}
build-python:
needs:
- release
name: >-
Build 🐍📦
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python
path: .
# - name: Test python package
# run: |
# pip install -r requirements.txt
# pip install -r test-requirements.txt
# pytest test
- name: Build distribution 📦
run: python setup.py sdist bdist_wheel
- name: Save distribution 📦
uses: actions/upload-artifact@v4
with:
name: python-package
path: dist/*
publish-to-pypi:
needs:
- build-python
if: needs.check-release-type.outputs.dry-run == 'false'
name: >-
Publish Python 🐍 distribution 📦 to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/galv-client
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download distribution 📦
uses: actions/download-artifact@v4
with:
name: python-package
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-testpypi:
needs:
- build-python
if: needs.check-release-type.outputs.dry-run == 'true'
name: >-
Publish Python 🐍 distribution 📦 to TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/galv-client
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download distribution 📦
uses: actions/download-artifact@v4
with:
name: python-package
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true