Skip to content

Commit

Permalink
Create action to create a commit with the next major/minor/patch version
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecialThing44 committed Oct 1, 2024
1 parent 61a6ee4 commit 90dedd7
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Actions for building workflows to build/publish images
- [needs](needs/action.yml)
- [prettier](prettier/action.yml)
- [next-version](next-version/action.yml)
- [bump-version](bump-version/action.yml)
148 changes: 148 additions & 0 deletions bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: "Bump Version"
description: "Create and push a version bump commit automatically picking major/minor/patch based on the contents of the major and minor directories"
author: "GarnerCorp"
branding:
icon: "arrow-up"
color: "green"
inputs:
version-file-path:
description: Path to the version file
required: true
version-type:
description: Version file type ("node", "sbt") -- if not provided a version-parser must be provided
required: false
version-parser:
description: Program (called to `parse` and `update` the version file)
required: false
git-name:
description: The name of the user who will make the version commit
required: false
git-email:
description: The email of the user who will make the version commit
required: false
major:
description: Directory containing files that signify a major version bump (to be combined into a message and deleted)
required: false
minor:
description: Directory containing files that signify a minor version bump (to be combined into a message and deleted)
required: false
debug:
description: Trace next-version steps
required: false
outputs:
version:
description: Generated version based on current version and presence of files in the major and minor directories
value: ${{ steps.bump-version.outputs.version }}
old-version:
description: Current version from given version file
value: ${{ steps.bump-version.outputs.old-version }}
commit-log:
description: Path to file containing contents of files in the major and minor directories
value: ${{ steps.bump-version.outputs.commit-log }}

runs:
using: "composite"
steps:
- name: Validate inputs
if: ${{ !inputs.version-file-path || (!inputs.version-pattern && !inputs.version_parser) }}
shell: bash
env:
INPUTS: ${{ toJSON(inputs) }}
run: |
"${{ github.action_path }}/../scripts/report-missing-inputs.pl"
- name: get-current-version
if: ${{ !inputs.version-type }}
shell: bash
run: |
: Ask the version-parser to get the version from the version file
echo "CURRENT_VERSION=$("$VERSION_PARSER" parse "$VERSION_FILE_PATH")" >> "$GITHUB_ENV"
env:
VERSION_PARSER: ${{ inputs.version-parser }}
VERSION_FILE_PATH: ${{ inputs.version-file-path }}

- name: Set variables
shell: bash
run: |
: Set the version pattern based on the version type
if [ "${{ inputs.version-type }}" == "node" ]; then
echo 'VERSION_PATTERN=${{ env.VERSION_PATTERN_NODE }}' >> "$GITHUB_ENV"
elif [ "${{ inputs.version-type }}" == "sbt" ]; then
echo 'VERSION_PATTERN=${{ env.VERSION_PATTERN_SBT }}' >> "$GITHUB_ENV"
else
echo 'VERSION_PATTERN=' >> "$GITHUB_ENV"
fi
# Set the git name and email
echo "GIT_NAME=$GIT_NAME" >> "$GITHUB_ENV"
echo "GIT_MAIL=$GIT_MAIL" >> "$GITHUB_ENV"
env:
VERSION_PATTERN_NODE: '"version": "(\d+\.\d+\.\d+)"'
VERSION_PATTERN_SBT: 'ThisBuild / version := "(\d+\.\d+\.\d+)"'
GIT_NAME: ${{ inputs.git-name }}
GIT_MAIL: ${{ inputs.git-email }}

- uses: GarnerCorp/build-actions/next-version@automated-version-bumping
with:
version-file-path: ${{ inputs.version-file-path }}
version-pattern: ${{ env.VERSION_PATTERN }}
current-version: ${{ env.CURRENT_VERSION }}
major: ${{ inputs.major }}
minor: ${{ inputs.minor }}
debug: ${{ inputs.debug }}

- name: custom-bump
if: ${{ inputs.version-parser }}
shell: bash
run: |
: Update the version in the file using custom parser
"$VERSION_PARSER" update "$VERSION_FILE" "$VERSION"
env:
VERSION: ${{ steps.bump.outputs.version }}
VERSION_PARSER: ${{ inputs.version-parser }}
VERSION_FILE: ${{ inputs.version-file-path }}

- name: default-bump
if: ${{ !inputs.version-parser }}
shell: bash
run: |
: Update the version in the file
perl -pi -e 's/$ENV{VERSION_PREFIX}$ENV{OLD_VERSION}/$ENV{VERSION_PREFIX}$ENV{VERSION}/g' "$VERSION_FILE"
env:
VERSION_PREFIX_NODE: '"version": "'
VERSION_PREFIX_SBT: 'ThisBuild / version := "'
VERSION_PREFIX: ${{ inputs.version-type == 'node' && env.VERSION_PREFIX_NODE || inputs.version-type == 'sbt' && env.VERSION_PREFIX_SBT || '' }}
VERSION: ${{ steps.bump.outputs.version }}
OLD_VERSION: ${{ steps.bump.outputs.old-version }}
VERSION_FILE: ${{ inputs.version-file-path }}

- name: set-git-username
if: ${{ env.GIT_NAME }}
shell: bash
run: |
: Set the git username
git config --global user.name "$GIT_NAME"
- name: set-git-email
if: ${{ env.GIT_MAIL }}
shell: bash
run: |
: Set the git email
git config --global user.email "$GIT_MAIL"
- name: commit
shell: bash
run: |
: Commit the version bump
git add -u
commit_message=$(mktemp)
(
echo "Update version to $VERSION"
echo
cat $COMMIT_LOG
) >> $commit_message
git commit -F "$commit_message"
git push origin HEAD
env:
VERSION: ${{ steps.bump.outputs.version }}
COMMIT_LOG: ${{ steps.bump.outputs.commit-log }}
8 changes: 6 additions & 2 deletions next-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ inputs:
required: true
version-pattern:
description: Perl regular expression containing a capture group which matches the version value from the specified file
required: true
required: false
current-version:
description: Current version from given version file
required: false
major:
description: Directory containing files that signify a major version bump (to be combined into a message and deleted)
required: false
Expand All @@ -35,7 +38,7 @@ runs:
using: "composite"
steps:
- name: Validate inputs
if: ${{ !inputs.version-pattern || !inputs.version-file-path }}
if: ${{ (!inputs.version-pattern || !inputs.version-file-path ) && !inputs.current-version }}
shell: bash
env:
INPUTS: ${{ toJSON(inputs) }}
Expand All @@ -50,6 +53,7 @@ runs:
env:
VERSION_FILE: ${{ inputs.version-file-path }}
VERSION_PATTERN: ${{ inputs.version-pattern }}
CURRENT_VERSION: ${{ inputs.current-version }}
MAJOR: ${{ inputs.major }}
MINOR: ${{ inputs.minor }}
DEBUG: ${{ inputs.debug }}
8 changes: 7 additions & 1 deletion next-version/next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ else
bump_type="patch"
fi

current_version=$(perl -ne 'next unless s/.*$ENV{VERSION_PATTERN}/$1/; print' "$VERSION_FILE")
if [ -n "$CURRENT_VERSION" ]; then
current_version="$CURRENT_VERSION"
else
current_version=$(perl -ne 'next unless s/.*$ENV{VERSION_PATTERN}/$1/; print' "$VERSION_FILE")
fi
echo "VERSION_PATTERN: $VERSION_PATTERN"


new_version=$(bump_version "$current_version" "$bump_type")

Expand Down

0 comments on commit 90dedd7

Please sign in to comment.