Skip to content

Commit

Permalink
Fix build number sha check
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 16, 2024
1 parent dd9fd66 commit 4a4ec1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Binary file not shown.
31 changes: 21 additions & 10 deletions scripts/build-number.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/bin/bash
TAGS=$(git show-ref --tags)
set -xe

function getBuildNumberTag {
set +e
echo "$TAGS"| grep "${1:-}" | grep -oE 'build-number-[[:digit:]]+' | grep -oE '[[:digit:]]+' | sort -nr | head -1
git pull --tags
git fetch --tags

RESULT="$(git show-ref --tags | grep "${1:-}" | grep -oE 'build-number-[[:digit:]]+' | grep -oE '[[:digit:]]+' | sort -nr | head -1)"
set -e

return "$RESULT"
}

CURRENT_BUILD_NUMBER=$(getBuildNumberTag "$INPUT_SHA")

OUT=$(echo "$TAGS" | grep -oE 'build-number-[[:digit:]]+')
OUT=$(git show-ref --tags | grep -oE 'build-number-[[:digit:]]+')
echo "$OUT"

if [[ -z "${CURRENT_BUILD_NUMBER}" ]]; then
Expand All @@ -24,17 +29,23 @@ if [[ -z "${CURRENT_BUILD_NUMBER}" ]]; then
fi

CURRENT_BUILD_NUMBER="$((LATEST_BUILD_NUMBER + 1))"
git tag "build-number-$CURRENT_BUILD_NUMBER"

git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
CHECK_BUILD_NUMBER=$(getBuildNumberTag "build-number-$CURRENT_BUILD_NUMBER")
if [[ -z "$CHECK_BUILD_NUMBER" ]]; then
git tag "build-number-$CURRENT_BUILD_NUMBER" "$INPUT_SHA"

GITHUB_URL_PROTOCOL=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^\(.*://\).*,\1,g')
GITHUB_URL_HOST=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^.*://\(.*\),\1,g')
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($GITHUB_REF)."
GITHUB_URL_PROTOCOL=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^\(.*://\).*,\1,g')
GITHUB_URL_HOST=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^.*://\(.*\),\1,g')

git push "${GITHUB_URL_PROTOCOL}${INPUT_GITHUB_TOKEN}@${GITHUB_URL_HOST}/${GITHUB_REPOSITORY}.git" --tags
echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($INPUT_SHA)."
git push "${GITHUB_URL_PROTOCOL}${INPUT_GITHUB_TOKEN}@${GITHUB_URL_HOST}/${GITHUB_REPOSITORY}.git" --tags
else
CURRENT_BUILD_NUMBER=$(getBuildNumberTag "$INPUT_SHA")
echo "Build number changed for current SHA $INPUT_SHA. Using origin build number $CURRENT_BUILD_NUMBER."
fi
else
echo "Found build number $CURRENT_BUILD_NUMBER for current SHA $INPUT_SHA."
echo "Skipping tag creation."
Expand Down

0 comments on commit 4a4ec1f

Please sign in to comment.