From 895c5931ea43f6f532af7205b442c1e1fb86f481 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Fri, 8 Mar 2024 15:29:53 +0530 Subject: [PATCH] feat: release management fix --- .github/workflows/CI-Action.yml | 11 ++- .github/workflows/PULL_REQUEST_TEMPLATE.md | 41 +++++++++ .../workflows/conventional-commit-check.yml | 86 +++++++++++++++++++ .github/workflows/pr-title-spell-check.yml | 28 ++++++ .husky/prepare-commit-msg | 22 +---- 5 files changed, 166 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/conventional-commit-check.yml create mode 100644 .github/workflows/pr-title-spell-check.yml diff --git a/.github/workflows/CI-Action.yml b/.github/workflows/CI-Action.yml index fab191d64..c692b7099 100644 --- a/.github/workflows/CI-Action.yml +++ b/.github/workflows/CI-Action.yml @@ -1,6 +1,8 @@ name: CI/CD Pipeline on: + pull_request: + merge_group: push: branches: - main @@ -24,11 +26,14 @@ jobs: - name: Install dependencies run: npm install - - name: Install fast-glob - run: npm install fast-glob - - name: Display Node.js version run: node --version + - name: "Rescript Code Compile" + run: npm run re:build + + - name: "Build" + run: npm run build + - name: npm release run: npx semantic-release --debug; diff --git a/.github/workflows/PULL_REQUEST_TEMPLATE.md b/.github/workflows/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..c91742e85 --- /dev/null +++ b/.github/workflows/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,41 @@ +## Type of Change + + + +- [ ] Bugfix +- [ ] New feature +- [ ] Enhancement +- [ ] Refactoring +- [ ] Dependency updates +- [ ] Documentation +- [ ] CI/CD + +## Description + + + +## Motivation and Context + + + +## How did you test it? + + + +## Checklist + + + +- [ ] I ran `npm run re:build` +- [ ] I reviewed submitted code +- [ ] I added unit tests for my changes where possible 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 }} diff --git a/.github/workflows/pr-title-spell-check.yml b/.github/workflows/pr-title-spell-check.yml new file mode 100644 index 000000000..424b18127 --- /dev/null +++ b/.github/workflows/pr-title-spell-check.yml @@ -0,0 +1,28 @@ +name: PR Title Spell Check + +on: + merge_group: + 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 diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index f78a1b8a3..b74e18a25 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -4,27 +4,11 @@ # This hook triggers Jira input modules. # Helps in maintaining code compatblity. -# JS Code Check -echo "*****~~~~~ Checking ReScript Code ~~~~~~*****" -if (! npm run re:build) -then - echo - echo "*****~~~~~ ReScript Code Compilation Failed! ~~~~~*****" - exit 1 -fi -echo "***** ReScript Code Compiled! *****" +echo "*****~~~~~ Commit hook initiated ~~~~~~*****" -# JS Code Build -echo "*****~~~~~ Checking ReScript Build ~~~~~~*****" -if (! npm run build) -then - echo - echo "*****~~~~~ ReScript Build Completition Failed! ~~~~~*****" - exit 1 -fi -echo "***** ReScript Build Completed! *****" #Trailing Space Check +echo echo "Evaluating for trailing spaces" find . -type f -name '.DS_Store' -exec rm {} + @@ -40,7 +24,7 @@ then echo "Usage of EditorConfig [https://editorconfig.org/#download] plugin is recommended for development " exit 1 fi - +echo echo "Done Evaluating" BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')