Skip to content

9.12.0

9.12.0 #35

Workflow file for this run

---
name: Test & Release
on:
push:
branches:
- master
- main
- "pre/*"
jobs:
eval-changes:
name: Evaluate changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50 # Must at least retrieve a set of commits to compare changes
# primarily because of any 'Rebase and Merge' PR action in GitHub
- name: Evaluate | Check specific file types for changes
id: changed-files
uses: tj-actions/changed-files@v45.0.2
with:
base_sha: ${{ github.event.push.before }}
files_yaml: |
build:
- MANIFEST.in
- Dockerfile
- .dockerignore
- scripts/**
ci:
- .github/workflows/main.yml
docs:
- docs/**
- README.rst
- AUTHORS.rst
- CONTRIBUTING.rst
- CHANGELOG.rst
src:
- semantic_release/**
- pyproject.toml
tests:
- tests/**
- name: Evaluate | Detect if any of the combinations of file sets have changed
id: all-changes
run: |
printf '%s\n' "any_changed=false" >> $GITHUB_OUTPUT
if [ "${{ steps.changed-files.outputs.build_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.ci_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.docs_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.src_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.tests_any_changed }}" == "true" ]; then
printf '%s\n' "any_changed=true" >> $GITHUB_OUTPUT
fi
outputs:
any-file-changes: ${{ steps.all-changes.outputs.any_changed }}
build-changes: ${{ steps.changed-files.outputs.build_any_changed }}
ci-changes: ${{ steps.changed-files.outputs.ci_any_changed }}
doc-changes: ${{ steps.changed-files.outputs.docs_any_changed }}
src-changes: ${{ steps.changed-files.outputs.src_any_changed }}
test-changes: ${{ steps.changed-files.outputs.tests_any_changed }}
test:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} tests
runs-on: ${{ matrix.os }}
needs: eval-changes
if: ${{ needs.eval-changes.outputs.src-changes == 'true' || needs.eval-changes.outputs.test-changes == 'true' || needs.eval-changes.outputs.ci-changes == 'true' }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[test]
python -m pip install pytest-github-actions-annotate-failures
- name: pytest on Linux
id: tests-linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python -m pytest \
-vv \
-nauto \
--cov=semantic_release \
--cov-context=test \
--cov-report=term-missing \
--cov-fail-under=80 \
--junit-xml=tests/reports/pytest-results.xml
- name: pytest on windows
id: tests-win
if: ${{ matrix.os == 'windows-latest' }}
# env:
# Required for GitPython to work on Windows because of getpass.getuser()
# USERNAME: "runneradmin"
# Because GHA is currently broken on Windows to pass these varables, we do it manually
run: |
$env:USERNAME = "runneradmin"
python -m pytest `
-vv `
-nauto `
`--cov=semantic_release `
`--cov-context=test `
`--cov-report=term-missing `
`--cov-fail-under=80 `
`--junit-xml=tests/reports/pytest-results.xml
- name: Report | Upload Linux Test Results
uses: mikepenz/action-junit-report@v4.3.1
if: ${{ always() && steps.tests-linux.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
- name: Report | Upload Windows Test Results
uses: mikepenz/action-junit-report@v4.3.1
if: ${{ always() && steps.tests-win.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
lint:
needs: eval-changes
if: ${{ needs.eval-changes.outputs.any-file-changes == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install mypy & dev packages
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev,mypy]
- name: Lint | Ruff Evaluation
id: lint
run: |
python -m ruff check \
--config pyproject.toml \
--output-format=full \
--exit-non-zero-on-fix
- name: Type-Check | MyPy Evaluation
id: type-check
if: ${{ always() && steps.lint.outcome != 'skipped' }}
run: |
python -m mypy --ignore-missing-imports semantic_release
- name: Format-Check | Ruff Evaluation
id: format-check
if: ${{ always() && steps.type-check.outcome != 'skipped' }}
run: |
python -m ruff format --check --config pyproject.toml
release:
name: Semantic Release
runs-on: ubuntu-latest
concurrency: push
needs: [test, lint]
if: github.repository == 'python-semantic-release/python-semantic-release'
environment:
name: pypi
url: https://pypi.org/project/python-semantic-release/
permissions:
# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps?apiVersion=2022-11-28#metadata
id-token: write
contents: write
env:
GITHUB_ACTIONS_AUTHOR_NAME: github-actions
GITHUB_ACTIONS_AUTHOR_EMAIL: actions@users.noreply.github.com
steps:
# Note: we need to checkout the repository at the workflow sha in case during the workflow
# the branch was updated. To keep PSR working with the configured release branches,
# we force a checkout of the desired release branch but at the workflow sha HEAD.
- name: Setup | Checkout Repository at workflow sha
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}
- name: Setup | Force correct release branch on workflow sha
run: |
git checkout -B ${{ github.ref_name }}
- name: Python Semantic Release
id: release
uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-vv"
- name: Update Minor Release Tag Reference
if: steps.release.outputs.released == 'true' && steps.release.outputs.is_prerelease == 'false'
env:
FULL_VERSION_TAG: ${{ steps.release.outputs.tag }}
GIT_COMMITTER_NAME: ${{ env.GITHUB_ACTIONS_AUTHOR_NAME }}
GIT_COMMITTER_EMAIL: ${{ env.GITHUB_ACTIONS_AUTHOR_EMAIL }}
run: |
MINOR_VERSION_TAG="$(echo "$FULL_VERSION_TAG" | cut -d. -f1,2)"
git tag --force --annotate "$MINOR_VERSION_TAG" "${FULL_VERSION_TAG}^{}" -m "$MINOR_VERSION_TAG"
git push -u origin "$MINOR_VERSION_TAG" --force
- name: Update Major Release Tag Reference
if: steps.release.outputs.released == 'true' && steps.release.outputs.is_prerelease == 'false'
env:
FULL_VERSION_TAG: ${{ steps.release.outputs.tag }}
GIT_COMMITTER_NAME: ${{ env.GITHUB_ACTIONS_AUTHOR_NAME }}
GIT_COMMITTER_EMAIL: ${{ env.GITHUB_ACTIONS_AUTHOR_EMAIL }}
run: |
MAJOR_VERSION_TAG="$(echo "$FULL_VERSION_TAG" | cut -d. -f1)"
git tag --force --annotate "$MAJOR_VERSION_TAG" "${FULL_VERSION_TAG}^{}" -m "$MAJOR_VERSION_TAG"
git push -u origin "$MAJOR_VERSION_TAG" --force
# see https://docs.pypi.org/trusted-publishers/
- name: Publish package distributions to PyPI
id: pypi-publish
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
- name: Publish package distributions to GitHub Releases
id: github-release
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: steps.release.outputs.released == 'true'
uses: python-semantic-release/publish-action@v9.9.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}