-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b700f10
commit 287ec6d
Showing
12 changed files
with
138 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Build Number | ||
|
||
on: | ||
workflow_call: | ||
outputs: | ||
build-number: | ||
description: "The build number generated from git tags on current SHA." | ||
value: ${{ jobs.build.outputs.build-number }} | ||
inputs: | ||
token: | ||
description: 'GitHub token or PAT token' | ||
required: false | ||
default: ${{ github.token }} | ||
type: string | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
outputs: | ||
build_number: ${{ steps.build-number.outputs.BUILD_NUMBER }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
fetch-tags: true | ||
|
||
- name: Generate build number | ||
id: build-number | ||
env: | ||
INPUT_GITHUB_TOKEN: ${{ inputs.token }} | ||
INPUT_SHA: ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha }} | ||
run: | | ||
./scripts/build-number.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
TAGS=$(git show-ref --tags) | ||
|
||
function getBuildNumberTag { | ||
set +e | ||
echo "$TAGS"| grep "${1:-}" | grep -oE 'build-number-[[:digit:]]+' | grep -oE '[[:digit:]]+' | sort -nr | head -1 | ||
set -e | ||
} | ||
|
||
CURRENT_BUILD_NUMBER=$(getBuildNumberTag "$INPUT_SHA") | ||
|
||
OUT=$(echo "$TAGS" | grep -oE 'build-number-[[:digit:]]+') | ||
echo "$OUT" | ||
|
||
if [[ -z "${CURRENT_BUILD_NUMBER}" ]]; then | ||
echo "No build number found for current SHA $INPUT_SHA." | ||
|
||
# Get the latest build number | ||
LATEST_BUILD_NUMBER=$(getBuildNumberTag) | ||
|
||
if [[ -z "${LATEST_BUILD_NUMBER}" ]]; then | ||
echo "No build number found in tags. Please create a tag with the format 'build-number-1' on main branch." | ||
exit 1 | ||
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]" | ||
|
||
GITHUB_URL_PROTOCOL=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^\(.*://\).*,\1,g') | ||
GITHUB_URL_HOST=$(echo "$GITHUB_SERVER_URL" | sed -e 's,^.*://\(.*\),\1,g') | ||
|
||
echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($GITHUB_REF)." | ||
|
||
git push "${GITHUB_URL_PROTOCOL}${INPUT_GITHUB_TOKEN}@${GITHUB_URL_HOST}/${GITHUB_REPOSITORY}.git" --tags | ||
else | ||
echo "Found build number $CURRENT_BUILD_NUMBER for current SHA $INPUT_SHA." | ||
echo "Skipping tag creation." | ||
fi | ||
|
||
echo "BUILD_NUMBER=$CURRENT_BUILD_NUMBER" >> "$GITHUB_ENV" |