feat: Refactor CLI with intuitive scan flags, add chalk/ora/cli-progr… #45
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: Automated Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*.*.*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| # Trigger on: | |
| # 1. Tag push (v*.*.*) | |
| # 2. Commit message starting with "chore: release" (squash merge) | |
| if: | | |
| startsWith(github.ref, 'refs/tags/v') || | |
| startsWith(github.event.head_commit.message, 'chore: release') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| run: corepack enable | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Install Dependencies | |
| run: pnpm install --frozen-lockfile --ignore-scripts | |
| - name: pnpm Audit | |
| run: pnpm audit --prod | |
| continue-on-error: true | |
| - name: Extract Version | |
| id: get_version | |
| env: | |
| COMMIT_MSG: ${{ github.event.head_commit.message }} | |
| GIT_REF: ${{ github.ref }} | |
| run: | | |
| # Try to get version from tag first | |
| if [[ "$GIT_REF" == refs/tags/v* ]]; then | |
| VERSION="${GIT_REF#refs/tags/v}" | |
| echo "Version from tag: $VERSION" | |
| else | |
| # Fallback to commit message | |
| # Use head -n 1 to ensure we only get the first match if multiple exist | |
| VERSION=$(echo "$COMMIT_MSG" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || echo "") | |
| echo "Version from commit: $VERSION" | |
| fi | |
| if [[ -z "$VERSION" ]]; then | |
| echo "Error: Could not extract version" | |
| exit 1 | |
| fi | |
| echo "Detected version: $VERSION" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Create Git Tag (if not exists) | |
| if: "!startsWith(github.ref, 'refs/tags/')" | |
| run: | | |
| VERSION="${{ steps.get_version.outputs.version }}" | |
| if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$VERSION already exists, skipping" | |
| else | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| fi | |
| - name: Extract Release Notes | |
| id: extract_notes | |
| run: | | |
| VERSION="${{ steps.get_version.outputs.version }}" | |
| # Extract content between the version header and the next header | |
| awk -v ver="$VERSION" '$0 ~ "^## \\[" ver "\\]" {flag=1; next} /^## \[/ {flag=0} flag' CHANGELOG.md > RELEASE_NOTES.md | |
| if [ -s RELEASE_NOTES.md ]; then | |
| echo "Notes extracted successfully." | |
| echo "use_generated=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Warning: No notes found for v$VERSION. Using auto-generated notes." | |
| echo "use_generated=true" >> $GITHUB_OUTPUT | |
| rm -f RELEASE_NOTES.md | |
| fi | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2.4.2 | |
| with: | |
| tag_name: v${{ steps.get_version.outputs.version }} | |
| name: v${{ steps.get_version.outputs.version }} | |
| body_path: ${{ steps.extract_notes.outputs.use_generated == 'false' && 'RELEASE_NOTES.md' || '' }} | |
| generate_release_notes: ${{ steps.extract_notes.outputs.use_generated }} | |
| draft: false | |
| prerelease: false |