Skip to content

Commit e13677a

Browse files
committed
Add bump mechanism again
1 parent 66f64ff commit e13677a

File tree

4 files changed

+122
-34
lines changed

4 files changed

+122
-34
lines changed

.github/workflows/bump.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import pathlib
5+
import sys
6+
7+
import tomlkit
8+
9+
root = pathlib.Path(__file__).parent.parent.parent
10+
11+
12+
def main():
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("package")
15+
parser.add_argument("package_version")
16+
parser.add_argument("repo_version")
17+
args = parser.parse_args()
18+
19+
# Package version year must match repo version year, otherwise we can end
20+
# up with users trying to install the prior year's packages and they
21+
# install a mess instead
22+
if args.repo_version.split(".")[0] != args.package_version.split(".")[0]:
23+
print("!! Package version year does not match repo version year!")
24+
return 1
25+
26+
with open(root / "pyproject.toml") as fp:
27+
data = tomlkit.load(fp)
28+
29+
pkg = data["tool"]["meta"]["packages"][args.package]
30+
if "version" in pkg:
31+
pkg["version"] = f"=={args.package_version}"
32+
elif "min_version" in pkg:
33+
pkg["min_version"] = args.package_version
34+
else:
35+
raise ValueError("unknown format")
36+
37+
with open(root / "pyproject.toml", "w") as fp:
38+
tomlkit.dump(data, fp)
39+
40+
return 0
41+
42+
43+
if __name__ == "__main__":
44+
sys.exit(main())

.github/workflows/bump.yml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,36 @@ jobs:
1111
- name: Information
1212
run: |
1313
echo "Version update for ${{ github.event.client_payload.package_name }} -> ${{ github.event.client_payload.package_version }} requested"
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
with:
1616
token: ${{ secrets.REPO_ACCESS_TOKEN }}
1717
fetch-depth: 0
18-
- uses: actions/setup-python@v2
18+
- uses: actions/setup-python@v4
1919
with:
2020
python-version: 3.8
2121

22-
# To prevent lots of spurious pypi package pushes during upgrades, you can
23-
# commit a file 'pause_until'. This will only push a new tag once that
24-
# package has been reached
25-
# - name: Check if paused
26-
# id: check-paused
27-
# shell: bash
28-
# run: |
29-
# if [ ! -f pause_until ]; then
30-
# echo "::set-output name=paused::no"
31-
# elif [ "$(cat pause_until)" == "${{ github.event.client_payload.package_name }}" ]; then
32-
# rm pause_until
33-
# git config --local user.email "[email protected]"
34-
# git config --local user.name "Github Action"
35-
# git commit -m "Remove paused marker" pause_until
36-
# git push
37-
# echo "::set-output name=paused::no"
38-
# else
39-
# echo "::set-output name=paused::yes"
40-
# fi
22+
- name: Install script requirements
23+
shell: bash
24+
run: |
25+
python -m pip --disable-pip-version-check install packaging tomlkit
4126
42-
- name: Bump Requirements
43-
uses: robotpy/build-actions/bump-requirements@v2022
44-
with:
45-
pkgname: ${{ github.event.client_payload.package_name }}
46-
pkgver: ${{ github.event.client_payload.package_version }}
27+
- name: Bump requirements
28+
shell: bash
29+
run: |
30+
python .github/workflows/bump.py ${{ github.event.client_payload.package_name }} ${{ github.event.client_payload.package_version }} "$(git describe --tags)"
4731
48-
# - name: Bump Version and push Tag
49-
# uses: anothrNick/[email protected]
50-
# # if: steps.check-paused.paused == 'no'
51-
# env:
52-
# GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
53-
# DEFAULT_BUMP: patch
54-
# WITH_V: false
32+
- name: Commit and push
33+
shell: bash
34+
run: |
35+
git config --local user.email "[email protected]"
36+
git config --local user.name "Github Action"
37+
git add pyproject.toml
38+
git commit -m "Bump '${{ github.event.client_payload.package_name }}' dependency to '${{ github.event.client_payload.package_version }}'"
39+
git push
40+
41+
- name: Tag and push
42+
shell: bash
43+
run: |
44+
TAG=$(python .github/workflows/tag.py ${{ github.event.client_payload.package_name }} ${{ github.event.client_payload.package_version }} "$(git describe --tags --no-abbrev)")
45+
git tag ${TAG}
46+
git push origin ${TAG}

.github/workflows/dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@v1
27+
- uses: actions/checkout@v4
2828
- uses: actions/setup-python@v4
2929
with:
3030
python-version: 3.8

.github/workflows/tag.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import subprocess
5+
import sys
6+
import typing
7+
8+
from packaging.version import Version
9+
10+
11+
def main():
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument("package")
14+
parser.add_argument("package_version")
15+
parser.add_argument("repo_version")
16+
args = parser.parse_args()
17+
18+
package_version = Version(args.package_version)
19+
repo_version = Version(args.repo_version)
20+
21+
if args.package == "mostrobotpy" and (
22+
repo_version.major != package_version.major
23+
or repo_version.minor != package_version.minor
24+
or repo_version.micro != package_version.micro
25+
or repo_version.pre != package_version.pre
26+
):
27+
new_version = package_version
28+
else:
29+
# Only bump the super micro version unless its a beta
30+
if repo_version.pre:
31+
v = ".".join(map(str, repo_version.release))
32+
v = f"{v}{''.join(map(str, repo_version.pre))}"
33+
if repo_version.post:
34+
v = f"{v}.post{repo_version.post+1}"
35+
else:
36+
v = f"{v}.post1"
37+
new_version = Version(v)
38+
else:
39+
parts: list = list(repo_version.release)
40+
if len(parts) == 3:
41+
parts.append(1)
42+
else:
43+
parts[3] = int(parts[3]) + 1
44+
new_version = Version(".".join(map(str, parts)))
45+
46+
assert new_version > repo_version
47+
print(new_version)
48+
return 0
49+
50+
51+
if __name__ == "__main__":
52+
sys.exit(main())

0 commit comments

Comments
 (0)