GitHub Actions - Automate npm package updates and release notes #13
Workflow file for this run
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: Check for Conventional Commits | |
| on: pull_request | |
| jobs: | |
| check_commits: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required to get all commits in the PR | |
| - name: Check for conventional commits | |
| id: get_commits | |
| continue-on-error: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| PR_NUMBER="${{ github.event.number }}" | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| HEAD_SHA="${{ github.event.pull_request.head.sha }}" | |
| echo "Got PR_NUMBER: $PR_NUMBER" | |
| echo "Got BASE_SHA: $BASE_SHA" | |
| echo "Got HEAD_SHA: $HEAD_SHA" | |
| if [[ -z "$PR_NUMBER" ]]; then | |
| PR_COMMITS=$(git log --pretty=format:'%s' $BASE_SHA...$HEAD_SHA) | |
| else | |
| PR_COMMITS=$(gh api -X GET /repos/${{ github.repository }}/pulls/$PR_NUMBER/commits --jq '.[].commit.message') | |
| fi | |
| echo "Got PR_COMMITS: $PR_COMMITS" | |
| commit_array=() | |
| while IFS= read -r line; do | |
| echo "Adding commit message to array: $line" | |
| commit_array+=("$line") | |
| done <<< "$PR_COMMITS" | |
| echo "Pass IFS ussage" | |
| echo "Using commit_array" | |
| has_conventional_commit=false | |
| for commit_message in "${commit_array[@]}"; do | |
| if [[ "$commit_message" =~ ^(feat|fix|build|chore|ci|docs|perf|refactor|revert|style|test)(([^)]+))?: .* ]]; then | |
| has_conventional_commit=true | |
| break | |
| fi | |
| done | |
| echo "has_conventional_commit: $has_conventional_commit" | |
| if [[ "$has_conventional_commit" == "false" ]]; then | |
| echo "::warning::Pull request does not contain at least one conventional commit. A new package version won't be created for this pull request." | |
| exit 1 | |
| else | |
| echo "::notice::Pull request contains at least one conventional commit. A new package version will be created for this pull request." | |
| fi |