cd: Add check if pushed tag version is highest in semantic versioning #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release on Tag | |
on: | |
push: | |
tags: | |
- 'v*.*.*' | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
env: | |
VERSION: | |
PROCEED: | |
steps: | |
- name: Checkout main branch | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Configure GitHub Actions bot | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
- 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 }} | |
if [[ $(printf '%s\n' "$latest_tag" "$new_tag" | sort -rV | head -n1) == "$new_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 | |
git commit -m "bot: Update version number to ${{ env.VERSION }}" || exit 0 | |
git push origin main | |
git tag -f ${{ env.VERSION }} | |
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 | |
generate_release_notes: true | |
make_latest: true | |
env: | |
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 | |
git add 42free.sh | |
git commit -m "bot: Update version number to $new_version" | |
git push origin main |