|
| 1 | +name: CI Lint |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: [master, 'stabilization*'] |
| 5 | +permissions: |
| 6 | + contents: read |
| 7 | +jobs: |
| 8 | + yamllint: |
| 9 | + name: Run yamllint on changed controls and profiles |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Install Git |
| 13 | + run: sudo apt-get update && sudo apt-get install -y git |
| 14 | + |
| 15 | + - name: Checkout CaC repo |
| 16 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 17 | + with: |
| 18 | + repository: ${{ github.repository }} |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Detect files changed by PR |
| 22 | + id: changed_files |
| 23 | + run: | |
| 24 | + repo=${{ github.repository }} |
| 25 | + pr_number=${{ github.event.pull_request.number }} |
| 26 | + # Fetch all pages of the files for the pull request |
| 27 | + url="repos/$repo/pulls/$pr_number/files" |
| 28 | + response=$(gh api "$url" --paginate) |
| 29 | + echo "$response" | jq -r '.[].filename' > filenames.txt |
| 30 | + cat filenames.txt |
| 31 | +
|
| 32 | + if grep "controls/" filenames.txt; then |
| 33 | + echo "CONTROLS_CHANGES=true" >> $GITHUB_ENV |
| 34 | + else |
| 35 | + echo "CONTROLS_CHANGES=false" >> $GITHUB_ENV |
| 36 | + fi |
| 37 | + if grep "\.profile" filenames.txt; then |
| 38 | + echo "PROFILES_CHANGES=true" >> $GITHUB_ENV |
| 39 | + else |
| 40 | + echo "PROFILES_CHANGES=false" >> $GITHUB_ENV |
| 41 | + fi |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Install yamllint |
| 46 | + if : ${{ env.CONTROLS_CHANGES == 'true' || env.PROFILES_CHANGES == 'true' }} |
| 47 | + run: pip install yamllint |
| 48 | + |
| 49 | + - name: Run yamllint in control files modified by PR |
| 50 | + if: ${{ env.CONTROLS_CHANGES == 'true' }} |
| 51 | + run: | |
| 52 | + for control_file in $(cat filenames.txt | grep "controls/"); do |
| 53 | + echo "Running yamllint on $control_file..." |
| 54 | + yamllint --no-warnings "$control_file" |
| 55 | + done |
| 56 | +
|
| 57 | + - name: Run yamllint in profile files modified by PR |
| 58 | + if: ${{ env.PROFILES_CHANGES == 'true' }} |
| 59 | + run: | |
| 60 | + for profile_file in $(cat filenames.txt | grep "\.profile"); do |
| 61 | + echo "Running yamllint on $profile_file..." |
| 62 | + yamllint --no-warnings "$profile_file" |
| 63 | + done |
0 commit comments