Skip to content

Commit 3d0bcdb

Browse files
committed
Add cpa, a command line for cpalgorithms
0 parents  commit 3d0bcdb

34 files changed

Lines changed: 1586 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ci-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
# Build and test on Linux and macOS with the race detector on. gofmt and vet
17+
# run here too so a formatting slip fails fast on both platforms.
18+
test:
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, macos-latest]
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- uses: actions/checkout@v5
26+
- uses: actions/setup-go@v6
27+
with:
28+
go-version-file: go.mod
29+
check-latest: true
30+
cache: true
31+
- name: gofmt
32+
run: |
33+
unformatted=$(gofmt -l .)
34+
if [ -n "$unformatted" ]; then
35+
echo "These files need gofmt -s -w:"
36+
echo "$unformatted"
37+
exit 1
38+
fi
39+
- name: go vet
40+
run: go vet ./...
41+
- name: build
42+
run: go build ./...
43+
- name: test
44+
run: go test -race -count=1 -coverprofile=coverage.out ./...
45+
- name: coverage summary
46+
if: matrix.os == 'ubuntu-latest'
47+
run: go tool cover -func=coverage.out | tail -1
48+
49+
# golangci-lint bundles staticcheck, govet, ineffassign, errcheck, unused and
50+
# more, so it is the main quality gate. Config lives in .golangci.yml.
51+
lint:
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v5
55+
- uses: actions/setup-go@v6
56+
with:
57+
go-version-file: go.mod
58+
check-latest: true
59+
cache: true
60+
- uses: golangci/golangci-lint-action@v8
61+
with:
62+
version: latest
63+
64+
# Scan the module and its dependencies for known vulnerabilities.
65+
govulncheck:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v5
69+
- uses: actions/setup-go@v6
70+
with:
71+
go-version-file: go.mod
72+
check-latest: true
73+
cache: true
74+
- name: govulncheck
75+
run: |
76+
go install golang.org/x/vuln/cmd/govulncheck@latest
77+
govulncheck ./...
78+
79+
# Confirm go.mod and go.sum are tidy: a PR that adds an import without running
80+
# go mod tidy fails here instead of breaking a later release.
81+
tidy:
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v5
85+
- uses: actions/setup-go@v6
86+
with:
87+
go-version-file: go.mod
88+
check-latest: true
89+
cache: true
90+
- name: go mod tidy is clean
91+
run: |
92+
go mod tidy
93+
git diff --exit-code -- go.mod go.sum

.github/workflows/docs.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "docs/**"
8+
- ".github/workflows/docs.yml"
9+
- "scripts/ensure_cloudflare_pages.py"
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
deployments: write
17+
18+
env:
19+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
20+
21+
concurrency:
22+
group: docs-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v6.0.2
30+
with:
31+
submodules: true
32+
# Sitemap lastmod comes from the latest content commit.
33+
fetch-depth: 0
34+
35+
- name: Checkout tago
36+
uses: actions/checkout@v6.0.2
37+
with:
38+
repository: tamnd/tago
39+
path: .tago-src
40+
fetch-depth: 1
41+
42+
- name: Setup Go
43+
uses: actions/setup-go@v6.4.0
44+
with:
45+
go-version-file: .tago-src/go.mod
46+
cache: false
47+
48+
- name: Cache tago binary
49+
id: tago-bin-cache
50+
uses: actions/cache@v5.0.5
51+
with:
52+
path: /usr/local/bin/tago
53+
key: tago-bin-${{ runner.os }}-${{ hashFiles('.tago-src/go.sum', '.tago-src/**/*.go') }}
54+
55+
- name: Build tago
56+
if: steps.tago-bin-cache.outputs.cache-hit != 'true'
57+
run: |
58+
cd .tago-src
59+
go build -o /usr/local/bin/tago ./cmd/tago/
60+
61+
# Two builds, one per deploy target. The theme links every page and asset
62+
# with absURL, so each output carries its own base path: the Pages build
63+
# gets the /cpalgorithms-cli/ sub-path, the Cloudflare build gets the domain root.
64+
- name: Build for GitHub Pages
65+
working-directory: docs
66+
run: tago build --base-url "https://tamnd.github.io/cpalgorithms-cli/" --output public-pages
67+
68+
# tago absURLs theme links but passes markdown content links through, so
69+
# root-relative links in content need the sub-path prefixed for the Pages
70+
# mirror. The Cloudflare build serves from the root and needs none.
71+
- name: Rewrite content links for the Pages sub-path
72+
run: |
73+
find docs/public-pages -name '*.html' -print0 |
74+
xargs -0 perl -pi -e 's|(href=")/(?!/)|${1}/cpalgorithms-cli/|g; s|(src=")/(?!/)|${1}/cpalgorithms-cli/|g'
75+
76+
- name: Build for Cloudflare Pages
77+
working-directory: docs
78+
run: tago build --base-url "https://cpalgorithms-cli.tamnd.com/" --output public-cf
79+
80+
- name: Upload Pages artifact
81+
uses: actions/upload-pages-artifact@v5.0.0
82+
with:
83+
path: docs/public-pages
84+
85+
- name: Upload Cloudflare artifact
86+
uses: actions/upload-artifact@v7.0.1
87+
with:
88+
name: public-cf
89+
path: docs/public-cf
90+
retention-days: 1
91+
92+
deploy-pages:
93+
runs-on: ubuntu-latest
94+
needs: build
95+
environment:
96+
name: github-pages
97+
url: ${{ steps.deployment.outputs.page_url }}
98+
steps:
99+
- name: Deploy to GitHub Pages
100+
id: deployment
101+
uses: actions/deploy-pages@v5.0.0
102+
103+
deploy-cloudflare:
104+
runs-on: ubuntu-latest
105+
needs: build
106+
concurrency:
107+
group: cloudflare-pages-cpalgorithms-cli
108+
cancel-in-progress: true
109+
steps:
110+
- uses: actions/checkout@v6.0.2
111+
with:
112+
fetch-depth: 1
113+
sparse-checkout: scripts/
114+
115+
- name: Download Cloudflare artifact
116+
uses: actions/download-artifact@v8.0.1
117+
with:
118+
name: public-cf
119+
path: public-cf
120+
121+
- name: Ensure Cloudflare Pages config
122+
env:
123+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
124+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
125+
run: python3 scripts/ensure_cloudflare_pages.py --project cpalgorithms-cli --domain cpalgorithms-cli.tamnd.com --zone tamnd.com
126+
127+
- name: Deploy to Cloudflare Pages
128+
env:
129+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
130+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
131+
run: |
132+
npx -y wrangler@4 pages deploy public-cf \
133+
--project-name=cpalgorithms-cli \
134+
--branch=main \
135+
--commit-dirty=true

