From 5263a3b889b858faf0e4d093bf1d85ef89b8756e Mon Sep 17 00:00:00 2001 From: krishnakumar Date: Tue, 3 Oct 2023 16:09:22 +0530 Subject: [PATCH] feat: add link chencking and naming global workflows for org --- .github/workflows/check-links.yml | 59 ++++++++++++ .github/workflows/pre-validate.yml | 139 +++++++++++++++++++++++++++++ pr-labels.yml | 42 +++++++++ 3 files changed, 240 insertions(+) create mode 100644 .github/workflows/check-links.yml create mode 100644 .github/workflows/pre-validate.yml create mode 100644 pr-labels.yml diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml new file mode 100644 index 0000000..3d25d70 --- /dev/null +++ b/.github/workflows/check-links.yml @@ -0,0 +1,59 @@ +name: Check-Links + +on: + workflow_call: + secrets: + token: + required: true + +concurrency: + group: link-checker-${{ github.repository }}-${{ github.head_ref }}-1 + cancel-in-progress: true + +env: + FAIL_ON_ERROR: ${{ github.event.schedule == '00 20 1-7 * SUN' || false }} + +jobs: + linkChecker: + runs-on: ubuntu-latest + steps: + - name: show + id: show-env + if: ${{ always() }} + run: | + echo "FAIL_ON_ERROR: ${{ env.FAIL_ON_ERROR }}" + echo "BRANCH: ${{ github.ref_name }}" + echo "SCHEDULE: ${{ github.event.schedule }}" + echo "SHA: ${{ github.sha }}" + + - name: Restore lychee cache + id: restore-lychee-cache + uses: actions/cache@v3 + with: + path: .lycheecache + key: cache-lychee-${{ github.sha }} + restore-keys: cache-lychee- + + - name: checkout + id: checkout + if: steps.restore-lychee-cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + env: + GITHUB_TOKEN: ${{ secrets.token }} + + - name: Link Checker Fail on Error - ${{ env.FAIL_ON_ERROR }} + id: lychee + uses: lycheeverse/lychee-action@v1.8.0 + with: + fail: ${{ env.FAIL_ON_ERROR }} + env: + GITHUB_TOKEN: ${{ secrets.token }} + + - name: Create Issue From File + id: create-issue + if: env.lychee_exit_code != 0 && github.ref_name == 'main' + uses: peter-evans/create-issue-from-file@v4 + with: + title: Link Checker Report + content-filepath: ./lychee/out.md + labels: report, automated issue \ No newline at end of file diff --git a/.github/workflows/pre-validate.yml b/.github/workflows/pre-validate.yml new file mode 100644 index 0000000..778ec89 --- /dev/null +++ b/.github/workflows/pre-validate.yml @@ -0,0 +1,139 @@ +name: Prevalidate + +on: + workflow_call: + secrets: + token: + required: true + inputs: + validate_changelog: + type: boolean + description: Whether to validate changelogs + required: false + default: false + triage: + type: boolean + description: Whether to perform automated triaging + required: false + default: false + +concurrency: + group: pre-validate-${{ github.repository }}-${{ github.event.pull_request.head.ref }}-1 + cancel-in-progress: true + +jobs: + checks: + runs-on: "ubuntu-latest" + # Ignore dependabot branches + if: ! startsWith(github.event.pull_request.head.ref, 'dependabot/') + + steps: + - name: Check out the repository + id: checkout + uses: actions/checkout@v3 + env: + GITHUB_TOKEN: ${{ secrets.token }} + with: + fetch-depth: 0 + persist-credentials: true + + - name: validate Branch Name + id: validate-branch-name + uses: deepakputhraya/action-branch-name@e0f8db53a8e289f1ae6f6c3e8dc70a3d366fd876 + with: + regex: '([a-z-0-9]{3,})\/([a-z0-9._-])+' # Regex the branch should match. + # This regex enforces grouping with a Jira ticket number and a lowercase subject + # so something like feat/pi-123/my-branch-for-my-cause would be a valid example + allowed_prefixes: "feat,fix,docs,style,refactor,perf,test,build,ci,chore,revert,deps,dependabot" # All branches should start with the given prefix + ignore: main # Ignore exactly matching branch names from convention + min_length: 4 # Min length of the branch name + max_length: 63 # Max length of the branch name + + - name: Verify Changelog Content + id: verify-changed-files + if: ${{ github.event.pull_request.base.ref == 'main' }} && ${{ inputs.validate_changelog == true }} + uses: tj-actions/changed-files@v37 + with: + since_last_remote_commit: false + files: | + Changelog.md + + - name: Verify Changelog was updated + id: verify-changelog-updated + if: ${{ github.event.pull_request.base.ref == 'main' }} && ${{ inputs.validate_changelog == true }} + run: | + if [ "${{ steps.verify-changed-files.outputs.any_changed }}" == "true" ]; then + echo "The Changelog.md file was updated" + else + echo "The Changelog.md file was not updated" + exit 1 + fi + + - name: Validate PR title + if: startsWith(github.event.pull_request.head.ref, 'dependabot/') + id: validate-title + uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54 + env: + GITHUB_TOKEN: ${{ secrets.token }} + with: + # Configure which types are allowed (newline delimited). + # Default: https://github.com/commitizen/conventional-commit-types + types: | + feat + fix + docs + style + refactor + perf + test + build + ci + chore + revert + deps + dependabot + # If the PR only contains a single commit, the action will validate that + # it matches the configured pattern. + validateSingleCommit: true + # For work-in-progress PRs you can typically use draft pull requests + # from GitHub. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true + # Configure additional validation for the subject based on a regex. + # This example ensures the subject doesn't start with an uppercase character. + # something like feat: PI-150 + subjectPattern: ^([a-z-A-Z]{2,3}[-0-9]{1,}[\s\|]*[\s]?)(.+)$ + # If `subjectPattern` is configured, you can use this property to override + # the default error message that is shown when the pattern doesn't match. + # The variables `subject` and `title` can be used within the message. + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + didn't match the configured pattern. + The regex pattern is "^([a-z-A-Z]{2,3}[-0-9]{1,}[\s\|]*[\s]?)(.+)$" and, + enforces use of a Jira ticket number followed by a (space/|) and subject in lowercase. + For example, a valid subject would be "LA-1234 | fixes something" or "LA-1234 fixes something" + + triage: + runs-on: "ubuntu-latest" + # Ignore dependabot branches + if: ! startsWith(github.event.pull_request.head.ref, 'dependabot/') && inputs.triage == 'true' + + permissions: + contents: read + pull-requests: write + steps: + - name: Label PR + id: label-pr + uses: TimonVS/pr-labeler-action@v4.1.1 + with: + repo-token: ${{ secrets.token }} + configuration-path: .github/pr-labels.yml + + - name: Assign PR + id: assign-pr + uses: samspills/assign-pr-to-author@v1.0.2 + with: + repo-token: "${{ secrets.token }}" \ No newline at end of file diff --git a/pr-labels.yml b/pr-labels.yml new file mode 100644 index 0000000..37390e5 --- /dev/null +++ b/pr-labels.yml @@ -0,0 +1,42 @@ +--- +# Label mappings for PRs +# Uses labels defined in .github/repo-labels.yml +# with branch name patterns defined in .github/workflows/pre-validate.yml +# Ref: https://github.com/marketplace/actions/pr-labeler +bug: + - "fix/*" +fix: + - "fix/*" +build: + - "build/*" +ci: + - "ci/*" +dependencies: + - "deps/*" +docs: + - "docs/*" +enhancement: + - "feat/*" + - "refactor/*" + - "perf/*" +github_actions: + - "ci/*" +perf: + - "perf/*" +python: + - "deps/*" +refactor: + - "refactor/*" +removal: + - "revert/*" +style: + - "style/*" +test: + - "test/*" +dependabot: + - "dependabot/*" +chore: + - "chore/*" + - "deps/*" + - "revert/*" + - "test/*" \ No newline at end of file