-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (96 loc) · 3.33 KB
/
_reusable-package-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
name: Package Build
on:
workflow_call:
inputs:
package-name:
description: The name of the package to build, install, and import (this must
be the package's importable name).
required: true
type: string
python-versions-array:
description: A valid JSON array of Python versions to validate the package
can be installed with.
required: true
type: string
operating-systems-array:
description: A valid JSON array of operating system names to validate the
package can be installed on.
required: false
default: '["ubuntu", "windows", "macos"]'
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }} (Reusable)
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
PACKAGE_NAME: ${{ inputs.package-name }}
jobs:
# Verify the package can be built
build-package:
name: Build package
runs-on: ubuntu-latest
environment: package-build
permissions:
id-token: write
attestations: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@f01e4d047aadcc0c054c95ec9900da3ec3fc7a0f # v2.10.0
id: build-pkg
with:
attest-build-provenance-github: ${{ !github.event.pull_request.head.repo.fork && !contains(fromJSON('["dependabot[bot]", "renovate[bot]"]'), github.actor) }}
# Verify the package can be installed
install-package:
name: Install package
needs: build-package
runs-on: ${{ matrix.os-name }}-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os-name: ${{ fromJSON(inputs.operating-systems-array) }}
python-version: ${{ fromJSON(inputs.python-versions-array) }}
steps:
- name: Download built packages
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: Packages
path: dist
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Test installing wheel
shell: bash
run: pip install dist/*.whl
- name: Test importing ${{ env.PACKAGE_NAME }}
run: python -c "import ${{ env.PACKAGE_NAME }}"
- name: Uninstall wheel
shell: bash
run: |
pip uninstall -y ${{ env.PACKAGE_NAME }}
pip freeze | xargs pip uninstall -y
- name: Test installing tarball
shell: bash
run: pip install dist/*.tar.gz
- name: Test importing ${{ env.PACKAGE_NAME }}
run: python -c "import ${{ env.PACKAGE_NAME }}"
- name: Uninstall tarball
shell: bash
run: |
pip uninstall -y ${{ env.PACKAGE_NAME }}
pip freeze | xargs pip uninstall -y
# Check that all jobs passed
check-build-and-install-passed:
if: ${{ !cancelled() }}
needs: [build-package, install-package]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
jobs: ${{ toJSON(needs) }}