Merge pull request #2 from LAB271/dependabot/npm_and_yarn/input_viewe… #42
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: Auto Release | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - "*.md" | |
| - "LICENSE" | |
| - ".gitignore" | |
| - "assets/**" | |
| jobs: | |
| analyze-and-release: | |
| name: Analyze & Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Need full history for commit analysis | |
| - name: Get current version | |
| id: current_version | |
| run: | | |
| if [ -f VERSION ]; then | |
| echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=0.0.0" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Analyze commits for version bump | |
| id: analyze | |
| run: | | |
| # Get commits since last tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| echo "No previous tag found, using all commits" | |
| COMMITS=$(git log --pretty=format:"%s" --no-merges) | |
| else | |
| echo "Analyzing commits since $LAST_TAG" | |
| COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"%s" --no-merges) | |
| fi | |
| if [ -z "$COMMITS" ]; then | |
| echo "No new commits since last tag" | |
| echo "bump=none" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "Commits to analyze:" | |
| echo "$COMMITS" | |
| echo "" | |
| # Determine version bump type based on conventional commits | |
| # BREAKING CHANGE or ! after type = major | |
| # feat = minor | |
| # fix, perf, refactor = patch | |
| BUMP="none" | |
| # Check for major (breaking changes) | |
| if echo "$COMMITS" | grep -qiE "^.+!:|BREAKING CHANGE"; then | |
| BUMP="major" | |
| echo "Found BREAKING CHANGE - major bump" | |
| # Check for minor (new features) | |
| elif echo "$COMMITS" | grep -qiE "^feat(\(.+\))?:"; then | |
| BUMP="minor" | |
| echo "Found feat commit - minor bump" | |
| # Check for patch (fixes, performance, refactors) | |
| elif echo "$COMMITS" | grep -qiE "^(fix|perf|refactor|build|ci)(\(.+\))?:"; then | |
| BUMP="patch" | |
| echo "Found fix/perf/refactor commit - patch bump" | |
| # Any other commits with conventional format | |
| elif echo "$COMMITS" | grep -qiE "^(docs|style|test|chore)(\(.+\))?:"; then | |
| echo "Found docs/style/test/chore - no version bump" | |
| BUMP="none" | |
| # Non-conventional commits default to patch | |
| else | |
| BUMP="patch" | |
| echo "Non-conventional commits found - defaulting to patch bump" | |
| fi | |
| echo "bump=$BUMP" >> $GITHUB_OUTPUT | |
| - name: Calculate new version | |
| id: new_version | |
| if: steps.analyze.outputs.bump != 'none' | |
| run: | | |
| CURRENT="${{ steps.current_version.outputs.version }}" | |
| BUMP="${{ steps.analyze.outputs.bump }}" | |
| # Parse current version | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" | |
| # Calculate new version | |
| case $BUMP in | |
| major) | |
| NEW_VERSION="$((MAJOR + 1)).0.0" | |
| ;; | |
| minor) | |
| NEW_VERSION="${MAJOR}.$((MINOR + 1)).0" | |
| ;; | |
| patch) | |
| NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" | |
| ;; | |
| esac | |
| echo "Current: $CURRENT -> New: $NEW_VERSION ($BUMP)" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update VERSION file | |
| if: steps.analyze.outputs.bump != 'none' | |
| run: | | |
| echo "${{ steps.new_version.outputs.version }}" > VERSION | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add VERSION | |
| git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}" | |
| git push | |
| - name: Create and push tag | |
| if: steps.analyze.outputs.bump != 'none' | |
| run: | | |
| VERSION="${{ steps.new_version.outputs.version }}" | |
| git tag -a "v${VERSION}" -m "Release v${VERSION}" | |
| git push origin "v${VERSION}" | |
| - name: Summary | |
| run: | | |
| if [ "${{ steps.analyze.outputs.bump }}" == "none" ]; then | |
| echo "### No Release" >> $GITHUB_STEP_SUMMARY | |
| echo "No version bump needed based on commit analysis." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "### 🚀 Release Triggered" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Bump type:** ${{ steps.analyze.outputs.bump }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **New version:** v${{ steps.new_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The release workflow will now build and publish the binaries." >> $GITHUB_STEP_SUMMARY | |
| fi |