-
-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (143 loc) · 7.06 KB
/
dev-release.yml
File metadata and controls
160 lines (143 loc) · 7.06 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: Dev Release
on:
push:
branches: [develop]
workflow_dispatch:
permissions:
contents: write # needed to create/update the rolling 'latest' GitHub pre-release
jobs:
test:
runs-on: ubuntu-latest
# Only run from the develop branch — blocks accidental workflow_dispatch from main.
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- run: pip install -e ".[dev]"
- run: ruff check src/ tests/
- run: ruff format --check src/ tests/
- run: mypy src/specsmith --ignore-missing-imports
- run: pytest tests/ -x -q
build-and-publish:
needs: test
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: write # write required to create/update the dev GitHub pre-release
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- name: Install build tools
run: pip install build
- name: Set dev version
run: |
# Use pyproject.toml version as the base (no patch bump).
# pyproject.toml should always hold the NEXT release version (e.g. 0.3.0).
# Dev builds publish as 0.3.0.devN — PEP 440 pre-release of the upcoming release.
# N = total commit count (monotonically increasing, unique per push).
BASE_VERSION=$(grep 'version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
COMMIT_COUNT=$(git rev-list --count HEAD)
DEV_VERSION="${BASE_VERSION}.dev${COMMIT_COUNT}"
echo "DEV_VERSION=${DEV_VERSION}" >> $GITHUB_ENV
# Patch pyproject.toml with dev version
sed -i "s/version = \"${BASE_VERSION}\"/version = \"${DEV_VERSION}\"/" pyproject.toml
echo "Building version: ${DEV_VERSION}"
- name: Strip git-URL deps before PyPI build
run: |
# PyPI rejects packages with direct git:// / git+https:// dependencies.
# chronomemory is not yet on PyPI; remove the line so the wheel uploads cleanly.
# TODO: replace with chronomemory>=0.1.0 once chronomemory is published to PyPI.
sed -i '/chronomemory @ git+/d' pyproject.toml
echo "pyproject.toml after stripping git deps:"
grep -A2 'dependencies' pyproject.toml | head -20
- run: python -m build
- name: Publish dev release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true # gracefully skip if this exact version is already on PyPI
# Create/update a rolling GitHub pre-release so users can track dev builds.
# NOTE: when the first official stable release ships, remove this step and
# instead rely on release.yml with --latest to make stable the default.
- name: Create/update rolling dev GitHub pre-release
env:
GH_TOKEN: ${{ github.token }}
run: |
# Delete any existing 'latest-dev' tag+release so we can overwrite it.
gh release delete latest-dev --repo ${{ github.repository }} \
--yes --cleanup-tag 2>/dev/null || true
# Also remove any stale local tag (actions/checkout may have fetched it)
git tag -d latest-dev 2>/dev/null || true
gh release create latest-dev dist/* \
--title "Latest dev build (${DEV_VERSION})" \
--notes "Rolling dev pre-release built from the develop branch." \
--prerelease \
--target "${{ github.sha }}"
# --prerelease already prevents GitHub from marking this as the default
# 'latest' release — no extra flag needed.
docs-build:
needs: build-and-publish
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Trigger ReadTheDocs builds (develop + latest)
env:
RTD_TOKEN: ${{ secrets.RTD_TOKEN }}
run: |
if [ -z "$RTD_TOKEN" ]; then
echo "WARNING: RTD_TOKEN secret is not set. Skipping RTD build trigger."
echo "To fix: go to GitHub repo Settings → Secrets → Actions and add RTD_TOKEN."
echo "Get the token from: https://readthedocs.org/accounts/tokens/"
exit 0
fi
# Trigger the 'develop' RTD version build (accessible at /en/develop/)
echo "Triggering RTD build for 'develop' version..."
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "Authorization: Token $RTD_TOKEN" \
"https://readthedocs.org/api/v3/projects/specsmith/versions/develop/builds/")
echo "RTD develop build trigger: HTTP $STATUS"
if [ "$STATUS" != "202" ]; then
echo "WARNING: RTD develop build trigger returned HTTP $STATUS (expected 202)."
echo "Common causes:"
echo " - 401: RTD_TOKEN is invalid or expired"
echo " - 404: 'develop' version not activated in RTD dashboard"
echo " Fix: https://readthedocs.org/projects/specsmith/versions/ → activate 'develop'"
fi
# Step 1: Set RTD project default_branch to 'develop'
echo "[1/3] Setting RTD project default_branch to 'develop'..."
PATCH_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH \
-H "Authorization: Token $RTD_TOKEN" \
-H "Content-Type: application/json" \
-d '{"default_branch": "develop"}' \
"https://readthedocs.org/api/v3/projects/specsmith/")
echo "RTD project PATCH: HTTP $PATCH_STATUS"
# Step 2: Set the 'latest' VERSION object's identifier to 'develop'
# This is the key step — the version object has its own branch setting
# separate from the project-level default_branch.
echo "[2/3] Setting RTD 'latest' version identifier to 'develop'..."
VER_PATCH=$(curl -s -o /tmp/ver_patch.txt -w "%{http_code}" -X PATCH \
-H "Authorization: Token $RTD_TOKEN" \
-H "Content-Type: application/json" \
-d '{"identifier": "develop", "active": true}' \
"https://readthedocs.org/api/v3/projects/specsmith/versions/latest/")
echo "RTD 'latest' version PATCH: HTTP $VER_PATCH"
cat /tmp/ver_patch.txt | head -c 200 || true
# Step 3: Trigger a fresh /en/latest/ build (now tracks develop)
echo "[3/3] Triggering RTD 'latest' build from develop..."
LATEST_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "Authorization: Token $RTD_TOKEN" \
"https://readthedocs.org/api/v3/projects/specsmith/versions/latest/builds/")
echo "RTD latest build trigger: HTTP $LATEST_STATUS"
if [ "$LATEST_STATUS" != "202" ]; then
echo "WARNING: RTD latest trigger returned HTTP $LATEST_STATUS"
echo "If 404: 'latest' version may not be active in RTD dashboard."
echo "Fix: https://readthedocs.org/projects/specsmith/versions/ -> activate 'latest'"
fi