|
| 1 | +name: 'spmgraph lint' |
| 2 | +description: 'Lints the dependency graph of a local Package.swift' |
| 3 | +inputs: |
| 4 | + package-directory: |
| 5 | + description: The directory where the Package.swift file is located |
| 6 | + required: true |
| 7 | + verbose: |
| 8 | + description: Show extra logging for troubleshooting purposes. |
| 9 | + type: boolean |
| 10 | + default: false |
| 11 | + excluded-suffixes: |
| 12 | + description: Comma separated suffixes to exclude from the graph e.g. 'Tests','Live','TestSupport' |
| 13 | + required: false |
| 14 | + default: '' |
| 15 | + strict: |
| 16 | + description: Errors out on warnings and fail the check. |
| 17 | + type: boolean |
| 18 | + default: false |
| 19 | + adds-to-summary: |
| 20 | + description: Reports the lint errors in the action summary. |
| 21 | + type: boolean |
| 22 | + default: true |
| 23 | + summary-limit: |
| 24 | + description: | |
| 25 | + The maximum number of characters to include in the summary. Needed for the lint output to appear in the summary. |
| 26 | + GitHub Actions summary has a limit of 1mb and around 65k characters. |
| 27 | + See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#step-isolation-and-limits" |
| 28 | + type: number |
| 29 | + default: 50000 |
| 30 | + adds-pr-comment: |
| 31 | + description: Reports the lint errors in a PR comment. |
| 32 | + type: boolean |
| 33 | + default: false |
| 34 | + config-build-directory: |
| 35 | + description: > |
| 36 | + **For users that leverage the lint capability and rely on the `SPMGraphConfig.swift` file**. |
| 37 | + |
| 38 | + A custom build directory that enables CI controlling and caching of the package used to edit and load the SPMGraphConfig. |
| 39 | + It defaults to a temporary directory, which works consistently for local runs and CI with clean builds. |
| 40 | + |
| 41 | + - **Note**: Cache this directory in your CI and reuse whenever the `SPMGraphConfig.swift` is stable for reducing the build times. |
| 42 | + |
| 43 | + - **Warning**: Ensure this is consistent across commands, otherwise your configuration won't be correctly loaded! |
| 44 | + required: false |
| 45 | + |
| 46 | + # TODO: Support danger as option for PR comment, requires making it a Danger plugin |
| 47 | + |
| 48 | +runs: |
| 49 | + using: 'composite' |
| 50 | + steps: |
| 51 | + - id: lint-dependency-graph |
| 52 | + name: Run spmgraph lint |
| 53 | + run: | |
| 54 | + spmgraph lint ${{ inputs.package-directory }} ${{ inputs.verbose == 'true' && '-v' || '' }} ${{ inputs.excluded-suffixes && '--excludedSuffixes ${{ inputs.excluded-suffixes }}' || '' }} ${{ inputs.strict == 'true' && '--strict' || '' }} --output lint_output ${{ inputs.config-build-directory != '' && format('--config-build-directory "{0}"', inputs.config-build-directory) || '' }} |
| 55 | +
|
| 56 | + # Set boolean output to indicate if lint failed or not |
| 57 | + echo "lint-failed=$(cat $GITHUB_WORKSPACE/.spmgraph_lint_result.txt)" >> $GITHUB_OUTPUT |
| 58 | + shell: /bin/bash -e {0} |
| 59 | + |
| 60 | + - name: Write to workflow job summary |
| 61 | + if: ${{ always() && inputs.adds-to-summary == 'true' }} |
| 62 | + run: | |
| 63 | + lint_summary=$'# spmgraph lint\n## Results\n' |
| 64 | + echo "$lint_summary" >> $GITHUB_STEP_SUMMARY |
| 65 | + |
| 66 | + # Limit the output characters so it's more likely that it appears in the summary |
| 67 | + cat $GITHUB_WORKSPACE/lint_output.txt | head -c ${{ inputs.summary-limit }} >> $GITHUB_STEP_SUMMARY |
| 68 | +
|
| 69 | + output_warning=$'#### The output was truncated so that it does not surpass 1mb.' |
| 70 | + echo "$output_warning" >> $GITHUB_STEP_SUMMARY |
| 71 | + shell: /bin/bash -e {0} |
| 72 | + |
| 73 | + - name: Report warnings as a PR comment |
| 74 | + if: ${{ always() && inputs.adds-pr-comment == 'true' && steps.lint-dependency-graph.outputs.lint-failed == 'true' }} |
| 75 | + continue-on-error: true # Do not fail the workflow if the comment fails or if not a PR |
| 76 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 |
| 77 | + with: |
| 78 | + file-path: /Users/administrator/runner/_work/iOS/iOS/lint_output.txt |
| 79 | + comment-tag: lint-report # the same across runs, which updates the comment from previous runs |
| 80 | + |
| 81 | + - name: Report lint passed as a PR comment |
| 82 | + if: ${{ always() && inputs.adds-pr-comment == 'true' && steps.lint-dependency-graph.outputs.lint-failed == 'false' }} |
| 83 | + continue-on-error: true # Do not fail the workflow if the comment fails or if not a PR |
| 84 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 |
| 85 | + with: |
| 86 | + message: spmgraph lint found no errors! The dependency graph looks tidy ✨ |
| 87 | + comment-tag: lint-report # the same across runs, which updates the comment from previous runs |
0 commit comments