-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (87 loc) · 3.78 KB
/
poll.yml
File metadata and controls
105 lines (87 loc) · 3.78 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
name: Poll for New Versions
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
poll:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Get latest version from PyPI
id: pypi
run: |
VERSION=$(curl -sf https://pypi.org/pypi/chromadb/json | python3 -c 'import json,sys; print(json.load(sys.stdin)["info"]["version"])')
echo "Raw version: $VERSION"
if [[ "$VERSION" =~ (a|b|rc|alpha|beta) ]]; then
echo "Version $VERSION is a pre-release, skipping"
echo "version=none" >> $GITHUB_OUTPUT
exit 0
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "PyPI latest stable: $VERSION"
- name: Get existing releases from GitHub
id: github
run: |
TAGS=$(curl -s -H "Authorization: Bearer ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/releases" | \
python3 -c "import sys, json; releases = json.load(sys.stdin); print(' '.join([r['tag_name'] for r in releases]))" || echo "")
echo "existing=$TAGS" >> $GITHUB_OUTPUT
echo "Existing releases: $TAGS"
- name: Check if release needed
id: check
run: |
PYPI_VERSION="${{ steps.pypi.outputs.version }}"
EXISTING="${{ steps.github.outputs.existing }}"
if [ "$PYPI_VERSION" = "none" ]; then
echo "status=skip" >> $GITHUB_OUTPUT
echo "Latest version is pre-release, skipping"
exit 0
fi
for tag in $EXISTING; do
if [ "$tag" = "$PYPI_VERSION" ]; then
echo "status=already_released" >> $GITHUB_OUTPUT
echo "Version $PYPI_VERSION already exists"
exit 0
fi
if [ "$tag" = "v$PYPI_VERSION" ]; then
echo "status=already_released" >> $GITHUB_OUTPUT
echo "Version $PYPI_VERSION already exists (with v prefix)"
exit 0
fi
done
echo "status=needs_release" >> $GITHUB_OUTPUT
echo "Version $PYPI_VERSION needs a release"
- name: Checkout code
uses: actions/checkout@v5
with:
ref: main
fetch-depth: 1
if: steps.check.outputs.status == 'needs_release'
- name: Create release branch
if: steps.check.outputs.status == 'needs_release'
run: |
PYPI_VERSION="${{ steps.pypi.outputs.version }}"
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git checkout -b "release/$PYPI_VERSION" origin/main
echo "$PYPI_VERSION" > VERSION
git add VERSION
git commit -m "Version $PYPI_VERSION"
git push origin "release/$PYPI_VERSION" --force
echo "Branch pushed, triggering build..."
- name: Trigger build workflow
if: steps.check.outputs.status == 'needs_release'
env:
PAT: ${{ secrets.PAT }}
run: |
PYPI_VERSION="${{ steps.pypi.outputs.version }}"
WORKFLOW_ID=$(curl -s -H "Authorization: Bearer $PAT" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows" | \
python3 -c "import sys, json; workflows = json.load(sys.stdin)['workflows']; print([w['id'] for w in workflows if w['name'] == 'Build and Release'][0])")
curl -X POST -H "Authorization: Bearer $PAT" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/dispatches" \
-d '{"ref":"release/'$PYPI_VERSION'"}'