Skip to content

Commit

Permalink
automatically roll to next snapshot version
Browse files Browse the repository at this point in the history
  • Loading branch information
apastel committed May 11, 2024
1 parent f5df154 commit 8e894a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
pdm version ${{ inputs.revision }}
- name: Commit version files to main
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ${{ inputs.revision }}
- name: Create tag
uses: actions/github-script@v7
with:
Expand All @@ -44,3 +46,26 @@ jobs:
release-and-publish:
needs: create-tag
uses: ./.github/workflows/release.yml
secrets: inherit
roll-to-snapshot:
needs: release-and-publish
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
- name: Roll to next snapshot version
run: |
pdm version snapshot
- name: Commit version files to main
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Roll to next snapshot version
18 changes: 12 additions & 6 deletions bump_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# Validate argument
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <major|minor|patch|custom_version>"
echo "Usage: $0 <major|minor|patch|snapshot|custom_version>"
exit 1
fi

if [[ "$1" != "major" && "$1" != "minor" && "$1" != "patch" ]]; then
if [[ "$1" != "major" && "$1" != "minor" && "$1" != "patch" && "$1" != "snapshot" ]]; then
echo "Custom version supplied: '$1'"
fi

Expand All @@ -27,18 +27,21 @@ bump_version_py() {
minor=$(echo "$current_version" | cut -d. -f2)
patch=$(echo "$current_version" | cut -d. -f3)

if [[ "$version_part" != "major" && "$version_part" != "minor" && "$version_part" != "patch" ]]; then
if [[ "$version_part" != "major" && "$version_part" != "minor" && "$version_part" != "patch" && "$version_part" != "snapshot" ]]; then
new_version="$version_part"
else
# Bump the specified version part
case "$version_part" in
major) major=$((major + 1)); minor=0; patch=0;;
minor) minor=$((minor + 1)); patch=0;;
patch) patch=$((patch + 1));;
patch|snapshot) patch=$((patch + 1));;
esac

# Create new version string
new_version="${major}.${minor}.${patch}"
if [[ $version_part == "snapshot" ]]; then
new_version+="-SNAPSHOT"
fi
fi

# Replace old version with new version in the file
Expand All @@ -60,18 +63,21 @@ bump_version_json() {
minor=$(echo "$current_version" | cut -d. -f2)
patch=$(echo "$current_version" | cut -d. -f3)

if [[ "$version_part" != "major" && "$version_part" != "minor" && "$version_part" != "patch" ]]; then
if [[ "$version_part" != "major" && "$version_part" != "minor" && "$version_part" != "patch" && "$version_part" != "snapshot" ]]; then
new_version="$version_part"
else
# Bump the specified version part
case "$version_part" in
major) major=$((major + 1)); minor=0; patch=0;;
minor) minor=$((minor + 1)); patch=0;;
patch) patch=$((patch + 1));;
patch|snapshot) patch=$((patch + 1));;
esac

# Create new version string
new_version="${major}.${minor}.${patch}"
if [[ $version_part == "snapshot" ]]; then
new_version+="-SNAPSHOT"
fi
fi

# Replace old version with new version in a temporary string
Expand Down

0 comments on commit 8e894a5

Please sign in to comment.