Skip to content

Deploy Public

Deploy Public #34

Workflow file for this run

name: Deploy Public
env:
REPO_NAME: fourinsight-api-python
REPO_NAME_SHORT: api
SRC_ROOT_PATH: "./fourinsight/api"
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@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build sphinx==5.3.0 pydata_sphinx_theme==0.11.0 myst_parser==1.0.0
- 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: Replace package version number
run: |
filename="$SRC_ROOT_PATH/__init__.py"
search_pattern="__version__ = \"0.0.1\""
replacement_text="__version__ = \"$VERSION_NUMBER\""
sed -i "s/$search_pattern/$replacement_text/" "$filename"
- name : Inject release notes to documentation
run: |
echo $VERSION_NUMBER
n_tag=25
i=0
# Note: may have to use paging if the number of releases gets very high
for tag in $(gh api "/repos/{owner}/{repo}/releases" --paginate -q .[].tag_name)
do
if [[ "$tag" == "v$VERSION_NUMBER" ]];
then
inject=True
fi
if [[ "$inject" == "True" ]] && [[ $i -le $n_tag ]];
then
i=$((i+1))
echo -e "$(gh release view $tag --json name --template '{{.name}}\n------------------------------')" >> docs/release_notes.md
echo -e "$(gh release view $tag --json body --template '{{.body}}\n')" | sed 's/<!-[^~]*->//g' | sed G >> docs/release_notes.md
fi
done
echo -e "*Note: this list includes only the most recent releases. For full release history, see www.github.com/$REPO_NAME/releases" >> docs/release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
run: python -m build --sdist --wheel --outdir ./dist
- name: Build documentation
run: |
pip install .
sphinx-build -b html ./docs ./build/html
- name: Stash build artifacts
uses: actions/upload-artifact@v3
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 }}
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v3
with:
name: build_artifacts
- name: Publish package to TestPyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TEST_API_KEY }}
repository_url: https://test.pypi.org/legacy/
- name: Upload documentation to TEST blob storage
uses: azure/CLI@v1
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@v1
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 }}
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v3
with:
name: build_artifacts
- name: Publish package to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PROD_API_KEY }}
- name: Upload documentation to PROD blob storage
uses: azure/CLI@v1
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@v1
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"