diff --git a/.github/workflows/fossa.yml b/.github/workflows/fossa.yml new file mode 100644 index 0000000..8f618c3 --- /dev/null +++ b/.github/workflows/fossa.yml @@ -0,0 +1,77 @@ +name: FOSSA license scan + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} + +permissions: + contents: read + +jobs: + fossa: + name: FOSSA license scan + runs-on: ubuntu-latest + timeout-minutes: 15 + env: + FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # Forks and repos without the secret skip the scan instead of failing + # the check on a missing input; the scan activates once FOSSA_API_KEY is set. + - name: Skip when FOSSA_API_KEY is not configured + if: env.FOSSA_API_KEY == '' + run: echo "FOSSA_API_KEY secret not set; skipping FOSSA scan." >> "$GITHUB_STEP_SUMMARY" + + # The key must be a push-only token from the *CNCF* FOSSA organization so + # the project lands in the CNCF instance (cncf/sandbox#545). `team` takes + # the team NAME, not the numeric id, and is honored only on the very first + # upload that creates the project (fossa-cli docs/references/files/fossa-yml.md). + # With `run-tests: true` the action runs ONLY `fossa test` (no analyze) + # and forwards `team`/`branch` to it, which `fossa test` rejects. So: + # always analyze (upload), then on PRs run the policy test separately. + - name: Run FOSSA scan + if: env.FOSSA_API_KEY != '' + uses: fossas/fossa-action@29693cc50323968e039056be419b32989fc5880c # v2.0.0 + with: + api-key: ${{ secrets.FOSSA_API_KEY }} + project: hivecommons/hivecommons.github.io + team: Hive Commons + branch: ${{ github.head_ref || github.ref_name }} + + # Policy test on PRs. The diff test compares against the base commit's + # scan; a repo whose base was never scanned (new project, or the base + # push scan did not run) has no such revision, and `fossa test --diff` + # fails with "Revision for locator ... was not found". Only in that + # specific case fall back to a plain `fossa test` of the PR revision just + # uploaded above. Any other failure (including real policy violations + # from either test) still fails the job. Reuses the CLI installed by the + # Run FOSSA scan step. + - name: Run FOSSA policy test + if: env.FOSSA_API_KEY != '' && github.event_name == 'pull_request' + env: + FOSSA_BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: | + set +e + out="$(fossa test --project hivecommons/hivecommons.github.io --diff "$FOSSA_BASE_SHA" 2>&1)" + rc=$? + printf '%s\n' "$out" + if [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q 'was not found'; then + echo "Base revision $FOSSA_BASE_SHA has no FOSSA scan; testing the PR revision without --diff." + echo "FOSSA base revision has no scan; policy test ran on the PR revision without diff." >> "$GITHUB_STEP_SUMMARY" + fossa test --project hivecommons/hivecommons.github.io + rc=$? + fi + exit "$rc" diff --git a/README.md b/README.md index 0bb5a2f..44f24f9 100644 --- a/README.md +++ b/README.md @@ -485,6 +485,8 @@ requirements first (see [issue #73](https://github.com/hivecommons/hivecommons.g **OpenSSF Scorecard** (`.github/workflows/scorecard.yml`) — Runs OpenSSF security scorecard analysis on every push to `main`, weekly (cron `23 5 * * 1`), and on manual dispatch from the Actions tab. Results are published to GitHub's code scanning dashboard. +**FOSSA license scan** (`.github/workflows/fossa.yml`) — Uploads the repository to the CNCF FOSSA instance on every push to `main` and every pull request targeting `main`, and on manual dispatch from the Actions tab. Pull requests also run a license policy test. The scan is skipped when the `FOSSA_API_KEY` secret is not configured. + **Close linked issues** (`.github/workflows/close-linked-issues.yml`) — Automatically closes issues linked to a closed pull request when a PR transitions to `closed`. **Incident response** — When a bad deploy or incident impacts visitors of `hivecommons.dev` (broken pages, dead redirects, domain issues), use the [postmortem template](runbooks/postmortem-template.md) to document it blamelessly and fact-based. Coordinate recovery using the [release-rollback runbook](runbooks/release-rollback.md).