diff --git a/.github/workflows/auto_assign.yml b/.github/workflows/auto_assign.yml index 0d745b0..9199463 100644 --- a/.github/workflows/auto_assign.yml +++ b/.github/workflows/auto_assign.yml @@ -6,14 +6,18 @@ on: pull_request_target: types: [opened] -permissions: - issues: write - pull-requests: write +permissions: {} +# pull_request_target is safe here: nothing is checked out, and the only event +# data used is html_url, passed through env and quoted. jobs: auto-assign: name: Assign to Maintainer runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + issues: write + pull-requests: write steps: - name: Add assignee env: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e00c67..fde44dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,12 +19,14 @@ jobs: changes: name: Detect relevant changes runs-on: ubuntu-latest + timeout-minutes: 5 outputs: code: ${{ steps.filter.outputs.code }} steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false - name: Decide whether the rest of the workflow needs to run id: filter @@ -67,17 +69,20 @@ jobs: if: needs.changes.outputs.code == 'true' name: Build & Test runs-on: windows-latest + timeout-minutes: 30 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 with: go-version-file: go.mod cache: true - name: Install golangci-lint - run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2 + run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 - name: Verify golangci-lint config run: golangci-lint config verify @@ -88,6 +93,12 @@ jobs: - name: go vet run: go vet ./... + # Snyk was removed in #44; this is the dependency and stdlib vulnerability + # gate now. It reports only vulnerabilities whose code is reachable, and it + # runs on the Windows runner so the *_windows.go paths are what it analyses. + - name: govulncheck + run: go run golang.org/x/vuln/cmd/govulncheck@v1.10.0 ./... + # Generate the .syso files here too, so a malformed winres.json fails on the # PR rather than on a pushed tag. Versions stay at 0.0.0.0 — only release.yml # stamps the real ones. Keep the pin in sync with release.yml and the @@ -116,3 +127,16 @@ jobs: - name: go test run: go test ./... + # Flags newly added dependencies with known vulnerabilities or disallowed + # licences in the PR diff itself, before they reach main. + dependency-review: + name: Dependency review + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec # v5.0.1 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fb27a25..fad006b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,12 +9,19 @@ on: permissions: contents: read +# The tag reaches every shell step through $TAG rather than an inline +# ${{ github.ref_name }}, which would be pasted into the script text before +# bash parses it: git allows $, ( and backticks in tag names. +env: + TAG: ${{ github.ref_name }} + jobs: build: name: Build & Sign (${{ matrix.goarch }}) runs-on: ubuntu-latest + timeout-minutes: 30 permissions: - contents: write + contents: read # only the release job writes; these upload artifacts id-token: write # cosign OIDC token exchange + attestation attestations: write # actions/attest-build-provenance @@ -27,12 +34,23 @@ jobs: suffix: windows-arm64.exe steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Reject non-release tags + run: | + [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::tag '$TAG' is not vX.Y.Z"; exit 1; } + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 with: go-version-file: go.mod - cache: true + # A tag build must not restore a cache written by a main-branch run: + # Go trusts its module and build caches without re-checking them. + cache: false + + - name: Verify module checksums + run: go mod verify - name: Install go-winres run: go install github.com/tc-hib/go-winres@v0.3.3 @@ -62,26 +80,26 @@ jobs: run: | go build \ -trimpath \ - -ldflags="-X github.com/michaelsanford/wtop/internal/version.Version=${{ github.ref_name }}" \ - -o wtop-${{ github.ref_name }}-${{ matrix.suffix }} \ + -ldflags="-X github.com/michaelsanford/wtop/internal/version.Version=${TAG}" \ + -o wtop-${TAG}-${{ matrix.suffix }} \ ./cmd/wtop/ - name: Attest build provenance - uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0 + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 with: subject-path: wtop-${{ github.ref_name }}-${{ matrix.suffix }} - name: Install cosign - uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2 + uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4.1.4 - name: Sign with cosign (keyless, GitHub OIDC) run: | cosign sign-blob --yes \ - wtop-${{ github.ref_name }}-${{ matrix.suffix }} \ - --bundle wtop-${{ github.ref_name }}-${{ matrix.suffix }}.bundle + wtop-${TAG}-${{ matrix.suffix }} \ + --bundle wtop-${TAG}-${{ matrix.suffix }}.bundle - name: Upload artifacts - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: binary-${{ matrix.goarch }} path: | @@ -91,48 +109,73 @@ jobs: sbom: name: Generate & Sign SBOM runs-on: ubuntu-latest + timeout-minutes: 20 needs: build permissions: - contents: write + contents: read # only the release job writes; these upload artifacts id-token: write # cosign OIDC token exchange + attestation attestations: write # actions/attest-build-provenance steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 with: go-version-file: go.mod - cache: true + # A tag build must not restore a cache written by a main-branch run: + # Go trusts its module and build caches without re-checking them. + cache: false + + - name: Verify module checksums + run: go mod verify - name: Install cyclonedx-gomod - run: go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.9.0 + run: go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.12.0 - name: Generate CycloneDX SBOM run: | cyclonedx-gomod app \ -licenses \ -json \ - -output wtop-${{ github.ref_name }}-sbom.cdx.json \ + -output wtop-${TAG}-sbom.cdx.json \ -main ./cmd/wtop \ . - name: Attest build provenance - uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0 + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 with: subject-path: wtop-${{ github.ref_name }}-sbom.cdx.json + # Provenance on the SBOM file says where it came from, not what it + # describes. An SBOM attestation binds it to the binaries themselves, so + # gh attestation verify --predicate-type https://cyclonedx.org/bom works + # on the .exe. + - name: Download the binaries the SBOM describes + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: binary-* + path: bin/ + merge-multiple: true + + - name: Attest SBOM against the binaries + uses: actions/attest-sbom@c604332985a26aa8cf1bdc465b92731239ec6b9e # v4.1.0 + with: + subject-path: bin/*.exe + sbom-path: wtop-${{ github.ref_name }}-sbom.cdx.json + - name: Install cosign - uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2 + uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4.1.4 - name: Sign with cosign (keyless, GitHub OIDC) run: | cosign sign-blob --yes \ - wtop-${{ github.ref_name }}-sbom.cdx.json \ - --bundle wtop-${{ github.ref_name }}-sbom.cdx.json.bundle + wtop-${TAG}-sbom.cdx.json \ + --bundle wtop-${TAG}-sbom.cdx.json.bundle - name: Upload SBOM artifact - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: sbom path: | @@ -143,43 +186,59 @@ jobs: name: Create Draft Release needs: [build, sbom] runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: write issues: write + id-token: write # attestation of SHA256SUMS + attestations: write steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Download all artifacts - uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: path: assets/ merge-multiple: true - name: Create release zip archive run: | - ZIP_NAME="wtop-${{ github.ref_name }}-windows.zip" + ZIP_NAME="wtop-${TAG}-windows.zip" # Package all release artifacts (binaries, cosign bundles, SBOM), LICENSE, and README zip -j "assets/${ZIP_NAME}" \ assets/* \ LICENSE \ README.md + # Written after the zip so it covers the zip too, which otherwise has no + # signature or attestation of its own. Attesting the checksum file gives + # every asset build provenance in one step. + - name: Write SHA256SUMS + working-directory: assets + run: sha256sum -- * > SHA256SUMS + + - name: Attest every release asset + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-checksums: assets/SHA256SUMS + - name: Create draft GitHub Release env: GH_TOKEN: ${{ github.token }} run: | - gh release create "${{ github.ref_name }}" \ + gh release create "${TAG}" \ assets/* \ --repo "${{ github.repository }}" \ - --title "${{ github.ref_name }}" \ + --title "${TAG}" \ --generate-notes \ --draft - name: Open WDSI submission tracking issue env: GH_TOKEN: ${{ github.token }} - TAG: ${{ github.ref_name }} REPO: ${{ github.repository }} run: | RELEASE_URL="https://github.com/${REPO}/releases/tag/${TAG}" diff --git a/.github/workflows/winget-track.yml b/.github/workflows/winget-track.yml index 4faaaf8..4c57a37 100644 --- a/.github/workflows/winget-track.yml +++ b/.github/workflows/winget-track.yml @@ -10,10 +10,7 @@ on: - cron: '0 * * * *' # hourly workflow_dispatch: -permissions: - contents: read - issues: write - actions: write +permissions: {} env: PACKAGE_ID: michaelsanford.wtop @@ -27,6 +24,11 @@ jobs: close: name: Reconcile winget trackers runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + issues: write # tracker comments and closes + actions: write # disables this workflow when no trackers remain steps: - name: Resolve, promote and close winget trackers env: @@ -167,7 +169,10 @@ jobs: if [ -n "$PR_COMMENTS" ] && [ "$PR_COMMENTS" != "[]" ]; then while read -r comment; do CID=$(echo "$comment" | jq -r '.id') - C_BODY=$(echo "$comment" | jq -r '.body') + # Anyone can comment on a winget-pkgs PR; only the validation bots' + # comments are mirrored, with @-mentions defused, so a stranger + # cannot post phishing links or pings that appear to come from here. + C_BODY=$(echo "$comment" | jq -r '.body' | sed 's/@/@\​/g') echo "$C_BODY" | grep -qiE "(Inconsistencies detected|Failed|Error|Reject|Missing|Validation Failed)" || continue echo "$EXISTING_COMMENTS" | grep -Fq "Comment #$CID" && continue @@ -180,7 +185,7 @@ jobs: gh issue comment "$NUM" --repo "$REPO" --body "$FAILURE_COMMENT" EXISTING_COMMENTS=$(printf '%s\n%s\n' "$EXISTING_COMMENTS" "$FAILURE_COMMENT") echo "Issue #$NUM: forwarded downstream comment #$CID." - done < <(echo "$PR_COMMENTS" | jq -c '.[]') + done < <(echo "$PR_COMMENTS" | jq -c '.[] | select(.user.type == "Bot" or .user.login == "wingetbot")') fi done < <(echo "$TRACKERS") diff --git a/.github/workflows/winget.yml b/.github/workflows/winget.yml index 8907ded..358a568 100644 --- a/.github/workflows/winget.yml +++ b/.github/workflows/winget.yml @@ -18,10 +18,11 @@ jobs: winget-update: name: Submit winget package update runs-on: windows-latest + timeout-minutes: 30 steps: - name: Submit to winget - uses: vedantmgoyal9/winget-releaser@4ffc7888bffd451b357355dc214d43bb9f23917e # v2 + uses: vedantmgoyal9/winget-releaser@4ffc7888bffd451b357355dc214d43bb9f23917e # v2 branch, untagged commit of 2024-11-27 with: identifier: ${{ env.PACKAGE_ID }} installers-regex: '\.exe$' @@ -31,6 +32,7 @@ jobs: name: Draft downstream PR and open tracker needs: winget-update runs-on: ubuntu-latest + timeout-minutes: 15 if: github.event_name == 'release' # tag_name only exists on release events permissions: contents: read # release compare API diff --git a/.run/Lint (golangci-lint).run.xml b/.run/Lint (golangci-lint).run.xml index 45b3891..712d1d7 100644 --- a/.run/Lint (golangci-lint).run.xml +++ b/.run/Lint (golangci-lint).run.xml @@ -1,6 +1,6 @@ -