|
| 1 | +# CI for the handbook itself: markdown, YAML, GitHub Actions, and Semgrep |
| 2 | +# rule validation. Educational CI templates under devsecops/ci-templates/ |
| 3 | +# are validated structurally by actionlint; they are not executed here. |
| 4 | +# |
| 5 | +# Action references are version tags by default. Dependabot is configured |
| 6 | +# in .github/dependabot.yml and will rewrite them as `<sha> # vN.M.K` in |
| 7 | +# follow-up PRs as updates roll in. This mirrors the supply-chain guidance |
| 8 | +# the handbook gives in devsecops/ci-templates/. |
| 9 | + |
| 10 | +name: ci |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main] |
| 15 | + pull_request: |
| 16 | + branches: [main] |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: ci-${{ github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + markdownlint: |
| 27 | + name: markdownlint |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + - name: Run markdownlint-cli2 |
| 33 | + uses: DavidAnson/markdownlint-cli2-action@v18 |
| 34 | + with: |
| 35 | + globs: | |
| 36 | + **/*.md |
| 37 | + !**/node_modules/** |
| 38 | +
|
| 39 | + yamllint: |
| 40 | + name: yamllint |
| 41 | + runs-on: ubuntu-24.04 |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v5 |
| 47 | + with: |
| 48 | + python-version: "3.12" |
| 49 | + - name: Install yamllint |
| 50 | + run: pip install --no-cache-dir 'yamllint==1.35.1' |
| 51 | + - name: Run yamllint |
| 52 | + # Relaxed config: long lines and missing document-start markers are |
| 53 | + # acceptable in educational YAML snippets. Real violations |
| 54 | + # (truthy, indentation, trailing-spaces) still fail. |
| 55 | + run: | |
| 56 | + yamllint --strict -d '{ |
| 57 | + extends: default, |
| 58 | + rules: { |
| 59 | + line-length: {max: 120, level: warning}, |
| 60 | + document-start: disable, |
| 61 | + comments-indentation: disable, |
| 62 | + truthy: {allowed-values: ["true", "false"], check-keys: false} |
| 63 | + } |
| 64 | + }' devsecops/ .github/ |
| 65 | +
|
| 66 | + actionlint: |
| 67 | + name: actionlint |
| 68 | + runs-on: ubuntu-24.04 |
| 69 | + steps: |
| 70 | + - name: Checkout |
| 71 | + uses: actions/checkout@v4 |
| 72 | + - name: Install actionlint |
| 73 | + # Uses the official installer script from the actionlint repository, |
| 74 | + # which downloads a release binary matching the pinned version. |
| 75 | + # Replace the version-only pin with a release binary checksum if you |
| 76 | + # need stricter supply-chain assurances; see the handbook's own |
| 77 | + # devsecops/ci-templates/ for that pattern. |
| 78 | + run: | |
| 79 | + bash <(curl -sSL https://raw.githubusercontent.com/rhysd/actionlint/v1.7.7/scripts/download-actionlint.bash) 1.7.7 |
| 80 | + echo "ACTIONLINT_BIN=$(pwd)/actionlint" >> "$GITHUB_ENV" |
| 81 | + - name: Lint handbook workflows |
| 82 | + run: | |
| 83 | + "$ACTIONLINT_BIN" -color .github/workflows/*.yml |
| 84 | + - name: Lint educational templates (advisory) |
| 85 | + # Educational templates may intentionally omit elements (for example, |
| 86 | + # `permissions:` is sometimes shown in a later step of the prose). |
| 87 | + # Treat findings as advisory so they do not block contributions. |
| 88 | + continue-on-error: true |
| 89 | + run: | |
| 90 | + if compgen -G "devsecops/ci-templates/github-actions/*.yml" > /dev/null; then |
| 91 | + "$ACTIONLINT_BIN" -color devsecops/ci-templates/github-actions/*.yml |
| 92 | + else |
| 93 | + echo "no github-actions templates found" |
| 94 | + fi |
| 95 | +
|
| 96 | + semgrep-rules: |
| 97 | + name: semgrep rule validate and test |
| 98 | + runs-on: ubuntu-24.04 |
| 99 | + steps: |
| 100 | + - name: Checkout |
| 101 | + uses: actions/checkout@v4 |
| 102 | + - name: Set up Python |
| 103 | + uses: actions/setup-python@v5 |
| 104 | + with: |
| 105 | + python-version: "3.12" |
| 106 | + - name: Install Semgrep |
| 107 | + run: pip install --no-cache-dir 'semgrep==1.96.0' |
| 108 | + - name: Validate rules |
| 109 | + run: semgrep --config devsecops/semgrep-rules/ --validate |
| 110 | + - name: Test rules |
| 111 | + # Tests require <rule>.test.<ext> fixture files in semgrep's expected |
| 112 | + # layout. If no fixtures are present, this step is a no-op rather |
| 113 | + # than a failure: rule-test fixtures are tracked separately and may |
| 114 | + # be introduced after rules. The job still fails if fixtures exist |
| 115 | + # and tests fail. |
| 116 | + run: | |
| 117 | + if find devsecops/semgrep-rules -name '*.test.*' -print -quit | grep -q .; then |
| 118 | + semgrep --config devsecops/semgrep-rules/ --test |
| 119 | + else |
| 120 | + echo "no semgrep test fixtures found; skipping --test" |
| 121 | + fi |
0 commit comments