Skip to content

Commit

Permalink
cd: Add check if pushed tag version is highest in semantic versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
itislu committed Apr 21, 2024
1 parent daf2059 commit 6f75af6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ on:
tags:
- 'v*.*.*'

env:
VERSION:

permissions:
contents: write
actions: write

jobs:
release:
runs-on: ubuntu-latest
env:
VERSION:
PROCEED:

steps:
- name: Checkout main branch
uses: actions/checkout@v4
Expand All @@ -30,7 +31,20 @@ jobs:
- name: Get version number
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

- name: 🏷️ Check tag version
run: |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
new_tag=${{ env.VERSION }}
echo "latest_tag: $latest_tag"
echo "new_tag: $new_tag"
if [[ $(printf '%s\n' "$latest_tag" "$new_tag" | sort -V | head -n1) == "$latest_tag" ]]; then
echo "PROCEED=true" >> "$GITHUB_ENV"
else
echo "PROCEED=false" >> "$GITHUB_ENV"
fi
- name: ⏫ Update version number in script
if: env.PROCEED == 'true'
run: |
sed -i "s/^current_version=.*/current_version=\"${{ env.VERSION }}\"/" 42free.sh
git add 42free.sh
Expand All @@ -40,6 +54,7 @@ jobs:
git push -f origin ${{ env.VERSION }}
- name: 🚀 Release and upload asset
if: env.PROCEED == 'true'
uses: softprops/action-gh-release@v2
with:
files: 42free.sh
Expand All @@ -49,6 +64,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 🛠️ Append dev to version number in script
if: env.PROCEED == 'true'
run: |
new_version="${{ env.VERSION }}+dev"
sed -i "s/^current_version=.*/current_version=\"$new_version\"/" 42free.sh
Expand Down

0 comments on commit 6f75af6

Please sign in to comment.