Repository navigation
[docs] Document global template sources in the CLI #2199
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Forbidden Words | |
| on: | |
| pull_request: | |
| branches: [main, release/*] | |
| # Re-run for label changes so maintainers can override a false positive | |
| # without pushing another commit, and restore enforcement if it is removed. | |
| types: [opened, synchronize, reopened, labeled, unlabeled] | |
| workflow_dispatch: | |
| inputs: | |
| base_sha: | |
| description: "Base SHA to diff from (defaults to origin/<default branch>)" | |
| required: false | |
| head_sha: | |
| description: "Head SHA to diff to (defaults to HEAD)" | |
| required: false | |
| # Group by PR so new commits cancel the in-flight run for the same PR. | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| permissions: | |
| contents: read | |
| jobs: | |
| forbidden-words: | |
| name: Check forbidden words | |
| runs-on: ubuntu-latest | |
| env: | |
| # Directory where findings are written for the suggestion workflow. | |
| FINDINGS_DIR: forbidden-words-out | |
| BYPASS_LABEL: ci:skip-forbidden-words | |
| BYPASS_FORBIDDEN_WORDS: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci:skip-forbidden-words') }} | |
| steps: | |
| - name: Acknowledge bypass label | |
| if: ${{ env.BYPASS_FORBIDDEN_WORDS == 'true' }} | |
| shell: bash | |
| run: | | |
| mkdir -p "$FINDINGS_DIR" | |
| printf '{"findings":[]}\n' > "$FINDINGS_DIR/findings.json" | |
| echo "::notice title=Forbidden-words check bypassed::The $BYPASS_LABEL label is applied to this pull request." | |
| { | |
| echo "### Forbidden-words check bypassed" | |
| echo | |
| echo "The \`$BYPASS_LABEL\` label is applied to this pull request." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| if: ${{ env.BYPASS_FORBIDDEN_WORDS != 'true' }} | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve base and head SHAs | |
| id: shas | |
| if: ${{ env.BYPASS_FORBIDDEN_WORDS != 'true' }} | |
| shell: bash | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| INPUT_BASE_SHA: ${{ github.event.inputs.base_sha }} | |
| INPUT_HEAD_SHA: ${{ github.event.inputs.head_sha }} | |
| run: | | |
| if [[ "$EVENT_NAME" == "pull_request" ]]; then | |
| base="$PR_BASE_SHA" | |
| head="$PR_HEAD_SHA" | |
| else | |
| base="$INPUT_BASE_SHA" | |
| head="${INPUT_HEAD_SHA:-$(git rev-parse HEAD)}" | |
| if [[ -z "$base" ]]; then | |
| git fetch origin "${GITHUB_REF_NAME}" || true | |
| base="$(git rev-parse "origin/${GITHUB_REF_NAME}" 2>/dev/null || git rev-parse HEAD~1)" | |
| else | |
| git fetch origin "$base" || true | |
| fi | |
| fi | |
| echo "base=$base" >> "$GITHUB_OUTPUT" | |
| echo "head=$head" >> "$GITHUB_OUTPUT" | |
| - name: Test scanner | |
| if: ${{ env.BYPASS_FORBIDDEN_WORDS != 'true' }} | |
| run: bash tests/scripts/test-forbidden-words.sh | |
| # Scan runs with continue-on-error so we can still publish findings (for the | |
| # suggestion workflow) before the gate step fails the check. | |
| - name: Scan added lines for forbidden words | |
| id: scan | |
| if: ${{ env.BYPASS_FORBIDDEN_WORDS != 'true' }} | |
| continue-on-error: true | |
| shell: bash | |
| run: | | |
| mkdir -p "$FINDINGS_DIR" | |
| FINDINGS_FILE="$FINDINGS_DIR/findings.json" \ | |
| .github/scripts/check-forbidden-words.sh \ | |
| "${{ steps.shas.outputs.base }}" \ | |
| "${{ steps.shas.outputs.head }}" | |
| - name: Upload findings | |
| if: ${{ always() && github.event_name == 'pull_request' }} | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: forbidden-words-findings | |
| path: ${{ env.FINDINGS_DIR }} | |
| retention-days: 1 | |
| if-no-files-found: ignore | |
| - name: Fail when forbidden words are found | |
| if: always() | |
| shell: bash | |
| run: | | |
| if [[ "$BYPASS_FORBIDDEN_WORDS" == "true" ]]; then | |
| echo "Forbidden-word enforcement was bypassed by the $BYPASS_LABEL label." | |
| exit 0 | |
| fi | |
| if [[ "${{ steps.scan.outcome }}" != "success" ]]; then | |
| echo "::error::Forbidden words were found in added lines (or the scan failed). See the annotations above; inline suggestions are posted on the pull request where possible." | |
| exit 1 | |
| fi | |
| echo "No forbidden phrases found in added lines." |