|
| 1 | +name: DTS Compliance Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "**/*.dts" |
| 7 | + - "**/*.dtsi" |
| 8 | + - "**/*.overlay" |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + files: |
| 12 | + description: "Comma-separated list of DTS files to lint" |
| 13 | + required: false |
| 14 | + default: "" |
| 15 | + logLevel: |
| 16 | + description: "Log level for dts-linter (none | verbose)" |
| 17 | + required: false |
| 18 | + default: "none" |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + dts-compliance: |
| 25 | + name: DTS Compliance Check |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 |
| 36 | + with: |
| 37 | + node-version: "20" |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: npm i -g dts-linter@0.0.0-alpha10 |
| 41 | + |
| 42 | + - name: Determine DTS files to format |
| 43 | + id: find-files |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | +
|
| 48 | + # Manual input from workflow_dispatch |
| 49 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.files }}" ]]; then |
| 50 | + echo "Using manually provided files..." |
| 51 | + echo "${{ github.event.inputs.files }}" | tr ',' '\n' | sed 's|^ *||;s| *$||' > dts-files-rel.txt |
| 52 | +
|
| 53 | + echo "Resolving absolute paths for manually provided files..." |
| 54 | + while IFS= read -r file; do |
| 55 | + if [ -f "$file" ]; then |
| 56 | + realpath "$file" |
| 57 | + else |
| 58 | + echo "Warning: File '$file' does not exist!" >&2 |
| 59 | + fi |
| 60 | + done < dts-files-rel.txt > dts-files.txt |
| 61 | + else |
| 62 | + echo "Detecting changed DTS files..." |
| 63 | +
|
| 64 | + # For PRs, get the diff from the base branch |
| 65 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 66 | + git fetch origin "$GITHUB_BASE_REF" |
| 67 | + git diff --name-only origin/"$GITHUB_BASE_REF"...HEAD | grep -E '\.dts$|\.dtsi$|\.overlay$' > dts-files-rel.txt || true |
| 68 | + else |
| 69 | + # For pushes, get the files changed in the last commit |
| 70 | + git diff --name-only HEAD~1 | grep -E '\.dts$|\.dtsi$|\.overlay$' > dts-files-rel.txt || true |
| 71 | + fi |
| 72 | +
|
| 73 | + echo "Resolving absolute paths for changed files..." |
| 74 | + while IFS= read -r file; do |
| 75 | + if [ -f "$file" ]; then |
| 76 | + realpath "$file" |
| 77 | + fi |
| 78 | + done < dts-files-rel.txt > dts-files.txt |
| 79 | + fi |
| 80 | +
|
| 81 | + if [ ! -s dts-files.txt ]; then |
| 82 | + echo "No DTS files found to lint." |
| 83 | + echo "empty=true" >> "$GITHUB_OUTPUT" |
| 84 | + else |
| 85 | + echo "Found DTS files:" |
| 86 | + cat dts-files.txt |
| 87 | + echo "empty=false" >> "$GITHUB_OUTPUT" |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Run DTS Linter |
| 91 | + if: steps.find-files.outputs.empty != 'true' |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + set -euo pipefail |
| 95 | + mapfile -t FILES < dts-files.txt |
| 96 | +
|
| 97 | + echo "Resolving absolute paths for bindings and includes..." |
| 98 | + BINDINGS=$(realpath dts/bindings) |
| 99 | + INCLUDES=( |
| 100 | + "$(realpath dts)" |
| 101 | + "$(realpath dts/arm)" |
| 102 | + "$(realpath dts/arm64)" |
| 103 | + "$(realpath dts/riscv)" |
| 104 | + "$(realpath dts/common)" |
| 105 | + "$(realpath dts/vendor)" |
| 106 | + "$(realpath include)" |
| 107 | + ) |
| 108 | +
|
| 109 | + FILE_ARGS=$(printf -- '--files %s ' "${FILES[@]}") |
| 110 | + INCLUDE_ARGS=$(printf -- '--includes %s ' "${INCLUDES[@]}") |
| 111 | +
|
| 112 | + LOG_LEVEL="${{ github.event.inputs.logLevel || 'none' }}" |
| 113 | + CMD="dts-linter --outFile ./diff --bindings $BINDINGS $INCLUDE_ARGS --formatting --diagnostics --logLevel $LOG_LEVEL $FILE_ARGS" |
| 114 | +
|
| 115 | + echo "Running dts-linter with command:" |
| 116 | + echo "$CMD" |
| 117 | +
|
| 118 | + set +e |
| 119 | + eval "$CMD" |
| 120 | + EXIT_CODE=$? |
| 121 | + set -e |
| 122 | +
|
| 123 | + echo "Linter finished with exit code: $EXIT_CODE" |
| 124 | + echo "EXIT_CODE=$EXIT_CODE" >> $GITHUB_ENV |
| 125 | + - name: Upload diff artifact |
| 126 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 127 | + with: |
| 128 | + name: dts-diff |
| 129 | + path: ./diff |
| 130 | + |
| 131 | + - name: Fail if linter failed |
| 132 | + if: env.EXIT_CODE == '1' |
| 133 | + run: exit 1 |
0 commit comments