-
Notifications
You must be signed in to change notification settings - Fork 674
104 lines (98 loc) · 3.99 KB
/
Copy pathrelease.yaml
File metadata and controls
104 lines (98 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
name: release
# Daily release train at 09:00 America/Los_Angeles. A day where nothing landed
# on main is a no-op: the release job sees HEAD already tagged and skips.
on:
schedule:
- cron: "0 16 * * *"
- cron: "0 17 * * *"
workflow_dispatch: {}
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
gate:
runs-on: ubuntu-latest
outputs:
run: ${{ steps.check.outputs.run }}
steps:
- id: check
run: |
if [ "${{ github.event_name }}" != "schedule" ]; then
echo "run=true" >> "$GITHUB_OUTPUT" # manual runs always proceed
elif [ "$(TZ=America/Los_Angeles date +%H)" = "09" ]; then
echo "run=true" >> "$GITHUB_OUTPUT" # 09:00 Pacific
else
echo "run=false" >> "$GITHUB_OUTPUT" # the other DST candidate; skip
fi
test:
needs: gate
if: needs.gate.outputs.run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[test,train]"
- run: pytest -q -m "not slow"
release:
needs: [gate, test]
if: needs.gate.outputs.run == 'true'
runs-on: ubuntu-latest
permissions:
contents: write # pushes the vX.Y.Z release tag
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install build twine
- id: version
run: |
last=$(git tag --list 'v*' --sort=-v:refname | head -1)
# New release tags include a metadata-only child commit. Its parent
# is the main commit that was tested and published.
source=""
if [ -n "$last" ]; then
source=$(git rev-parse "$last^{commit}")
if [ "$source" != "$(git rev-parse HEAD)" ] && [ "$(git log -1 --format=%s "$last")" = "chore: release ${last#v}" ]; then
source=$(git rev-parse "$last^")
fi
fi
if [ "$source" = "$(git rev-parse HEAD)" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# A manual bump on main or a publish whose tag step failed leaves
# PyPI ahead of the tags; the next version follows whichever is newer.
published=$(curl -sf https://pypi.org/pypi/cactus-needle/json | python3 -c 'import json,sys; print(json.loads(sys.stdin.read(), strict=False)["info"]["version"])' || true)
current=$(printf '%s\n%s\n' "${last#v}" "$published" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
echo "next=$(echo "$current" | awk -F. '{printf "%d.%d.%d", $1, $2, $3 + 1}')" >> "$GITHUB_OUTPUT"
- if: steps.version.outputs.skip != 'true'
run: |
next="${{ steps.version.outputs.next }}"
sed -i "s/^version = \".*\"/version = \"$next\"/" pyproject.toml
sed -i "s/^__version__ = \".*\"/__version__ = \"$next\"/" needle/__init__.py
- if: steps.version.outputs.skip != 'true'
run: python -m build
- if: steps.version.outputs.skip != 'true'
run: twine check dist/*
- if: steps.version.outputs.skip != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
- if: steps.version.outputs.skip != 'true'
run: |
# Preserve the exact versioned source used for the distribution.
# Keep the release-only commit on the tag, without writing to main.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add pyproject.toml needle/__init__.py
git diff --cached --quiet || git commit -m "chore: release ${{ steps.version.outputs.next }}"
git tag "v${{ steps.version.outputs.next }}"
git push origin "v${{ steps.version.outputs.next }}"