Skip to content

Commit e4340c0

Browse files
committed
feat: automatically update version tag in deploy.yml
1 parent d299b19 commit e4340c0

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

.github/workflows/_deploy.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ on:
44
workflow_dispatch:
55
inputs:
66
version-tag:
7-
description: Version tag
7+
description: 'Version tag'
88
required: true
9-
default: v0.1.5
9+
default: v0.1.8
1010
dry-run:
1111
description: Dry run
1212
type: boolean
1313
default: false
1414

15+
#### aaaaaaa
1516
jobs:
1617
commit-changelog-and-release:
1718
uses: ./.github/workflows/commit-changelog-and-release.yml
1819
with:
1920
version-tag: ${{ github.event.inputs.version-tag }}
21+
#### aaaaaaa
2022
dry-run: ${{ github.event.inputs.dry-run == 'true' }}
2123
changelog-path: docs/CHANGELOG.md
2224
exclude-types: build,docs,style,other
25+
deploy-yml-path: .github/workflows/_deploy.yml
2326

2427
publish-to-pypi:
2528
if: ${{ github.event.inputs.dry-run == 'false' }}
@@ -38,5 +41,5 @@ jobs:
3841
- name: Build and upload to PyPI
3942
run: |
4043
cd python-projector
41-
uv build --sdist
44+
uv build
4245
uv publish

.github/workflows/commit-changelog-and-release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# Example deploy.yml
2+
# on:
3+
# workflow_dispatch:
4+
# inputs:
5+
# version-tag:
6+
# description: Version tag
7+
# required: true
8+
# default: v0.1.8 # IMPORTANT to have this because we update this.
9+
# dry-run:
10+
# description: Dry run
11+
# type: boolean
12+
# default: false
13+
#
14+
# jobs:
15+
# commit-changelog-and-release:
16+
# uses: ./.github/workflows/commit-changelog-and-release.yml
17+
# with:
18+
# version-tag: ${{ github.event.inputs.version-tag }}
19+
# dry-run: ${{ github.event.inputs.dry-run == 'true' }}
20+
# changelog-path: docs/CHANGELOG.md
21+
# exclude-types: build,docs,style,other
22+
# deploy-yml-path: .github/workflows/deploy.yml
23+
124
name: Commit CHANGELOG.md and create a Release
225

326
on:
@@ -19,6 +42,10 @@ on:
1942
description: Comma-separated list of commit types to exclude from the changelog
2043
type: string
2144
default: build,docs,style,other
45+
deploy-yml-path:
46+
description: Path to the deploy.yml file to modify the next version. It should have on.workflow_call.inputs.version-tag
47+
type: string
48+
default: .github/workflows/deploy.yml
2249

2350
jobs:
2451
dry-run:
@@ -99,8 +126,16 @@ jobs:
99126
git push origin --delete ${{ inputs.version-tag }}
100127
fi
101128
129+
- name: Modify default next version in deploy.yml inputs
130+
run: |
131+
pip install ruamel.yaml
132+
python <(curl https://raw.githubusercontent.com/deargen/workflows/refs/heads/master/scripts/set_next_version_in_deploy_yml.py) \
133+
${{ inputs.deploy-yml-path }} \
134+
${{ inputs.version-tag }}
135+
102136
- name: Commit ${{ inputs.changelog-path }} and update tag
103137
run: |
138+
git add ${{ inputs.deploy-yml-path }}
104139
git add ${{ inputs.changelog-path }}
105140
git commit -m "docs: update ${{ inputs.changelog-path }} for ${{ inputs.version-tag }} [skip ci]"
106141
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Update the default version tag in the deploy.yml file.
3+
4+
```yaml
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version-tag:
9+
description: 'Version tag'
10+
required: true
11+
default: 'v0.1.0' # <-- HERE
12+
13+
# ...
14+
```
15+
"""
16+
17+
import sys
18+
from pathlib import Path
19+
20+
import ruamel.yaml
21+
22+
23+
def unidiff_output(expected: str, actual: str):
24+
"""Returns a string containing the unified diff of two multiline strings."""
25+
import difflib
26+
27+
expected_list = expected.splitlines(keepends=True)
28+
actual_list = actual.splitlines(keepends=True)
29+
30+
diff = difflib.unified_diff(expected_list, actual_list)
31+
32+
return "".join(diff)
33+
34+
35+
if len(sys.argv) != 3:
36+
print(
37+
"Usage: python increase_version_in_deploy_yml.py <deploy.yml> <current_version>"
38+
)
39+
print(
40+
"Example: python increase_version_in_deploy_yml.py .github/workflows/_deploy.yml v0.1.0"
41+
)
42+
print(
43+
"This script will set on.workflow_dispatch.inputs.version-tag.default to v0.1.1"
44+
)
45+
sys.exit(1)
46+
47+
deploy_yml = sys.argv[1]
48+
current_version = sys.argv[2]
49+
50+
split_version = current_version.split(".")
51+
last_digit = int(split_version[-1])
52+
split_version[-1] = str(last_digit + 1)
53+
new_version = ".".join(split_version)
54+
55+
yaml = ruamel.yaml.YAML()
56+
yaml.preserve_quotes = True
57+
yaml.indent(mapping=2, sequence=4, offset=2)
58+
original_yml_content = Path(deploy_yml).read_text()
59+
with open(deploy_yml) as f:
60+
data = yaml.load(f)
61+
data["on"]["workflow_dispatch"]["inputs"]["version-tag"]["default"] = new_version
62+
63+
with open(deploy_yml, "w") as f:
64+
yaml.dump(data, f)
65+
66+
new_yml_content = Path(deploy_yml).read_text()
67+
if original_yml_content == new_yml_content:
68+
print(f"Version was already set to {new_version}")
69+
else:
70+
print(unidiff_output(original_yml_content, new_yml_content))

0 commit comments

Comments
 (0)