|
| 1 | +name: linter |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + packages: read |
| 10 | + statuses: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + checkout: |
| 14 | + name: checkout |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + needs_c_cpp_linting: ${{ steps.check_extension.outputs.c_cpp }} |
| 18 | + needs_java_linting: ${{ steps.check_extension.outputs.java}} |
| 19 | + needs_javascript_linting: ${{ steps.check_extension.outputs.javascript }} |
| 20 | + needs_python_linting: ${{ steps.check_extension.outputs.python }} |
| 21 | + needs_other_linting: ${{ steps.check_extension.outputs.other }} |
| 22 | + steps: |
| 23 | + - name: Checking out the repo |
| 24 | + |
| 25 | + - name: Setup Python |
| 26 | + |
| 27 | + - name: Fetching PR Details |
| 28 | + run: | |
| 29 | + touch pr.json |
| 30 | + gh pr view $PR_NUMBER --json files > pr.json |
| 31 | + env: |
| 32 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 33 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + - name: Checking file extensions |
| 35 | + id: check_extension |
| 36 | + uses: jannekem/run-python-script-action@v1 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + import os |
| 40 | + import json |
| 41 | +
|
| 42 | + # Setting default variables |
| 43 | + checks = { lang:'false' for lang in ['c_cpp', 'java', 'javascript', 'python', 'other'] } |
| 44 | + c_cpp_ext = ['.c', '.cpp', '.h', '.hpp', '.cc', '.hh', '.cxx', '.hxx'] |
| 45 | +
|
| 46 | + # Reading contents of PR |
| 47 | + with open('pr.json','r') as json_file: |
| 48 | + data = json.load(json_file) |
| 49 | +
|
| 50 | + # Iterating over data |
| 51 | + for file in data["files"]: |
| 52 | + path = file["path"] |
| 53 | + |
| 54 | + # Ending loop if all are 'true' |
| 55 | + if all([val == 'true' for val in checks.values()]): |
| 56 | + break |
| 57 | +
|
| 58 | + # Checking for extensions |
| 59 | + if os.path.exists(path): |
| 60 | + for key,value in checks.items(): |
| 61 | + if value == 'true': |
| 62 | + continue |
| 63 | + if any([path.endswith(ext) for ext in c_cpp_ext]): |
| 64 | + checks['c_cpp']='true' |
| 65 | + elif path.endswith('.java'): |
| 66 | + checks['java']='true' |
| 67 | + elif path.endswith('.js'): |
| 68 | + checks['javascript']='true' |
| 69 | + elif path.endswith('.py'): |
| 70 | + checks['python']='true' |
| 71 | + elif '.' in path.split('/')[-1] and not path.endswith('.md'): |
| 72 | + checks['other']='true' |
| 73 | +
|
| 74 | + # Setting output variables based on file extensions |
| 75 | + for lang,val in checks.items(): |
| 76 | + os.system(f'echo "{lang}={val}" >> "$GITHUB_OUTPUT"') |
| 77 | +
|
| 78 | + c-cpp-linter: |
| 79 | + needs: [checkout] |
| 80 | + if: ${{ needs.checkout.outputs.needs_c_cpp_linting == 'true' }} |
| 81 | + uses: Grow-with-Open-Source/C-CPP-Projects/.github/workflows/c-cpp-linter.yml@main |
| 82 | + |
| 83 | + java-linter: |
| 84 | + needs: [checkout] |
| 85 | + if: ${{ needs.checkout.outputs.needs_java_linting == 'true' }} |
| 86 | + uses: Grow-with-Open-Source/Java-Projects/.github/workflows/java-linter.yml@main |
| 87 | + |
| 88 | + javascript-linter: |
| 89 | + needs: [checkout] |
| 90 | + if: ${{ needs.checkout.outputs.needs_javascript_linting == 'true' }} |
| 91 | + uses: Grow-with-Open-Source/Javascript-Projects/.github/workflows/javascript-linter.yml@main |
| 92 | + |
| 93 | + python-linter: |
| 94 | + needs: [checkout] |
| 95 | + if: ${{ needs.checkout.outputs.needs_python_linting == 'true' }} |
| 96 | + uses: Grow-with-Open-Source/Python-Projects/.github/workflows/python-linter.yml@main |
| 97 | + |
| 98 | + other-linter: |
| 99 | + needs: [checkout, c-cpp-linter, java-linter, javascript-linter, python-linter] |
| 100 | + if: ${{ |
| 101 | + always() && |
| 102 | + needs.checkout.outputs.needs_other_linting == 'true' || |
| 103 | + ((needs.c-cpp-linter.result == 'skipped' || needs.checkout.outputs.needs_c_cpp_linting == 'false') && |
| 104 | + (needs.java-linter.result == 'skipped' || needs.checkout.outputs.needs_java_linting == 'false') && |
| 105 | + (needs.javascript-linter.result == 'skipped' || needs.checkout.outputs.needs_javascript_linting == 'false') && |
| 106 | + (needs.python-linter.result == 'skipped' || needs.checkout.outputs.needs_python_linting == 'false')) |
| 107 | + }} |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - name: Checking out the repo |
| 111 | + |
| 112 | + with: |
| 113 | + fetch-depth: 0 |
| 114 | + ref: ${{ github.event.pull_request.head.ref }} |
| 115 | + - name: Super Linter |
| 116 | + uses: super-linter/[email protected] |
| 117 | + env: |
| 118 | + VALIDATE_ALL_CODEBASE: false |
| 119 | + DEFAULT_BRANCH: main |
| 120 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments