Create Release #3
This file contains hidden or 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: Create Release | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| create-release: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine version bump | |
| id: bump | |
| run: | | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$LATEST_TAG" ]; then | |
| SINCE=$(git rev-list --max-parents=0 HEAD) | |
| COMMITS=$(git log "$SINCE"..HEAD --pretty=format:"%s") | |
| else | |
| COMMITS=$(git log "$LATEST_TAG"..HEAD --pretty=format:"%s") | |
| fi | |
| BUMP="patch" | |
| if echo "$COMMITS" | grep -q "^feat:"; then | |
| BUMP="minor" | |
| fi | |
| if echo "$COMMITS" | grep -q "^breaking:"; then | |
| BUMP="major" | |
| fi | |
| echo "type=$BUMP" >> "$GITHUB_OUTPUT" | |
| - name: Compute new version | |
| id: version | |
| run: | | |
| CURRENT=$(grep '^pluginVersion=' gradle.properties | cut -d= -f2) | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | |
| BUMP="${{ steps.bump.outputs.type }}" | |
| if [ "$BUMP" = "major" ]; then | |
| MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 | |
| elif [ "$BUMP" = "minor" ]; then | |
| MINOR=$((MINOR + 1)); PATCH=0 | |
| else | |
| PATCH=$((PATCH + 1)) | |
| fi | |
| NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
| echo "current=$CURRENT" >> "$GITHUB_OUTPUT" | |
| echo "new=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Update gradle.properties | |
| run: | | |
| sed -i "s/^pluginVersion=.*/pluginVersion=${{ steps.version.outputs.new }}/" gradle.properties | |
| - name: Commit and tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add gradle.properties | |
| git commit -m "chore: bump version to ${{ steps.version.outputs.new }}" | |
| git tag "v${{ steps.version.outputs.new }}" | |
| git push origin main --tags |