Merge pull request #1688 from TeoZosa/dependabot/pip/xdoctest-1.2.0 #3168
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: Release | |
on: # yamllint disable-line rule:truthy | |
push: | |
branches: | |
- main # forward-compatibility with new GitHub default branch naming | |
- master # backward-compatibility with old GitHub default branch naming | |
workflow_dispatch: | |
pull_request: | |
jobs: | |
# Shared tag & version number info ---------------------- | |
get-tag-xor-dev-version: | |
name: Get tags and version numbers | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.detect-new-version-tag.outputs.tag }} | |
dev-version: ${{ steps.bump-dev-version.outputs.version }} | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
with: | |
fetch-depth: 2 | |
- name: Set up Python | |
uses: actions/setup-python@v4.2.0 | |
with: | |
python-version: "3.11" | |
- name: Upgrade pip | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt pip | |
pip --version | |
- name: Install Poetry | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt poetry | |
poetry --version | |
- name: Check if there is a parent commit | |
id: check-parent-commit | |
run: | | |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT | |
- name: Detect new version tag | |
id: detect-new-version-tag | |
if: "steps.check-parent-commit.outputs.sha" | |
run: | | |
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
git checkout HEAD~ | |
PARENT_COMMIT_VER=$(make get-project-version-number) | |
git checkout "${BRANCH_NAME}" | |
CURRENT_COMMIT_VER=$(make get-project-version-number) | |
if [[ "${PARENT_COMMIT_VER}" != "${CURRENT_COMMIT_VER}" ]]; then | |
echo "tag=${CURRENT_COMMIT_VER}" >> $GITHUB_OUTPUT | |
fi | |
- name: Bump version for developmental release | |
id: bump-dev-version | |
if: "! steps.detect-new-version-tag.outputs.tag" | |
run: | | |
poetry version patch && | |
VERSION=$(make get-project-version-number) && | |
DEV_VERSION="${VERSION}.dev.$(date +%s)" && | |
poetry version "${DEV_VERSION}" && | |
echo "version=${DEV_VERSION}" >> $GITHUB_OUTPUT | |
# Package build ---------------------- | |
package-build: | |
strategy: | |
matrix: | |
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | |
python-version: ["3.8", "3.9", "3.10", "3.11"] | |
name: Package build | |
runs-on: ${{ matrix.os }} | |
needs: get-tag-xor-dev-version | |
outputs: | |
is-test-package: ${{ steps.use-dev-version-for-testing.outputs.is_testing }} | |
package-version: ${{ steps.log-package-version.outputs.version }} | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
- name: Set up Python | |
uses: actions/setup-python@v4.2.0 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Upgrade pip | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt pip | |
pip --version | |
- name: Install Poetry | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt poetry | |
poetry --version | |
- name: Install Tox | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt tox | |
tox --version | |
- name: Load cached tox testenv(s) (if they exist) | |
id: cached-poetry-dependencies | |
uses: actions/cache@v3.0.1 | |
with: | |
path: | | |
.tox | |
key: tox-${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-CPython${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
# Update the project version number to the dev version that was | |
# generated upstream (only used in non-release builds; else project | |
# already set to the correct version number) | |
- name: Use dev project version for testing | |
id: use-dev-version-for-testing | |
if: "needs.get-tag-xor-dev-version.outputs.dev-version" | |
run: | | |
VERSION=${{ needs.get-tag-xor-dev-version.outputs.dev-version }} | |
poetry version "${VERSION}" | |
echo "is_testing=true" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Log package version | |
id: log-package-version | |
run: | | |
VERSION=$(make get-project-version-number) | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Build package | |
run: | | |
make package | |
- name: Store the binary wheel | |
uses: actions/upload-artifact@v3.1.0 | |
with: | |
name: python-package-distributions | |
path: dist | |
# PyPI/TestPyPI package upload ---------------------- | |
pypi-packages-upload: | |
name: PyPI/TestPyPI package upload | |
runs-on: ubuntu-latest | |
needs: package-build | |
outputs: | |
package-version: ${{ needs.package-build.outputs.package-version }} | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
- name: Set up Python | |
uses: actions/setup-python@v4.2.0 | |
with: | |
python-version: "3.11" | |
- name: Upgrade pip | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt pip | |
pip --version | |
- name: Download the binary wheels | |
uses: actions/download-artifact@v3.0.0 | |
with: | |
name: python-package-distributions | |
path: dist | |
- name: Publish packages on PyPI | |
if: "! needs.package-build.outputs.is-test-package" | |
uses: pypa/gh-action-pypi-publish@v1.5.1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_TOKEN }} # pragma: allowlist secret | |
- name: Publish packages on TestPyPI | |
if: "needs.package-build.outputs.is-test-package" | |
uses: pypa/gh-action-pypi-publish@v1.5.1 | |
with: | |
user: __token__ | |
password: ${{ secrets.TEST_PYPI_TOKEN }} # pragma: allowlist secret | |
repository_url: https://test.pypi.org/legacy/ | |
# Install Verification ---------------------- | |
verify-user-install: | |
strategy: | |
matrix: | |
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | |
python-version: ["3.8", "3.9", "3.10", "3.11"] | |
name: Verify package install as user | |
runs-on: ${{ matrix.os }} | |
needs: pypi-packages-upload | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
- name: Set up Python | |
uses: actions/setup-python@v4.2.0 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install package-under-test | |
run: | | |
PYPI_PACKAGE="cookiecutter-cruft-poetry-tox-pre-commit-ci-cd-instance==${PACKAGE_VERSION}" | |
TEST_PYPI_PACKAGE="${PYPI_PACKAGE} --index-url https://test.pypi.org/simple/" | |
function install_test_pypi() { pip install ${TEST_PYPI_PACKAGE} --no-deps && install_pypi; } | |
function install_pypi() { pip install --upgrade ${PYPI_PACKAGE}; } | |
until (install_test_pypi || install_pypi) | |
do | |
echo "Waiting for Python Package Index to serve current package-under-test: ${PYPI_PACKAGE}" | |
sleep 10 | |
done | |
pip list -v | |
env: | |
PACKAGE_VERSION: ${{ needs.pypi-packages-upload.outputs.package-version }} | |
shell: bash | |
- name: Run basic commands | |
run: | | |
cookiecutter-cruft-poetry-tox-pre-commit-ci-cd-instance --help || true | |
cookiecutter-cruft-poetry-tox-pre-commit-ci-cd-instance --version || true | |
cookiecutter-cruft-poetry-tox-pre-commit-ci-cd-instance || true | |
shell: bash | |
# Docker image build and upload ---------------------- | |
docker-image-build-and-upload: | |
name: Docker image build and upload | |
runs-on: ubuntu-latest | |
needs: get-tag-xor-dev-version | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
- name: Set up Python | |
uses: actions/setup-python@v4.2.0 | |
with: | |
python-version: "3.11" | |
- name: Upgrade pip | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt pip | |
pip --version | |
- name: Install Poetry | |
run: | | |
pip install --constraint=.github/workflows/constraints.txt poetry | |
poetry --version | |
# Docker build/push job ---------------------- | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Update the project version number to the dev version that was | |
# generated upstream (only used in non-release builds; else project | |
# already set to the correct version number) | |
- name: Use dev project version for testing | |
id: use-dev-version-for-testing | |
if: "needs.get-tag-xor-dev-version.outputs.dev-version" | |
run: | | |
VERSION=${{ needs.get-tag-xor-dev-version.outputs.dev-version }} | |
poetry version "${VERSION}" | |
- name: Get container image metadata | |
id: container-image-metadata | |
run: | | |
CI_TAGGED_IMG=$(echo -n $(make get-docker-img-strong-version-tag get-project-version-number) | tr ' ' '-') | |
CANONICAL_TAGGED_IMGS=$(echo -n $(make get-docker-img-strong-version-tag get-docker-img-latest-tag) | tr ' ' ',') | |
echo "tagged_images=${CI_TAGGED_IMG},${CANONICAL_TAGGED_IMGS}" >> $GITHUB_OUTPUT | |
- name: Build and push container image | |
id: docker_build | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
tags: ${{ steps.container-image-metadata.outputs.tagged_images }} | |
- name: Log image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
# Release notes publication ---------------------- | |
publish-release-notes: | |
name: Publish release notes | |
runs-on: ubuntu-latest | |
needs: | |
- get-tag-xor-dev-version | |
- verify-user-install | |
- docker-image-build-and-upload | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v3.0.2 | |
- name: Publish the release notes | |
uses: release-drafter/release-drafter@v5.21.0 | |
with: | |
publish: ${{ needs.get-tag-xor-dev-version.outputs.tag != '' }} | |
# Annotated tag to associate with the current commit | |
tag: ${{ needs.get-tag-xor-dev-version.outputs.tag }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |