From 10de07fe1ad2ae77e955a91a7e7a5bb3cacfd877 Mon Sep 17 00:00:00 2001 From: Jeeva Ramachandran Date: Wed, 29 Nov 2023 19:43:02 +0530 Subject: [PATCH 1/2] feat: update pr title check workflow --- .../workflows/conventional-commit-check.yml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/conventional-commit-check.yml diff --git a/.github/workflows/conventional-commit-check.yml b/.github/workflows/conventional-commit-check.yml new file mode 100644 index 000000000..ad0164206 --- /dev/null +++ b/.github/workflows/conventional-commit-check.yml @@ -0,0 +1,86 @@ +name: Conventional Commit Message Check + +on: + # This is a dangerous event trigger as it causes the workflow to run in the + # context of the target repository. + # Avoid checking out the head of the pull request or building code from the + # pull request whenever this trigger is used. + # Since we only label pull requests, do not have a checkout step in this + # workflow, and restrict permissions on the token, this is an acceptable + # use of this trigger. + pull_request_target: + types: + - opened + - edited + - reopened + - ready_for_review + - synchronize + + merge_group: + types: + - checks_requested + +permissions: + # Reference: https://github.com/cli/cli/issues/6274 + repository-projects: read + pull-requests: write + +env: + # Allow more retries for network requests in cargo (downloading crates) and + # rustup (installing toolchains). This should help to reduce flaky CI failures + # from transient network timeouts or other issues. + CARGO_NET_RETRY: 10 + RUSTUP_MAX_RETRIES: 10 + # Use cargo's sparse index protocol + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + +jobs: + pr_title_check: + name: Verify PR title follows conventional commit standards + runs-on: ubuntu-latest + + steps: + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable 2 weeks ago + + - uses: baptiste0928/cargo-install@v2.2.0 + with: + crate: cocogitto + + - name: Verify PR title follows conventional commit standards + id: pr_title_check + if: ${{ github.event_name == 'pull_request_target' }} + shell: bash + env: + TITLE: ${{ github.event.pull_request.title }} + continue-on-error: true + run: cog verify "$TITLE" + + - name: Verify commit message follows conventional commit standards + id: commit_message_check + if: ${{ github.event_name == 'merge_group' }} + shell: bash + # Fail on error, we don't have context about PR information to update labels + continue-on-error: false + run: cog verify '${{ github.event.merge_group.head_commit.message }}' + + # GitHub CLI returns a successful error code even if the PR has the label already attached + - name: Attach 'S-conventions-not-followed' label if PR title check failed + if: ${{ github.event_name == 'pull_request_target' && steps.pr_title_check.outcome == 'failure' }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + gh --repo ${{ github.event.repository.full_name }} pr edit --add-label 'S-conventions-not-followed' ${{ github.event.pull_request.number }} + echo "::error::PR title does not follow conventional commit standards" + exit 1 + + # GitHub CLI returns a successful error code even if the PR does not have the label attached + - name: Remove 'S-conventions-not-followed' label if PR title check succeeded + if: ${{ github.event_name == 'pull_request_target' && steps.pr_title_check.outcome == 'success' }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: gh --repo ${{ github.event.repository.full_name }} pr edit --remove-label 'S-conventions-not-followed' ${{ github.event.pull_request.number }} From a5e7cc4c6a30838ba2acf21f2e9466b64618380a Mon Sep 17 00:00:00 2001 From: Jeeva Ramachandran <120017870+JeevaRamu0104@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:47:48 +0530 Subject: [PATCH 2/2] feat: add pr title check workflow (#30) --- .github/workflows/pr-title-spell-check.yml | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/pr-title-spell-check.yml diff --git a/.github/workflows/pr-title-spell-check.yml b/.github/workflows/pr-title-spell-check.yml new file mode 100644 index 000000000..03b5a8758 --- /dev/null +++ b/.github/workflows/pr-title-spell-check.yml @@ -0,0 +1,27 @@ +name: PR Title Spell Check + +on: + pull_request: + types: + - opened + - edited + - synchronize + +jobs: + typos: + name: Spell check PR title + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Store PR title in a file + shell: bash + env: + TITLE: ${{ github.event.pull_request.title }} + run: echo $TITLE > pr_title.txt + + - name: Spell check + uses: crate-ci/typos@master + with: + files: ./pr_title.txt