From d3bf2f05968fee2e3c601ec6681c3ddf5c6c749f Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Tue, 14 Jan 2025 11:55:01 -0600 Subject: [PATCH] fix: put version parsing in script --- .github/workflows/main.yml | 21 ++------------------- scripts/version.sh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100755 scripts/version.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 357e6d4a..79be3e94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,17 +56,7 @@ jobs: env: REF: ${{ github.ref }} run: | - versionFile=$(cat VERSION | tr -d '[:space:]') - if [[ $REF == refs/tags/* ]]; then - # check if versionFile equals the tag. - if [[ $versionFile != "${REF#refs/tags/}" ]]; then - echo "Version in VERSION file does not match the tag" - exit 1 - fi - else - # if this isnt a release, add the commit hash to the end of the version - v=$(git rev-parse --short HEAD) echo -n "${versionFile}+${v}" > VERSION - fi + ./scripts/version.sh $REF - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -105,14 +95,7 @@ jobs: env: REF: ${{ github.ref }} run: | - versionFile=$(cat VERSION | tr -d '[:space:]') - if [[ $REF == refs/tags/* ]]; then - # check if versionFile equals the tag. - if [[ $versionFile != "${REF#refs/tags/}" ]]; then - echo "Version in VERSION file does not match the tag" - exit 1 - fi - else + ./scripts/version.sh $REF - name: Build binary run: | VERSION=$(cat VERSION | tr -d '[:space:]') diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 00000000..b584c3ec --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +REF=$1 + +versionFile=$(cat VERSION | tr -d '[:space:]') +if [[ $REF == refs/tags/* ]]; then + # check if versionFile equals the tag. + if [[ $versionFile != "${REF#refs/tags/}" ]]; then + echo "Version in VERSION file does not match the tag" + exit 1 + fi + echo "Version correctly matches tag" +else + # if this isnt a release, add the commit hash to the end of the version + v=$(git rev-parse --short HEAD) + updatedVersion = "${versionFile}+${v}" + echo "Updated version to '${updatedVersion}'" + echo -n $updatedVersion > VERSION +fi