Skip to content

Add version code generation in CI #5

Add version code generation in CI

Add version code generation in CI #5

Workflow file for this run

name: Build Number
on:
workflow_call:
outputs:
build-number:
description: "The build number generated from git tags on current SHA."
value: ${{ jobs.build-number.outputs.build-number }}
inputs:
token:
description: 'GitHub token or PAT token'
required: false
default: ${{ github.token }}
type: string
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build-number:
runs-on: ubuntu-latest
# outputs:
# build_number: ${{ steps.build-number.outputs.build_number }}
steps:

Check failure on line 25 in .github/workflows/build-number.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-number.yml

Invalid workflow file

You have an error in your yaml syntax on line 25
- name: Generate build number
id: build-number
env:
INPUT_GITHUB_TOKEN: ${{ inputs.token }}
run: |
CURRENT_BUILD_NUMBER=$(git show-ref --tags | grep "$GITHUB_SHA" | sort -nr | head -1 | grep -oE "build-number--(\d+)" | grep -oE "\d+")
echo "Found build number $CURRENT_BUILD_NUMBER for current SHA."
if [ -z "${CURRENT_BUILD_NUMBER}" ]; then
echo "No build number found for current SHA"
# Get the latest build number
LATEST_BUILD_NUMBER=$(git show-ref --tags | grep -oE "build-number-(\d+)" | sort -nr | head -1 | grep -oE "\d+")
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%?(:)//*}"
# "$GITHUB_SERVER_URL" | sed -E "s/https?:\/\///g")
REMOTE_REPO="${GITHUB_URL_PROTOCOL}//oauth2:${INPUT_GITHUB_TOKEN}@${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
# PUSH_PARAMETERS="${REMOTE_REPO} HEAD:${GITHUB_REF}"
PUSH_PARAMETERS="${REMOTE_REPO}"
echo "Pushing build number tag build-number-$CURRENT_BUILD_NUMBER to Github ($GITHUB_REF)."
git push "$PUSH_PARAMETERS" --tags
else
echo "Skipping tag creation."
exit 0
fi
echo "BUILD_NUMBER=$CURRENT_BUILD_NUMBER" > "$GITHUB_ENV"