updated readme #15
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 Tag and Version Bump | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| types: [closed] | |
| branches: [main] | |
| workflow_dispatch: | |
| # Ensure we only run one tag creation at a time | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test-and-tag: | |
| # Only run if push to main or PR was merged (not just closed) | |
| if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for full history and conventional commits analysis | |
| - name: Use Node.js 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Run linting | |
| run: npm run lint | |
| - name: Get current version | |
| id: current-version | |
| uses: martinbeentjes/[email protected] | |
| - name: Determine version bump | |
| id: version-bump | |
| run: | | |
| # Install conventional-changelog-cli globally | |
| npm install -g conventional-changelog-cli conventional-recommended-bump | |
| # Determine bump type based on conventional commits | |
| BUMP_TYPE=$(npx conventional-recommended-bump -p angular) | |
| echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT | |
| # Get the current version | |
| CURRENT_VERSION=${{ steps.current-version.outputs.current-version }} | |
| # Calculate new version based on bump type | |
| if [ "$BUMP_TYPE" = "major" ]; then | |
| NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$1 = $1 + 1; $2 = 0; $3 = 0} {print $1"."$2"."$3}') | |
| elif [ "$BUMP_TYPE" = "minor" ]; then | |
| NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$2 = $2 + 1; $3 = 0} {print $1"."$2"."$3}') | |
| else | |
| NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$3 = $3 + 1} {print $1"."$2"."$3}') | |
| fi | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update version in package.json | |
| run: npm version ${{ steps.version-bump.outputs.new_version }} --no-git-tag-version | |
| - name: Generate Release Notes | |
| id: release-notes | |
| run: | | |
| # Generate release notes from conventional commits | |
| conventional-changelog -p angular -i CHANGELOG.md -s -r 1 > RELEASE_NOTES.md | |
| # Save release notes to output | |
| echo "NOTES<<EOF" >> $GITHUB_OUTPUT | |
| cat RELEASE_NOTES.md >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Commit version bump | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| git add package.json package-lock.json CHANGELOG.md | |
| git commit -m "chore(release): bump version to ${{ steps.version-bump.outputs.new_version }} [skip ci]" | |
| git push - name: Create and push tag | |
| # Create annotated tag with release notes | |
| echo "${{ steps.release-notes.outputs.NOTES }}" > tag_message.txt | |
| git tag -a "v${{ steps.version-bump.outputs.new_version }}" -F tag_message.txt | |
| # Force push in case tag exists remotely but not locally | |
| git push origin --force "v${{ steps.version-bump.outputs.new_version }}" | |
| - name: Wait for release workflow | |
| run: | | |
| # Wait for up to 5 minutes for the release workflow to start | |
| for i in {1..30}; do | |
| echo "Checking for release workflow (attempt $i)..." | |
| if gh run list --workflow=release.yml --event=push --json conclusion,status,headBranch --jq '.[] | select(.headBranch=="v${{ steps.version-bump.outputs.new_version }}")' | grep -q .; then | |
| echo "Release workflow found!" | |
| exit 0 | |
| fi | |
| sleep 10 | |
| done | |
| echo "Release workflow did not start within timeout" | |
| exit 1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |