Skip to content

V0.0.1dev6 (#8)

V0.0.1dev6 (#8) #10

Workflow file for this run

name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest
permissions:
contents: read
statuses: read
steps:
- name: Wait for Linting/Coverage Jobs to Finish
id: check_status
uses: actions/github-script@v6
with:
script: |
let maxRetries = 10;
const delay = ms => new Promise(res => setTimeout(res, ms));
for (let i = 0; i < maxRetries; i++) {
const { data } = await github.rest.repos.getCombinedStatusForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: '${{ github.sha }}'
});
const pylintStatus = data.statuses.find(status => status.context === 'PyLint')?.state;
const pylintSHA = data.statuses.find(status => status.context === 'PyLint')?.sha;
const blackStatus = data.statuses.find(status => status.context === 'Black Formatter')?.state;
const blackSHA = data.statuses.find(status => status.context === 'Black Formatter')?.sha;
const coverageStatus = data.statuses.find(status => status.context === 'Coverage')?.state;
const coverageSHA = data.statuses.find(status => status.context === 'Coverage')?.sha;
console.log(`PyLint: ${pylintStatus} (${pylintSHA}) | Black: ${blackStatus} (${blackSHA}) | Coverage: ${coverageStatus} (${coverageSHA})`);
if (pylintStatus === 'success' && blackStatus === 'success' && coverageStatus === 'success') {
console.log('Pylint, Black and Coverage succeeded.');
return;
}
if (pylintStatus !== undefined && blackStatus !== undefined && coverageStatus !== undefined) {
throw new Error("Linting jobs and Coverage did not complete successfully.");
}
console.log(`Retrying... (${i + 1}/${maxRetries})`);
await delay(30000); // wait 30s
}
throw new Error("Linting jobs and Coverage did not complete successfully.");
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read Python version from file
id: get_python_version
run: |
python_version=$(cat .python_version)
echo "Using Python version: $python_version"
echo "python-version=$python_version" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install coverage
# Execute tests with coverage
- name: Run tests and check coverage
run: |
coverage run -m unittest discover -s ./tests
# Check if coverage is 100%
- name: Check 100% coverage
run: |
coverage report --fail-under=100
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/bigquery-advanced-utils
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CHANGELOG=$(cat CHANGELOG.md)
gh release create \
'${{ github.ref_name }}' \
--repo '${{ github.repository }}' \
--notes "$CHANGELOG"
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'