Skip to content

Deploy Public

Deploy Public #29

name: Deploy Public
env:
REPO_NAME: smsfusion-python
REPO_NAME_SHORT: smsfusion
SRC_ROOT_PATH: "./src/smsfusion"
on:
workflow_dispatch:
inputs:
version_number:
description: Release version number [MAJOR.MINOR.PATCH] to deploy. Use "$latest" to automatically choose the latest release.
required: true
type: string
default: "$latest"
pipeline:
description: Choose deploy pipeline.
required: true
default: production
type: choice
options:
- production
- test
doc_latest:
description: Deploy documentation as latest?
default: true
required: true
type: boolean
jobs:
build:
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.version_number.outputs.VERSION_NUMBER }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install hatch
- name: Get new version number from input
id: version_number
run: |
if [ "${{ inputs.version_number }}" = "$latest" ]
then
version="$(gh release view --json tagName --jq .tagName)"
version=${version#v}
else
version="${{ inputs.version_number }}"
fi
echo "VERSION_NUMBER=$version" | tee $GITHUB_ENV $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update package version number
run: hatch version $VERSION_NUMBER
- name : Inject release notes to documentation
run: |
gh api "https://api.github.com/repos/{owner}/{repo}/releases" --template "
{{- range . -}}
{{ if and (le .tag_name \"v$VERSION_NUMBER\") (eq .draft false) (eq .prerelease false) }}
# [{{ .name }}]({{ .html_url }})
{{ .body }}
{{ end }}
{{- end -}}
" > docs/release_notes/generated.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
run: hatch build -t wheel
- name: Build documentation
run: hatch run docs:build
- name: Stash build artifacts
uses: actions/upload-artifact@v4
with:
name: build_artifacts
path: |
./dist/*.whl
./build/html
retention-days: 1
deploy-test:
if: ${{ inputs.pipeline == 'test' }}
runs-on: ubuntu-latest
needs: build
env:
VERSION_NUMBER: ${{ needs.build.outputs.version_number }}
name: pypi
url: https://pypi.org/p/<your-pypi-project-name>
permissions:
id-token: write
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: build_artifacts
- name: Publish package to TestPyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Upload documentation to TEST blob storage
uses: azure/CLI@v2
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTTEST_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/$VERSION_NUMBER"
- name: Upload documentation to TEST blob storage as latest
if: ${{ inputs.doc_latest }}
uses: azure/CLI@v2
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTTEST_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob delete-batch -s "\$web" --pattern "$REPO_NAME_SHORT/python/docs/latest/*"
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/latest"
deploy-prod:
if: ${{ inputs.pipeline == 'production' }}
runs-on: ubuntu-latest
needs: build
env:
VERSION_NUMBER: ${{ needs.build.outputs.version_number }}
name: pypi
url: https://pypi.org/p/<your-pypi-project-name>
permissions:
id-token: write
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: build_artifacts
- name: Publish package to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
- name: Upload documentation to PROD blob storage
uses: azure/CLI@v2
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTPROD_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/$VERSION_NUMBER"
- name: Upload documentation to PROD blob storage as latest
if: ${{ inputs.doc_latest }}
uses: azure/CLI@v2
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTPROD_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob delete-batch -s "\$web" --pattern "$REPO_NAME_SHORT/python/docs/latest/*"
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/latest"