Merge branch 'main' of github.com:jooaf/thoth #14
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: Auto Tag and Update Version | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
auto_tag_and_update: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Debug Info | |
run: | | |
echo "GitHub Ref: ${{ github.ref }}" | |
echo "GitHub Event Name: ${{ github.event_name }}" | |
echo "Last Commit Message:" | |
git log -1 --pretty=%B | |
echo "Changed files:" | |
git diff --name-only HEAD^ | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
git fetch --tags | |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0") | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT | |
echo "Latest tag: $LATEST_TAG" | |
- name: Bump version | |
id: bump_version | |
run: | | |
LATEST_TAG=${{ steps.get_latest_tag.outputs.LATEST_TAG }} | |
LATEST_VERSION=${LATEST_TAG#v} | |
IFS='.' read -ra VERSION_PARTS <<< "$LATEST_VERSION" | |
MAJOR=${VERSION_PARTS[0]} | |
MINOR=${VERSION_PARTS[1]} | |
PATCH=${VERSION_PARTS[2]} | |
NEW_PATCH=$((PATCH + 1)) | |
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT | |
echo "New version: $NEW_VERSION" | |
- name: Update Cargo.toml | |
run: | | |
sed -i 's/^version = ".*"/version = "${{ steps.bump_version.outputs.NEW_VERSION }}"/' Cargo.toml | |
echo "Updated Cargo.toml:" | |
grep version Cargo.toml | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add Cargo.toml | |
git commit -m "Bump version to ${{ steps.bump_version.outputs.NEW_VERSION }}" | |
git push | |
echo "Pushed changes to Cargo.toml" | |
echo "New git status:" | |
git status | |
- name: Create new tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git tag -a v${{ steps.bump_version.outputs.NEW_VERSION }} -m "Release v${{ steps.bump_version.outputs.NEW_VERSION }}" | |
git push origin v${{ steps.bump_version.outputs.NEW_VERSION }} | |
echo "Created and pushed new tag: v${{ steps.bump_version.outputs.NEW_VERSION }}" | |
echo "All tags:" | |
git tag -l |