Repository navigation
160 lines (137 loc) · 5.8 KB
/
Copy pathalpha-release.yml
File metadata and controls
160 lines (137 loc) · 5.8 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Alpha release
# Publishes develop as it is, as a pre-release, so Python users can run pip install --pre bhom-schema and get what is on develop. It does not
# regenerate and needs no C# build: develop is regenerated by python-schema-generation.yml and takes pull requests in between. The version is
# the BHoM version with the UTC time (X.Y.0aYYMMDDHHmm); it is stamped in this checkout only, never committed. A run is skipped when develop has not
# moved since the last alpha. Fails when develop still reports a BHoM version that is already released: bump it first.
on:
schedule:
- cron: '0 6 * * *' # every day, after the Saturday generation (4 AM) has pushed
workflow_dispatch:
inputs:
dry_run:
description: Check and build the wheel, but do not publish
type: boolean
default: true
force:
description: Publish even when develop has not changed since the last alpha
type: boolean
default: false
# The generation and the release write to develop and its tags, so none of them runs while another does
concurrency:
group: develop-publishing
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
outputs:
publish: ${{ steps.gate.outputs.publish }}
version: ${{ steps.stamp.outputs.version }}
sha: ${{ steps.gate.outputs.sha }}
env:
PYTHONPATH: ${{ github.workspace }}/.ci/generation
steps:
- name: Checkout develop
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
# alpha-latest is the commit of the last published alpha
- name: Has develop moved since the last alpha?
id: gate
shell: bash
run: |
sha=$(git rev-parse HEAD)
last=$(git ls-remote --tags origin alpha-latest | cut -f1)
echo "sha=$sha" >> "$GITHUB_OUTPUT"
if [ "$last" = "$sha" ] && [ "${{ inputs.force }}" != "true" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "develop ($sha) is already published as the last alpha: nothing to do." | tee -a "$GITHUB_STEP_SUMMARY"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-python@v5
if: steps.gate.outputs.publish == 'true'
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml
- name: Install the Python tools
if: steps.gate.outputs.publish == 'true'
run: python -m pip install -e ".[dev]" build
# Fails when the BHoM version of develop is already released (tag vX.Y.0); the stamp is written into this checkout only
- name: Stamp the alpha version
id: stamp
if: steps.gate.outputs.publish == 'true'
shell: bash
run: |
tags=$(git tag --list "v*.0")
version=$(python -m py2cs alpha-version --package src/bhom_schema --tags $tags --stamp)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Alpha version: $version" | tee -a "$GITHUB_STEP_SUMMARY"
- name: Every module imports
if: steps.gate.outputs.publish == 'true'
run: python -m py2cs verify --package src/bhom_schema
- uses: actions/setup-dotnet@v4
if: steps.gate.outputs.publish == 'true'
with:
dotnet-version: '8.0.x'
# The py2cs tests that plan changes to C# files run the Roslyn patcher (CI=true makes them fail, not skip, when it is missing). It needs no BHoM assemblies.
- name: Build the C# patcher
if: steps.gate.outputs.publish == 'true'
run: dotnet build .ci/generation/PythonSchemaGeneration.Patcher/PythonSchemaGeneration.Patcher.csproj -c Release --nologo
- name: Tests that need no BHoM assemblies
if: steps.gate.outputs.publish == 'true'
run: python -m pytest .ci/unit-tests/python/test_py2cs .ci/unit-tests/python/test_support -q
- name: Pyright
if: steps.gate.outputs.publish == 'true'
run: python -m pyright
- name: Build the wheel
if: steps.gate.outputs.publish == 'true'
shell: bash
run: |
python -m build --wheel --outdir dist
ls dist
ls dist | grep -F "${{ steps.stamp.outputs.version }}" || { echo "The wheel does not carry the version ${{ steps.stamp.outputs.version }}"; exit 1; }
- uses: actions/upload-artifact@v4
if: steps.gate.outputs.publish == 'true'
with:
name: alpha
path: dist
# Trusted publishing: TestPyPI trusts this workflow and environment, so there is no token or password to store
publish-testpypi:
needs: build
if: ${{ needs.build.outputs.publish == 'true' && !inputs.dry_run }}
runs-on: ubuntu-latest
environment: testpypi-alpha
permissions:
id-token: write
steps:
- name: Download the wheel
uses: actions/download-artifact@v4
with:
name: alpha
path: dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
# Records the commit that was published, so the next run can tell whether develop has moved
mark:
needs: [build, publish-testpypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.build.outputs.sha }}
- name: Move the tag alpha-latest
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -f alpha-latest
git push --force origin alpha-latest
echo "alpha-latest now points at ${{ needs.build.outputs.sha }} (${{ needs.build.outputs.version }})" >> "$GITHUB_STEP_SUMMARY"