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