Skip to content

Commit e796a48

Browse files
blink1073alcaeus
andauthored
Add bump-version and tag-version scripts (#32)
Co-authored-by: Andreas Braun <git@alcaeus.org>
1 parent 1e0af6f commit e796a48

File tree

6 files changed

+170
-65
lines changed

6 files changed

+170
-65
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ The action requires `id-token: write` permissions.
5151

5252
## Signing tools
5353

54-
The actions in the `garasign` folder are used to sign artifacts using the team's
55-
GPG key.
54+
These actions are used to sign artifacts using the team's GPG key.
5655

5756
### git-sign
5857

@@ -75,6 +74,34 @@ Use this action to create signed git artifacts:
7574
command: "git tag -m 'Tag' -s --local-user=${{ env.GPG_KEY_ID }} -a <tag>"
7675
```
7776

77+
### bump-version
78+
79+
This is a convenience action to bump the version, create a signed commit, and
80+
push the commit unless `push_commit` is disabled. You can override the commit message
81+
format if desired. The version bump script should accept a new version as
82+
an argument and update the version accordingly.
83+
84+
```yaml
85+
- name: Bump version
86+
uses: mongodb-labs/drivers-github-tools/bump-version@v2
87+
with:
88+
version: ${{ inputs.version }}
89+
version_bump_script: "bash ./my-bump-version-script.sh"
90+
```
91+
92+
### tag-version
93+
94+
This is a convenience action to create a signed tag, optionally verify the tag,
95+
and push the tag unless `push_tag` is disabled. You can override the tag format and the
96+
tag message format if desired.
97+
98+
```yaml
99+
- name: Tag version
100+
uses: mongodb-labs/drivers-github-tools/tag-version@v2
101+
with:
102+
version: ${{ inputs.version }}
103+
```
104+
78105
### gpg-sign
79106

80107
This action is used to create detached signatures for files:

bump-version/action.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Bump Version
2+
description: Bump the version and push if not a dry-run
3+
inputs:
4+
version:
5+
description: The new version
6+
required: true
7+
version_bump_script:
8+
description: The version bump script
9+
required: true
10+
commit_template:
11+
description: The template for the git commit message
12+
default: "BUMP ${VERSION}"
13+
push_commit:
14+
description: Whether to push the commit
15+
default: "true"
16+
artifactory_image:
17+
description: "Image to use for artifactory"
18+
default: release-tools-container-registry-local/garasign-git
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Set new version
24+
shell: bash -eux {0}
25+
run: |
26+
${{ inputs.version_bump_script }} ${{ inputs.version }}
27+
- name: Get the commit message
28+
shell: bash -eux {0}
29+
run: |
30+
export VERSION=${{inputs.version}}
31+
export COMMIT_MESSAGE=$(echo "${{inputs.commit_template}}" | envsubst)
32+
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
33+
- name: Commit the version bump
34+
uses: mongodb-labs/drivers-github-tools/git-sign@v2
35+
with:
36+
command: git commit -a -m \"${{env.COMMIT_MESSAGE}}\" -s --gpg-sign=${{ env.GPG_KEY_ID }}
37+
artifactory_image: ${{inputs.artifactory_image}}
38+
- name: Push the commit to the source branch
39+
shell: bash -eux {0}
40+
run: |
41+
if [ ${{ inputs.push_commit }} == "true" ]; then
42+
git push origin
43+
echo "### Pushed version bump: ${{inputs.version}}" >> $GITHUB_STEP_SUMMARY
44+
else
45+
echo "### Created version bump (no push): ${{inputs.version}}" >> $GITHUB_STEP_SUMMARY
46+
fi

python/bump-and-tag/action.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

python/pre-release/action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Python Pre-Release
2+
description: Perform pre-release operations for Python Libraries
3+
inputs:
4+
version:
5+
description: The published version
6+
required: true
7+
version_bump_script:
8+
description: The version bump script
9+
required: true
10+
dry_run:
11+
description: Whether this is a dry run
12+
required: true
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.11'
20+
- name: Set version
21+
uses: blink1073/drivers-github-tools/bump-version@bump-version
22+
with:
23+
version: ${{ inputs.version }}
24+
version_bump_script: ${{ inputs.version_bump_script }}
25+
dry_run: ${{ inputs.dry_run }}
26+
- name: Tag version
27+
uses: blink1073/drivers-github-tools/tag-version@bump-version
28+
with:
29+
version: ${{ inputs.version }}
30+
dry_run: ${{ inputs.dry_run }}

python/publish/action.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,14 @@ runs:
6868
- name: Publish distribution 📦 to PyPI
6969
if: inputs.dry_run == 'false'
7070
uses: pypa/gh-action-pypi-publish@release/v1
71-
- name: Set following version
71+
- name: Ensure a clean repo
7272
shell: bash -eux {0}
7373
run: |
7474
git clean -dffx
75-
bash ${{ inputs.version_bump_script }} ${{ inputs.version }}
76-
- name: Commit the version bump
77-
uses: mongodb-labs/drivers-github-tools/git-sign@v2
75+
git pull origin ${{ github.ref }}
76+
- name: Set following version
77+
uses: blink1073/drivers-github-tools/bump-version@bump-version
7878
with:
79-
command: git commit -a -m \"BUMP ${{ inputs.following_version }}\" -s --gpg-sign=${{ env.GPG_KEY_ID }}
80-
- name: Push the commit to the source branch
81-
shell: bash -eux {0}
82-
run: |
83-
if [ ${{ inputs.dry_run }} != "true" ]; then
84-
git push origin --tags
85-
else
86-
echo "Not pushing the following_version tag since it is a dry run"
87-
fi
79+
version: ${{ inputs.following_version }}
80+
version_bump_script: ${{ inputs.version_bump_script }}
81+
dry_run: ${{ inputs.dry_run }}

tag-version/action.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Bump Version
2+
description: Bump the version and push if not a dry-run
3+
inputs:
4+
version:
5+
description: The new version
6+
required: true
7+
tag_template:
8+
description: The template for the git tag
9+
default: "${VERSION}"
10+
tag_message_template:
11+
description: The template for the git tag message
12+
default: "BUMP ${VERSION}"
13+
push_tag:
14+
description: Whether to push the tag
15+
default: "true"
16+
artifactory_image:
17+
description: "Image to use for artifactory"
18+
default: release-tools-container-registry-local/garasign-git
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Get the tag
24+
shell: bash -eux {0}
25+
run: |
26+
export VERSION=${{inputs.version}}
27+
export TAG=$(echo "${{inputs.tag_template}}" | envsubst)
28+
echo "TAG=$TAG" >> $GITHUB_ENV
29+
- name: Get the tag message
30+
shell: bash -eux {0}
31+
run: |
32+
export VERSION=${{inputs.version}}
33+
export TAG_MESSAGE=$(echo "${{inputs.tag_message_template}}" | envsubst)
34+
echo "TAG_MESSAGE=$TAG_MESSAGE" >> $GITHUB_ENV
35+
- name: Tag the version
36+
uses: mongodb-labs/drivers-github-tools/git-sign@v2
37+
with:
38+
command: git tag -a \"${{ env.TAG }}\" -m \"${{ env.TAG_MESSAGE }}\" -s --local-user=${{ env.GPG_KEY_ID }}
39+
artifactory_image: ${{ inputs.artifactory_image }}
40+
- name: Verify the tag
41+
shell: bash -eux {0}
42+
run: |
43+
if [ -n "$GPG_PUBLIC_URL" ]; then
44+
curl $GPG_PUBLIC_URL --output /tmp/signature.pub
45+
gpg --import /tmp/signature.pub
46+
git verify-tag $TAG
47+
else
48+
echo "Skipping tag verification"
49+
fi
50+
- name: Push the tag to the source branch
51+
shell: bash -eux {0}
52+
run: |
53+
if [ ${{ inputs.push_tag }} == "true" ]; then
54+
git push origin --tags
55+
echo "### Pushed tag: ${{inputs.version}}" >> $GITHUB_STEP_SUMMARY
56+
else
57+
echo "### Created tag (no push): ${{inputs.version}}" >> $GITHUB_STEP_SUMMARY
58+
fi

0 commit comments

Comments
 (0)