-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (111 loc) · 3.99 KB
/
python-packages.yml
File metadata and controls
126 lines (111 loc) · 3.99 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Python Packages (test + publish)
on:
push:
branches: [master]
paths:
- 'packages/**'
- '.github/workflows/python-packages.yml'
pull_request:
branches: [master]
paths:
- 'packages/**'
release:
types: [published]
jobs:
# ─── Tests run on every push / PR / release for BOTH packages ─────────────
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.11', '3.12']
package:
- midas_stress
- midas_params
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install ${{ matrix.package }} (editable, with dev extras)
run: pip install -e "packages/${{ matrix.package }}[dev]"
- name: Run tests for ${{ matrix.package }}
run: |
cd packages/${{ matrix.package }}
python -m pytest tests/ -v --tb=short
# ─── Build + publish: triggered by GitHub release only ────────────────────
# The tag name selects which package to publish:
# midas-stress-v* → midas_stress
# midas-params-v* → midas_params
#
# Release tags without one of these prefixes are ignored (no-op build).
build:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'release'
outputs:
package: ${{ steps.which.outputs.package }}
pypi_name: ${{ steps.which.outputs.pypi_name }}
steps:
- uses: actions/checkout@v4
- id: which
name: Identify package from tag
run: |
TAG="${GITHUB_REF##*/}"
echo "Tag: $TAG"
if [[ "$TAG" == midas-stress-v* ]]; then
echo "package=midas_stress" >> "$GITHUB_OUTPUT"
echo "pypi_name=midas-stress" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" == midas-params-v* ]]; then
echo "package=midas_params" >> "$GITHUB_OUTPUT"
echo "pypi_name=midas-params" >> "$GITHUB_OUTPUT"
else
echo "Tag $TAG does not match any known package prefix; skipping."
echo "package=" >> "$GITHUB_OUTPUT"
echo "pypi_name=" >> "$GITHUB_OUTPUT"
fi
- name: Set up Python
if: steps.which.outputs.package != ''
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tools
if: steps.which.outputs.package != ''
run: pip install build
- name: Build sdist and wheel
if: steps.which.outputs.package != ''
run: |
cd packages/${{ steps.which.outputs.package }}
python -m build
- name: Upload artifacts
if: steps.which.outputs.package != ''
uses: actions/upload-artifact@v4
with:
name: ${{ steps.which.outputs.pypi_name }}-dist
path: packages/${{ steps.which.outputs.package }}/dist/
publish:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release' && needs.build.outputs.package != ''
environment: pypi
permissions:
id-token: write # for trusted publishing (OIDC)
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.pypi_name }}-dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Uses trusted publishing (OIDC). One-time setup per package at pypi.org:
# Settings > Publishing > Add a new pending publisher
# Owner: marinerhemant
# Repo: MIDAS
# Workflow: python-packages.yml
# Environment: pypi
# The same GitHub environment (pypi) is shared across packages;
# the PyPI side identifies which project to publish to by the
# PyPI project name baked into the uploaded dist/*.