diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..fab5806 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,43 @@ +name: Create version tag + +on: + push: + branches: + - main +env: + TAG_VERSION: v0.0.0 + PREVIOUS_TAG: 0.0.0 + LATEST_TAG: 0.0.0 + SHELL_SCRIPT_VERSION: 0.0.0 +jobs: + create_tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Check the latest version + run: | + all_tags=$(git tag | sort -rV) + read -ra all_tags_vector <<< "$all_tags" + latest_tag_version="${all_tags_vector[0]#v}" + shell_script_version=$(grep -i -E '^# version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"' archcrystal.sh | \ + grep -o -E '[0-9]+\.[0-9]+\.[0-9]+') + echo "SHELL_SCRIPT_VERSION=${shell_script_version}" >> $GITHUB_ENV + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } + if [ $(shell_script_version#v) -ge $(latest_tag_version) ]; then + echo "NEW_TAG_FLAG='1'" >> $GITHUB_ENV + echo "::set-output name=tag-created::1" + fi + + - uses: butlerlogic/action-autotag@1.1.2 + if: ${{ env.NEW_TAG_FLAG != '0' }} + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + with: + strategy: regex + root: archcrystal.sh + regex_pattern: $SHELL_SCRIPT_VERSION + tag_prefix: v diff --git a/archcrystal.sh b/archcrystal.sh index d0396ff..b4c573a 100644 --- a/archcrystal.sh +++ b/archcrystal.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Script Name: archcrystal.sh +# Version: 1.0.0 set -a BASE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"