Skip to content

Commit

Permalink
AAE-11760 git-latest-tag-sha action (#201)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovanni Toraldo <giovanni.toraldo@hyland.com>
  • Loading branch information
ozeta and gionn committed Dec 20, 2022
1 parent a3485c7 commit 4a862d4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
10 changes: 1 addition & 9 deletions .github/actions/git-latest-tag/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,4 @@ runs:
env:
PATTERN: ${{ inputs.pattern }}
REPO_DIR: ${{ inputs.repository-directory }}
run: |
if [ -n "$REPO_DIR" ]
then
cd $REPO_DIR
fi
git fetch --tags
TAG=$(git tag --list "$PATTERN" --sort=-creatordate | head -n 1)
echo "Latest tag for the pattern $PATTERN is $TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
run: ${{ github.action_path }}/git-latest-tag.sh
11 changes: 11 additions & 0 deletions .github/actions/git-latest-tag/git-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -n "$REPO_DIR" ]; then
cd "$REPO_DIR"
fi
git fetch --tags
TAG=$(git tag --list "$PATTERN" --sort=-creatordate | head -n 1)
TAG_LONG_SHA=$(git rev-list -n 1 $TAG)
echo "Tag for the pattern $PATTERN is $TAG ($TAG_LONG_SHA)"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "tag_long_sha=$TAG_LONG_SHA" >> "$GITHUB_OUTPUT"
35 changes: 35 additions & 0 deletions .github/actions/git-latest-tag/tests/git-latest-tag.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
setup() {
git fetch --tags

# Runs everywhere
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"

# Mock GitHub Actions default variables
export GITHUB_ENV=/dev/null
export GITHUB_HEAD_REF="AAE-11760-get-latest-tag-sha"

# Mock git-latest-tag defaults
export PATTERN="*"
export REPO_DIR="$PWD"
}

@test "latest_tag" {
regex="v[0-9]+\.[0-9]+\.[0-9]+"
run git-latest-tag.sh
[ "$status" -eq 0 ]
if [[ ! $output =~ $regex ]]; then
echo "Output does not match regex: $regex"
exit 1
fi
}

@test "tag_v1.0.0" {
export PATTERN="v1.0.0"
tag="v1.0.0"
tag_sha="93891a5cfd55868bdfbd145ed8016ea8c63e37be"
run git-latest-tag.sh

[ "$status" -eq 0 ]
[ "$output" = "Tag for the pattern $PATTERN is $tag ($tag_sha)" ]
}
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Commits local changes after configuring git user and showing the status of what

### git-latest-tag

Gets the latest tag for the given pattern. The result is returned in the output named `tag`.
Gets the latest tag and commit sha for the given pattern. The result is returned in the output named `tag` and `tag_long_sha`.

```yaml
- uses: Alfresco/alfresco-build-tools/.github/actions/git-latest-tag@ref
Expand Down

0 comments on commit 4a862d4

Please sign in to comment.