-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add abstract workflows for coverage, linting, testing, reuse, and scorecard #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7630c9e
feat: add abstract workflows for coverage, linting, testing, reuse, a…
seantronsen ae3624a
wip: address unnecessary flexibility comment
seantronsen 8acb6d6
wip: dedup permissions
seantronsen 9628ff6
wip: use explicit permissions in README for scorecard workflow
seantronsen c64b0b9
wip: address reuse nitpick
seantronsen 0874861
feat: add optional reuse CLI version parameter
seantronsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # SPDX-FileCopyrightText: 2025 OpenCHAMI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| name: coverage-go | ||
|
|
||
| # Reusable workflow that produces a Go coverage profile, writes the total | ||
| # to the job summary, and uploads the profile to Coveralls. | ||
| # | ||
| # The caller repo must be enrolled in Coveralls; the upload authenticates | ||
| # with the automatically-provided GITHUB_TOKEN. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| go_version: | ||
| description: 'Go version to use (e.g. "1.26.7", "stable"). Mutually exclusive with go_version_file.' | ||
| required: false | ||
| type: string | ||
| go_version_file: | ||
| description: 'Path to a go.mod or .go-version file containing the Go version. Mutually exclusive with go_version.' | ||
| required: false | ||
| type: string | ||
| coverage-command: | ||
| description: 'Command that writes the coverage profile to `coverage-file`' | ||
| required: false | ||
| type: string | ||
| default: 'go test -coverprofile=coverage.out ./...' | ||
| coverage-file: | ||
| description: 'Path to the coverage profile written by `coverage-command`' | ||
| required: false | ||
| type: string | ||
| default: 'coverage.out' | ||
|
|
||
| permissions: | ||
| contents: read # baseline for checkout | ||
|
|
||
| jobs: | ||
| coverage-go: | ||
| name: coverage-go | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| with: | ||
| go-version: ${{ inputs.go_version || (inputs.go_version_file == '' && 'stable' || '') }} | ||
| go-version-file: ${{ inputs.go_version_file || '' }} | ||
|
|
||
| - name: Run tests with coverage | ||
| env: | ||
| COVERAGE_COMMAND: ${{ inputs.coverage-command }} | ||
| run: eval "$COVERAGE_COMMAND" | ||
|
|
||
| - name: Report total coverage | ||
| env: | ||
| COVERAGE_FILE: ${{ inputs.coverage-file }} | ||
| run: | | ||
| total=$(go tool cover -func="$COVERAGE_FILE" | awk '/^total:/ {print $3}') | ||
| echo "Total coverage: ${total}" | tee -a "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Upload coverage to Coveralls | ||
| uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 | ||
| with: | ||
| file: ${{ inputs.coverage-file }} | ||
| format: golang | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # SPDX-FileCopyrightText: 2025 OpenCHAMI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| name: lint-go | ||
|
|
||
| # Reusable workflow that lints the caller's Go module. Runs golangci-lint, | ||
| # and separately verifies go.mod/go.sum are tidy by running the tidy | ||
| # command and failing on a dirty diff. | ||
| # | ||
| # Pair with test-go for the unit-test half of the Go CI wave. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| go_version: | ||
| description: 'Go version to use (e.g. "1.26.7", "stable"). Mutually exclusive with go_version_file.' | ||
| required: false | ||
| type: string | ||
| go_version_file: | ||
| description: 'Path to a go.mod or .go-version file containing the Go version. Mutually exclusive with go_version.' | ||
| required: false | ||
| type: string | ||
| golangci-lint-version: | ||
| description: 'golangci-lint release to run' | ||
| required: false | ||
| type: string | ||
| default: 'latest' | ||
|
|
||
| permissions: | ||
| contents: read # baseline for checkout | ||
|
|
||
| jobs: | ||
| golangci-lint: | ||
| name: golangci-lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| with: | ||
| go-version: ${{ inputs.go_version || (inputs.go_version_file == '' && 'stable' || '') }} | ||
| go-version-file: ${{ inputs.go_version_file || '' }} | ||
| - uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 | ||
| with: | ||
| version: ${{ inputs.golangci-lint-version }} | ||
|
|
||
| modules: | ||
| name: modules | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| with: | ||
| go-version: ${{ inputs.go_version || (inputs.go_version_file == '' && 'stable' || '') }} | ||
| go-version-file: ${{ inputs.go_version_file || '' }} | ||
| - name: Check go.mod and go.sum are tidy | ||
| run: | | ||
| go mod tidy | ||
| git diff --exit-code -- go.mod go.sum | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # SPDX-FileCopyrightText: 2025 OpenCHAMI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| name: reuse | ||
|
|
||
| # Reusable workflow that checks the caller repo for REUSE compliance — | ||
| # every file carries a copyright notice and an SPDX license identifier, | ||
| # and every referenced license is present under LICENSES/. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| reuse_version: | ||
| type: string | ||
| required: false | ||
| default: '6.2.0' | ||
| description: 'Reuse CLI version to use (e.g. "6.2.0").' | ||
|
|
||
| permissions: | ||
| contents: read # baseline for checkout | ||
|
|
||
| jobs: | ||
| reuse: | ||
| name: reuse | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
| - name: REUSE compliance check | ||
| env: | ||
| REUSE_VERSION: ${{ inputs.reuse_version }} | ||
| run: pipx run --backend pip --spec "reuse==$REUSE_VERSION" reuse lint --lines |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # SPDX-FileCopyrightText: 2025 OpenCHAMI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| name: scorecard | ||
|
|
||
| # Reusable workflow that runs the OpenSSF Scorecard supply-chain analysis | ||
| # over the caller repo and uploads the SARIF to GitHub Advanced Security. | ||
| # | ||
| # On anything other than a pull_request the results are also published to | ||
| # the public OpenSSF dashboard, which is what backs the Scorecard badge. | ||
| # Callers should trigger this on the default branch, on pull_request, and | ||
| # on a schedule; running it on other branches scores an incomplete tree. | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| contents: read # baseline for checkout | ||
| security-events: write # for SARIF upload to GHAS | ||
| id-token: write # for publishing results to the OpenSSF dashboard | ||
|
|
||
| jobs: | ||
| scorecard: | ||
| name: scorecard | ||
| # Scorecard is a container action and needs a full-fat runner. | ||
| runs-on: ubuntu-latest | ||
|
synackd marked this conversation as resolved.
|
||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Run Scorecard analysis | ||
| uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4 | ||
| with: | ||
| results_file: results.sarif | ||
| results_format: sarif | ||
| publish_results: ${{ github.event_name != 'pull_request' }} | ||
|
|
||
| - name: Upload SARIF artifact | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: scorecard-sarif | ||
| path: results.sarif | ||
| retention-days: 5 | ||
|
|
||
| - name: Upload SARIF to GHAS | ||
| if: github.event_name != 'pull_request' | ||
| uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2 | ||
| with: | ||
| sarif_file: results.sarif | ||
| category: scorecard | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # SPDX-FileCopyrightText: 2025 OpenCHAMI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| name: test-go | ||
|
|
||
| # Reusable workflow that runs the caller's Go unit tests. Fetches tags so | ||
| # tests that assert on version metadata derived from `git describe` behave | ||
| # the same as they do locally. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| go_version: | ||
| description: 'Go version to use (e.g. "1.26.7", "stable"). Mutually exclusive with go_version_file.' | ||
| required: false | ||
| type: string | ||
| go_version_file: | ||
| description: 'Path to a go.mod or .go-version file containing the Go version. Mutually exclusive with go_version.' | ||
| required: false | ||
| type: string | ||
| test-command: | ||
| description: 'Command that runs the tests' | ||
| required: false | ||
| type: string | ||
| default: 'go test -race ./...' | ||
|
|
||
| permissions: | ||
| contents: read # baseline for checkout | ||
|
|
||
| jobs: | ||
| test-go: | ||
| name: test-go | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| fetch-tags: true | ||
| persist-credentials: false | ||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | ||
| with: | ||
| go-version: ${{ inputs.go_version || (inputs.go_version_file == '' && 'stable' || '') }} | ||
| go-version-file: ${{ inputs.go_version_file || '' }} | ||
| - name: Run tests | ||
| env: | ||
| TEST_COMMAND: ${{ inputs.test-command }} | ||
| run: eval "$TEST_COMMAND" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.