Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-11760 git-latest-tag-sha action #201

Merged
merged 20 commits into from
Dec 20, 2022
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"
36 changes: 36 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,36 @@
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
ozeta marked this conversation as resolved.
Show resolved Hide resolved
echo "Output does not match regex: $regex"
exit 1
fi
}

@test "tag_v1.0.0" {
export PATTERN="v1.0.0"
export REPO_DIR="$PWD"
ozeta marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -364,7 +364,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