|
| 1 | +name: "Validate PR Title" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - edited |
| 8 | + - synchronize |
| 9 | + |
| 10 | +permissions: |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-pr-title: |
| 15 | + name: Validate PR title |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: amannn/action-semantic-pull-request@v6.0.0 |
| 19 | + id: lint_pr_title |
| 20 | + env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - uses: marocchino/sticky-pull-request-comment@v2.0.0 |
| 24 | + # When the previous steps fails, the workflow would stop. By adding this |
| 25 | + # condition you can continue the execution with the populated error message. |
| 26 | + if: always() && (steps.lint_pr_title.outputs.error_message != null) |
| 27 | + with: |
| 28 | + header: pr-title-lint-error |
| 29 | + message: | |
| 30 | + Hey there and thank you for opening this pull request! 👋🏼 |
| 31 | +
|
| 32 | + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. |
| 33 | +
|
| 34 | + Details: |
| 35 | +
|
| 36 | + ``` |
| 37 | + ${{ steps.lint_pr_title.outputs.error_message }} |
| 38 | + ``` |
| 39 | +
|
| 40 | + # Delete a previous comment when the issue has been resolved |
| 41 | + - if: ${{ steps.lint_pr_title.outputs.error_message == null }} |
| 42 | + uses: marocchino/sticky-pull-request-comment@v2.0.0 |
| 43 | + with: |
| 44 | + header: pr-title-lint-error |
| 45 | + delete: true |
| 46 | + |
| 47 | + enforce-packages: |
| 48 | + name: Prevent new files in `equinix` package |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - uses: actions/github-script@v8.0.0 |
| 52 | + id: check_added_files |
| 53 | + with: |
| 54 | + result-encoding: string |
| 55 | + retries: 3 |
| 56 | + script: | |
| 57 | + const files = await github.paginate(github.rest.pulls.listFiles,{ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + pull_number: context.issue.number |
| 61 | + }) |
| 62 | +
|
| 63 | + const blockedFiles = [] |
| 64 | +
|
| 65 | + for (const file of files) { |
| 66 | + if (file.status === "added" && file.filename.match(/equinix\/[^\/]*\.go/)) { |
| 67 | + blockedFiles.push("- " + file.filename) |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | + var errorMessage = "" |
| 72 | +
|
| 73 | + if (blockedFiles.length > 0) { |
| 74 | + errorMessage = `The following files were added to the \`equinix\` package and must be moved somewhere else: |
| 75 | + ${blockedFiles.join("\n")} |
| 76 | + ` |
| 77 | + core.setFailed(errorMessage) |
| 78 | + } |
| 79 | +
|
| 80 | + return errorMessage |
| 81 | +
|
| 82 | + - uses: marocchino/sticky-pull-request-comment@v2.0.0 |
| 83 | + # When the previous steps fails, the workflow would stop. By adding this |
| 84 | + # condition you can continue the execution with the populated error message. |
| 85 | + if: always() && (steps.check_added_files.outputs.result != '') |
| 86 | + with: |
| 87 | + header: files-added-to-equinix-error |
| 88 | + message: | |
| 89 | + We are actively working to reduce the amount of code in the `equinix` |
| 90 | + package to avoid unintentional code sharing. |
| 91 | +
|
| 92 | + New files should be added in an isolated package instead of adding |
| 93 | + more code to the `equinix` package. You may need to refactor and/or |
| 94 | + temporarily duplicate existing code in order to move your new code |
| 95 | + to an isolated package. |
| 96 | +
|
| 97 | + Details: |
| 98 | +
|
| 99 | + ``` |
| 100 | + ${{ steps.check_added_files.outputs.result }} |
| 101 | + ``` |
| 102 | +
|
| 103 | + # Delete a previous comment when the issue has been resolved |
| 104 | + - if: steps.check_added_files.outputs.result == '' |
| 105 | + uses: marocchino/sticky-pull-request-comment@v2.0.0 |
| 106 | + with: |
| 107 | + header: files-added-to-equinix-error |
| 108 | + delete: true |
0 commit comments