Skip to content

Commit

Permalink
Add version output (#3)
Browse files Browse the repository at this point in the history
* Refactor to get output

* quiet down maven

* quiet down maven

* bump

* bump

* Fix typo

* Refactor get-version into own script

* Fix bug

* Fix stuff

* Fix stuff

* Fix stuff

* Fix stuff

* Remove uneeded logging

* Update docs
  • Loading branch information
jonnysamps authored Apr 12, 2021
1 parent 1ee257a commit 116126b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v3 - 04/10/2021

- Add `version` output
- Refactor to use composite type instead of Dockerfile

## v2 - 01/09/2021

- Use Docker image with dependencies pre-loaded
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ jobs:
uses: actions/checkout@v2

- name: Bump Version
id: bump
uses: nnichols/maven-version-bump-action@v2
with:
github-token: ${{ secrets.github_token }}

- name: Print Version
run: "echo 'New Version: ${{steps.bump.outputs.version}}'"
```
## Supported Arguments
Expand All @@ -36,3 +40,7 @@ jobs:
* `git-email`: The email address each commit should be associated with. Defaults to a github provided noreply address
* `git-username`: The GitHub username each commit should be associated with. Defaults to `github-actions[bot]`
* `pom-path`: The path within your directory the pom.xml you intended to change is located.

## Outputs

* `version` - The after-bump version. Will return the old version if bump was not necessary.
32 changes: 25 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ inputs:
required: true
default: github-actions[bot]

outputs:
version:
description: 'The current version (whether updated or not)'
value: ${{ steps.get-outputs.outputs.version }}

runs:
using: docker
image: Dockerfile
env:
TOKEN: ${{ inputs.github-token }}
EMAIL: ${{ inputs.git-email }}
NAME: ${{ inputs.git-username }}
POMPATH: ${{ inputs.pom-path}}
using: "composite"
steps:
- name: Bump Version
env:
TOKEN: ${{ inputs.github-token }}
EMAIL: ${{ inputs.git-email }}
NAME: ${{ inputs.git-username }}
POMPATH: ${{ inputs.pom-path }}
run: ${{github.action_path}}/version-bump.sh
shell: bash
- name: Set outputs
id: get-outputs
shell: bash
env:
POMPATH: ${{ inputs.pom-path }}
run: echo "::set-output name=version::$(${{github.action_path}}/get-version.sh)"
- name: Result
shell: bash
run: "echo 'Version is now ${{ steps.get-outputs.outputs.version }}'"

1 change: 1 addition & 0 deletions get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cat $POMPATH/pom.xml | grep "<version>.*</version>" | head -1 | awk -F'[><]' '{print $3}'
17 changes: 10 additions & 7 deletions version-bump.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

#
# Takes a version number, and the mode to bump it, and increments/resets
# the proper components so that the result is placed in the variable
Expand Down Expand Up @@ -30,11 +33,8 @@ function bump {

git config --global user.email $EMAIL
git config --global user.name $NAME
export GITHUB_TOKEN=$TOKEN

cd $POMPATH

OLD_VERSION=$(cat pom.xml | grep "<version>.*</version>" | head -1 | awk -F'[><]' '{print $3}')
OLD_VERSION=$($DIR/get-version.sh)

BUMP_MODE="none"
if git log -1 | grep -q "#major"; then
Expand All @@ -53,8 +53,11 @@ else
echo $BUMP_MODE "version bump detected"
bump $BUMP_MODE $OLD_VERSION
echo "pom.xml at" $POMPATH "will be bumped from" $OLD_VERSION "to" $NEW_VERSION
mvn versions:set -DnewVersion="${NEW_VERSION}"
git add pom.xml
mvn -q versions:set -DnewVersion="${NEW_VERSION}"
git add $POMPATH/pom.xml
REPO="https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git"
git commit -m "Bump pom.xml from $OLD_VERSION to $NEW_VERSION"
git push -u "https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git"
git tag $NEW_VERSION
git push $REPO --follow-tags
git push $REPO --tags
fi

0 comments on commit 116126b

Please sign in to comment.