Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Private Go module dependencies
#
# A repo whose go.mod requires a private repo in this org needs the module
# proxy path authenticated before any `go` command touches the network. Pass
# the org secret through:
#
# secrets:
# XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
#
# A caller using `secrets: inherit` gets this automatically, no change
# needed. A caller passing secrets explicitly (as the README recommends)
# must add the line above itself, alongside CODECOV_TOKEN.
#
# The secret is optional. Leave it unset and every job runs exactly as it
# does today - the auth step becomes a no-op.

name: Go CI

on:
Expand Down Expand Up @@ -67,9 +83,16 @@ on:
description: 'Check that nested go.mod files require their siblings at versions the module proxy can serve. A nested module replace is ignored once the module is somebody else dependency, so a require naming an unpublished version breaks go get for every consumer while every local build keeps working. No-op in a repo with a single go.mod.'
type: boolean
default: true
private-module-pattern:
description: 'GOPRIVATE pattern applied when XRAPH_REPO_TOKEN is set. Only takes effect if the secret is present.'
type: string
default: 'github.com/xraph/*'
secrets:
CODECOV_TOKEN:
required: false
XRAPH_REPO_TOKEN:
description: 'Org token for resolving private github.com/xraph/* Go modules. Optional - unset means public-only, matching current behavior.'
required: false

jobs:
setup:
Expand Down Expand Up @@ -129,6 +152,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v7

- name: Configure Go module auth
env:
XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
PRIVATE_MODULE_PATTERN: ${{ inputs.private-module-pattern }}
run: |
set -euo pipefail
if [ -n "${XRAPH_REPO_TOKEN}" ]; then
git config --global url."https://x-access-token:${XRAPH_REPO_TOKEN}@github.com/".insteadOf "https://github.com/"
echo "GOPRIVATE=${PRIVATE_MODULE_PATTERN}" >> "$GITHUB_ENV"
fi

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand Down Expand Up @@ -267,6 +301,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v7

- name: Configure Go module auth
env:
XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
PRIVATE_MODULE_PATTERN: ${{ inputs.private-module-pattern }}
run: |
set -euo pipefail
if [ -n "${XRAPH_REPO_TOKEN}" ]; then
git config --global url."https://x-access-token:${XRAPH_REPO_TOKEN}@github.com/".insteadOf "https://github.com/"
echo "GOPRIVATE=${PRIVATE_MODULE_PATTERN}" >> "$GITHUB_ENV"
fi

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand Down Expand Up @@ -299,6 +344,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v7

- name: Configure Go module auth
env:
XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
PRIVATE_MODULE_PATTERN: ${{ inputs.private-module-pattern }}
run: |
set -euo pipefail
if [ -n "${XRAPH_REPO_TOKEN}" ]; then
git config --global url."https://x-access-token:${XRAPH_REPO_TOKEN}@github.com/".insteadOf "https://github.com/"
echo "GOPRIVATE=${PRIVATE_MODULE_PATTERN}" >> "$GITHUB_ENV"
fi

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand Down Expand Up @@ -366,6 +422,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v7

- name: Configure Go module auth
env:
XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
PRIVATE_MODULE_PATTERN: ${{ inputs.private-module-pattern }}
run: |
set -euo pipefail
if [ -n "${XRAPH_REPO_TOKEN}" ]; then
git config --global url."https://x-access-token:${XRAPH_REPO_TOKEN}@github.com/".insteadOf "https://github.com/"
echo "GOPRIVATE=${PRIVATE_MODULE_PATTERN}" >> "$GITHUB_ENV"
fi

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,32 @@ npm-global-packages: 'typescript@5.8.2 esbuild@0.28.1'

Both default to empty, so nothing is installed unless asked.

## Private Go module dependencies

A repo whose go.mod requires a private repo in this org needs the module
proxy authenticated before any `go` command touches the network, and a
reusable workflow's caller cannot inject a step into its jobs to do that
itself. `go-ci.yml` covers it directly: pass the org secret through, and a
"Configure Go module auth" step runs in `test`, `lint`, `verify` and
`security`, before that job's `Set up Go` step, so it takes effect for
`go mod download`, `golangci-lint`, `go vet`, `gosec` and `govulncheck` alike.

```yaml
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
XRAPH_REPO_TOKEN: ${{ secrets.XRAPH_REPO_TOKEN }}
```

The secret is optional and defaults to unset, so every existing caller is
unaffected. If your workflow uses `secrets: inherit`, you already get this
for free and there is nothing to change. If you pass secrets explicitly, as
recommended above, add the `XRAPH_REPO_TOKEN` line yourself alongside
`CODECOV_TOKEN`.

The step sets `GOPRIVATE` to `github.com/xraph/*` by default. Override it
with the `private-module-pattern` input if your module paths need a
different pattern, though that should be rare inside this org.

## Escaping the Makefile probe

`go-ci.yml` prefers a Makefile target when one matching the step exists. That
Expand Down