Build #83
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
# Runs a build test on commit to ensure functionality. | |
name: Build | |
on: | |
push: | |
tags: | |
- "*.*.*" | |
workflow_run: | |
workflows: ["Type Coverage and Linting"] | |
types: [completed] | |
branches: [main] | |
jobs: | |
build: | |
if: ${{ github.event.workflow_run.conclusion == 'success' || startsWith(github.ref, 'refs/tags') }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.x"] | |
name: "Build @ ${{ matrix.python-version }}" | |
steps: | |
- name: "Checkout Repository" | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: "Load cached poetry installation @ ${{ matrix.python-version }}" | |
id: cached-poetry | |
uses: actions/cache@v3 | |
with: | |
path: ~/.local | |
key: poetry-0 | |
- name: "Setup Poetry @ ${{ matrix.python-version }}" | |
if: steps.cached-poetry.outputs.cache-hit != 'true' | |
uses: snok/install-poetry@v1 | |
with: | |
version: latest | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
virtualenvs-path: ~/.venv | |
- name: "Setup Python @ ${{ matrix.python-version }}" | |
id: setup-python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "${{ matrix.python-version }}" | |
cache: "poetry" | |
- name: "Load cached venv @ ${{ matrix.python-version }}" | |
id: cached-pip-wheels | |
uses: actions/cache@v3 | |
with: | |
path: .venv/ | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: "Install Python deps @ ${{ matrix.python-version }}" | |
if: ${{ steps.cached-pip-wheels.outputs.cache-hit != 'true' }} | |
id: install-deps | |
run: | | |
poetry install --no-interaction | |
- name: Activate venv @ ${{ matrix.python-version }} | |
run: | | |
echo "$(poetry env info --path)/bin" >> $GITHUB_PATH | |
- name: "Check it imports @ ${{ matrix.python-version }}" | |
run: | | |
poetry run python -c 'import mystbin' | |
- name: "Build wheels @ ${{ matrix.python-version}}" | |
run: | | |
poetry build | |
- name: "Build docs @ ${{ matrix.python-version}}" | |
run: | | |
cd docs/ | |
poetry run sphinx-build -aETW --keep-going . build | |
- name: "Upload artifacts @ ${{ matrix.python-version}}" | |
if: ${{ matrix.python-version == '3.11' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: distributions | |
path: dist/* | |
# Credits to most of this step go to Gorialis (Devon R [https://github.com/Gorialis]) | |
# as I found them in their Jishaku builds (https://github.com/Gorialis/jishaku/blob/d3f50749b5a977b544e5fd14894585f656247486/.github/workflows/deploy.yml#L82-L119) | |
create_release: | |
name: Create Release | |
needs: [build] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
submodules: true | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: distributions | |
path: dist | |
- name: Create GitHub release | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -x | |
assets=() | |
for asset in ./dist/*.{whl,tar.gz}; do | |
assets+=("$asset") | |
done | |
tag_name="${GITHUB_REF##*/}" | |
gh release create "$tag_name" -F "CHANGELOG.md" "${assets[@]}" | |
- name: "Set up Poetry" | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: false | |
- name: Publish to PyPI | |
env: | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
run: | | |
poetry config pypi-token.pypi $PYPI_TOKEN | |
poetry publish |