diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..309a36e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,96 @@ +# This workflow automatically creates a tagged release when the Kitty version +# number in README.md is updated. It detects changes to the version line +# "Keywords based on `v`" and creates a new tag with an incremented +# minor version (e.g., v0.1.0 -> v0.2.0) and a GitHub release. +# +# The workflow only triggers when README.md changes and the Kitty version +# differs from the previous commit. + +name: Create Tagged Release + +on: + push: + branches: + - main + paths: + - 'README.md' + +permissions: + contents: write + +jobs: + check-and-release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + - name: Check if kitty version changed + id: check_version + run: | + # Define the regex pattern for extracting the kitty version + VERSION_PATTERN='Keywords based on `v\K[0-9]+\.[0-9]+\.[0-9]+' + + # Extract the current kitty version from README.md + CURRENT_VERSION=$(grep -oP "$VERSION_PATTERN" README.md) + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + + # Get the previous commit's version using git show + PREV_VERSION=$(git show HEAD^1:README.md 2>/dev/null | grep -oP "$VERSION_PATTERN" || echo "") + echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT + + if [ "$CURRENT_VERSION" != "$PREV_VERSION" ] && [ -n "$PREV_VERSION" ]; then + echo "version_changed=true" >> $GITHUB_OUTPUT + echo "::notice title=Version Updated::Kitty version changed from $PREV_VERSION to $CURRENT_VERSION" + else + echo "version_changed=false" >> $GITHUB_OUTPUT + echo "::info::Kitty version unchanged or first version" + fi + - name: Determine next tag version + if: steps.check_version.outputs.version_changed == 'true' + id: next_version + run: | + # Get the latest tag using git's version sorting + LATEST_TAG=$(git tag -l 'v*' --sort=-version:refname | head -n 1) + + if [ -z "$LATEST_TAG" ]; then + # No tags yet, start with v0.1.0 + NEXT_VERSION="0.1.0" + else + # Extract version numbers + TAG_VERSION=${LATEST_TAG#v} + MAJOR=$(echo $TAG_VERSION | cut -d. -f1) + MINOR=$(echo $TAG_VERSION | cut -d. -f2) + + # Increment minor version + MINOR=$((MINOR + 1)) + NEXT_VERSION="$MAJOR.$MINOR" + fi + + echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT + echo "::notice title=Next Version::Next version will be: v$NEXT_VERSION" + - name: Create tag and release + if: steps.check_version.outputs.version_changed == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + KITTY_VERSION="${{ steps.check_version.outputs.current_version }}" + TAG_VERSION="v${{ steps.next_version.outputs.next_version }}" + TAG_MESSAGE="Sync with v$KITTY_VERSION" + + # Configure git + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Create annotated tag + git tag -a "$TAG_VERSION" -m "$TAG_MESSAGE" + + # Push tag + git push origin "$TAG_VERSION" + + # Create GitHub release + gh release create "$TAG_VERSION" \ + --title "$TAG_VERSION" \ + --notes "$TAG_MESSAGE" \ + --verify-tag diff --git a/README.md b/README.md index 2be1283..475e309 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ session files.

+ + + Keywords based on `v0.44.0`. See [screenshot](https://github.com/fladson/vim-kitty/wiki) for a visual