Merge pull request #69 from digitalaotearoa/childcareassist #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.11.9 | |
- 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.11.9 | |
- 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" |