.github/workflows/release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: release
2+
3+
# Pushing a version tag turns the GoReleaser config (.goreleaser.yaml) into a
4+
# GitHub release with the archives, Linux packages (deb, rpm, apk), checksums,
5+
# SBOMs and a cosign signature, and pushes the multi-arch container image to
6+
# GHCR. Pull requests and pushes to main run `goreleaser check` only, so a
7+
# config that would fail a real release is caught long before the tag.
8+
9+
on:
10+
push:
11+
branches: [main]
12+
tags: ["v*"]
13+
pull_request:
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: release-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
# Fast gate on every PR and push: the config parses and is valid for the
25+
# installed GoReleaser version. No artifacts are built here.
26+
check:
27+
if: github.ref_type != 'tag'
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v5
31+
with:
32+
fetch-depth: 0
33+
- uses: actions/setup-go@v6
34+
with:
35+
go-version-file: go.mod
36+
cache: true
37+
- uses: goreleaser/goreleaser-action@v6
38+
with:
39+
distribution: goreleaser
40+
version: "~> v2"
41+
args: check
42+
43+
# The real release, only on a version tag.
44+
release:
45+
if: github.ref_type == 'tag'
46+
runs-on: ubuntu-latest
47+
permissions:
48+
contents: write # create the GitHub release
49+
packages: write # push the image to ghcr.io
50+
id-token: write # keyless cosign signing
51+
steps:
52+
- uses: actions/checkout@v5
53+
with:
54+
fetch-depth: 0
55+
- uses: actions/setup-go@v6
56+
with:
57+
go-version-file: go.mod
58+
cache: true
59+
60+
# Build and ship the linux/arm64 image from the amd64 runner.
61+
- uses: docker/setup-qemu-action@v3
62+
- uses: docker/setup-buildx-action@v3
63+
- uses: docker/login-action@v3
64+
with:
65+
registry: ghcr.io
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
# Tools GoReleaser shells out to for signing and SBOMs.
70+
- uses: sigstore/cosign-installer@v3
71+
- uses: anchore/sbom-action/download-syft@v0
72+
73+
- uses: goreleaser/goreleaser-action@v6
74+
with:
75+
distribution: goreleaser
76+
version: "~> v2"
77+
args: release --clean
78+
env:
79+
# Creating the release and pushing the GHCR image use the built-in
80+
# token. The package-manager publish steps each read their own secret;
81+
# any that is unset leaves that manager skipped (the artifact is still
82+
# produced), so the release never fails for a tap that is not set up.
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
85+
SCOOP_BUCKET_GITHUB_TOKEN: ${{ secrets.SCOOP_BUCKET_GITHUB_TOKEN }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/dist/
2+
/bin/
3+
*.out
4+
*.test
5+
.DS_Store
6+
7+
# Built docs site (tago output) and its cache
8+
/docs/public/
9+
/docs/public-pages/
10+
/docs/public-cf/
11+
**/.tago-cache.db

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/themes/tago-doks"]
2+
path = docs/themes/tago-doks
3+
url = https://github.com/tamnd/tago-doks

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Pinned golangci-lint configuration so lint behaviour is the same on every
2+
# machine and in CI, rather than drifting with the action's built-in default.
3+
version: "2"
4+
5+
run:
6+
timeout: 5m
7+
8+
linters:
9+
# The standard set (errcheck, govet, ineffassign, staticcheck, unused) plus a
10+
# couple of cheap, high-signal extras.
11+
default: standard
12+
enable:
13+
- misspell
14+
- unconvert
15+
16+
formatters:
17+
enable:
18+
- gofmt

0 commit comments

Comments
 (0)