Skip to content

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7 #3779

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7

Merge branch 'main' into dependabot/docker/docker-deps-33463fdea7 #3779

name: Python package
on:
push:
branches:
- "**"
tags:
- "v*"
pull_request:
branches:
- "main"
permissions:
contents: read
jobs:
upload-event-file:
name: Upload event file
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
- name: Upload
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: event-file
path: ${{ github.event_path }}
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
strategy:
fail-fast: false
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.codecov.io:443
api.github.com:443
cli.codecov.io:443
codecov.io:443
files.pythonhosted.org:443
fulcio.sigstore.dev:443
get.anchore.io:443
github.com:443
ingest.codecov.io:443
keybase.io:443
o26192.ingest.us.sentry.io:443
objects.githubusercontent.com:443
pypi.org:443
raw.githubusercontent.com:443
registry.npmjs.org:443
rekor.sigstore.dev:443
release-assets.githubusercontent.com:443
storage.googleapis.com:443
uploader.codecov.io:443
uploads.github.com:443
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Make venv
run: make venv
- name: Lint
run: make lint
- name: Test
run: make test
- name: Upload test results
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: test-results-${{ matrix.python-version }}
path: test-results.xml
- name: Upload test results to Codecov
if: always()
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
with:
files: ./test-results.xml
flags: python-${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
files: ./coverage.xml
flags: python-${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build
run: make build
- name: Generate SBOM
if: ${{ matrix.python-version == '3.11' }}
uses: anchore/sbom-action@da167eac915b4e86f08b264dbdbc867b61be6f0c # v0.20.5
with:
format: spdx-json
artifact-name: sbom-python.spdx.json
output-file: sbom-python.spdx.json
- name: Generate SBOM attestation
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && matrix.python-version == '3.11' }}
uses: actions/attest-sbom@bd218ad0dbcb3e146bd073d1d9c6d78e08aa8a0b # v2.4.0
with:
subject-path: dist/*.whl
sbom-path: sbom-python.spdx.json
- name: Generate artifact attestation
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && matrix.python-version == '3.11' }}
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
with:
subject-path: dist/*.whl
- name: Generate hashes
id: hash
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && matrix.python-version == '3.11' }}
run: cd dist && echo "hashes=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
- name: Store the distribution packages
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && matrix.python-version == '3.11' }}
with:
name: python-package-distributions
path: dist/
provenance-and-draft-release:
name: Generate provenance and create draft release
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') }}
needs:
- build
- upload-event-file
permissions:
actions: read
id-token: write
contents: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ needs.build.outputs.hashes }}
upload-assets: true
draft-release: true
publish-to-test-pypi:
name: Publish to TestPyPI
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') }}
needs:
- provenance-and-draft-release
runs-on: ubuntu-latest
environment:
name: test-pypi
url: https://test.pypi.org/p/cf-ips-to-hcloud-fw
permissions:
id-token: write
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
fulcio.sigstore.dev:443
ghcr.io:443
pkg-containers.githubusercontent.com:443
rekor.sigstore.dev:443
test.pypi.org:443
tuf-repo-cdn.sigstore.dev:443
- name: Download all the distribution packages
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: python-package-distributions
path: dist
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
with:
repository-url: https://test.pypi.org/legacy/
publish-to-pypi:
name: Publish to PyPI
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') }}
needs:
- provenance-and-draft-release
- publish-to-test-pypi
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/cf-ips-to-hcloud-fw
permissions:
id-token: write
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
fulcio.sigstore.dev:443
ghcr.io:443
pkg-containers.githubusercontent.com:443
rekor.sigstore.dev:443
tuf-repo-cdn.sigstore.dev:443
upload.pypi.org:443
- name: Download all the distribution packages
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: python-package-distributions
path: dist
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
upload-dist-to-github-release:
name: Upload distribution packages to GitHub Release
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') }}
needs:
- publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Harden runner
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
uploads.github.com:443
- name: Download all the distribution packages
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: python-package-distributions
path: dist
- name: Upload distribution packages to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'