-
-
Notifications
You must be signed in to change notification settings - Fork 3
100 lines (86 loc) · 3.07 KB
/
publish.yaml
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
# Ultralytics HUB-SDK 🚀, AGPL-3.0 License
# Publish pip package to PyPI https://pypi.org/project/hub-sdk/ or Test PyPI https://test.pypi.org/project/hub-sdk/
name: Publish
on:
workflow_dispatch:
inputs:
production:
type: boolean
description: Publish to PyPI (TRUE) or Test PyPI (FALSE)
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Increment Version
id: versioning
run: |
# Extract the version
VERSION=$(grep -oP '__version__\s*=\s*"\K[0-9.]+(?:-rc\.[0-9]+)?"' hub_sdk/__init__.py | tr -d '"')
# Split the version into parts
IFS='.-' read -ra VER <<< "$VERSION"
MAJOR=${VER[0]}
MINOR=${VER[1]}
PATCH=${VER[2]}
RC=${VER[4]}
if ${{ github.event.inputs.production }}; then
# Increment patch or remove RC version
if [[ "$RC" ]]; then
# Remove RC version
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
else
# Increment patch
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
fi
else
# Increment patch or RC version
if [[ "$RC" ]]; then
# Increment RC version
RC=$((RC + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH-rc.$RC"
else
# Increment patch and add -rc.0
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH-rc.0"
fi
fi
# Update the version
sed -i "s/__version__ = \".*\"/__version__ = \"$NEW_VERSION\"/" hub_sdk/__init__.py
# Set the new version as an output variable
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Commit Release Changes
run: |
NEW_VERSION=${{ steps.versioning.outputs.NEW_VERSION }}
git add .
git commit -m "chore(release): $NEW_VERSION"
git push
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip" # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel build twine
- name: Publish to PyPI
if: ${{ github.event.inputs.production }}
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
python -m build
python -m twine upload dist/* -u __token__ -p $PYPI_TOKEN
- name: Publish to Test PyPI
if: ${{ !github.event.inputs.production }}
env:
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}
run: |
python -m build
python -m twine upload --repository testpypi dist/* -u __token__ -p $TEST_PYPI_TOKEN