Skip to content

Commit

Permalink
Make code error reliant
Browse files Browse the repository at this point in the history
This should make it easier to use versioner on repos with no tags
  • Loading branch information
Dragos Dumitrache committed Jan 2, 2024
1 parent 6c464ac commit b59fef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-and-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
run: |
./run_tests.sh
- uses: ./versioner/
if: github.ref == 'ref/heads/master'
if: ${{ github.ref == 'refs/heads/master' }}
id: versioner
- name: publish tag
if: github.ref == 'ref/heads/master'
if: ${{ github.ref == 'refs/heads/master' }}
run: |
git config --global user.email ${{ secrets.EMAIL }}
git config --global user.name ${{ secrets.NAME }}
Expand Down
18 changes: 12 additions & 6 deletions version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ function semver {
git_branch=$(git branch --show-current)

# Get the latest tag
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
major_minor=$(echo $latest_tag | cut -d '.' -f -2)
patch=$(echo $latest_tag | cut -d '.' -f 3)
# Get the list of commits since the latest tag
commits=$(git rev-list --count $latest_tag..HEAD)
new_patch=$(($commits + $patch))
latest_tag=$(git tag -l --sort=-creatordate | head -n 1)
if [ $latest_tag ]; then

major_minor=$(echo "$latest_tag" | cut -d '.' -f -2)
patch=$(echo "$latest_tag" | cut -d '.' -f 3)
# Get the list of commits since the latest tag
commits=$(git rev-list --count "$latest_tag"..HEAD)
# shellcheck disable=SC2004
new_patch=$(($commits + $patch))
else
new_patch=$patch
fi
git_generated_version="${major_minor}.${new_patch}"
future_major=$(cat version.json | jq ".major" --raw-output)
future_minor=$(cat version.json | jq ".minor" --raw-output)
Expand Down

0 comments on commit b59fef3

Please sign in to comment.