-
Notifications
You must be signed in to change notification settings - Fork 15
70 lines (65 loc) · 2.48 KB
/
deploy.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
name: Deploy
on:
push:
branches: [ main ]
jobs:
validate:
uses: "./.github/workflows/validate.yml"
# GitHub Actions does not have a halt job option to stop from deploying if no functional changes were found.
# We thus execute a separate deployment job depending on the output of this job.
check-for-functional-changes:
runs-on: ubuntu-22.04
outputs:
status: ${{ steps.stop-early.outputs.status }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.12
- id: stop-early
run: |
if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh"
then
echo "status=success" >> $GITHUB_OUTPUT
fi
check-pypi-token: # Use intermediary job as secrets cannot be directly referenced in `if:` conditionals; see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
runs-on: ubuntu-22.04
outputs:
pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }}
steps:
- name: Check PyPI token is defined
id: check_token
run: |
if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]
then
echo "pypi_token_present=true" >> $GITHUB_OUTPUT
else
echo "pypi_token_present=false" >> $GITHUB_OUTPUT
fi
deploy:
runs-on: ubuntu-22.04
needs: [ validate, check-for-functional-changes, check-pypi-token ]
if: needs.check-for-functional-changes.outputs.status == 'success' && needs.check-pypi-token.outputs.pypi_token_present == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.12
- name: Restore build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Restore built package
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
- name: Upload a Python package to PyPi
run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }}
- name: Publish a git tag
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"