Skip to content

Commit 26c8138

Browse files
committed
chore: scaffold project and impl. proxy server
Assisted-by: Claude:claude-opus-4-8
1 parent 3bfc2ea commit 26c8138

23 files changed

Lines changed: 2550 additions & 2 deletions

‎.dockerignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Keep the build context small: the Dockerfile only needs the crate sources and the
2+
# lockfile. Everything else (build output, git, CI, docs) is excluded.
3+
target/
4+
.git/
5+
.github/
6+
*.md

‎.github/workflows/ci.yml‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
RUST_BACKTRACE: 1
11+
12+
jobs:
13+
# Gate the Rust jobs on Rust changes, so docs-only changes skip lint and test.
14+
changes:
15+
name: Detect changes
16+
runs-on: ubuntu-latest
17+
outputs:
18+
rust: ${{ steps.filter.outputs.rust }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: dorny/paths-filter@v3
22+
id: filter
23+
with:
24+
filters: |
25+
rust:
26+
- '**/*.rs'
27+
- '**/Cargo.toml'
28+
- 'Cargo.lock'
29+
- '.github/workflows/ci.yml'
30+
31+
lint:
32+
name: Lint
33+
needs: changes
34+
if: needs.changes.outputs.rust == 'true'
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: dtolnay/rust-toolchain@stable
39+
with:
40+
components: clippy, rustfmt
41+
- uses: Swatinem/rust-cache@v2
42+
- name: Check formatting
43+
run: cargo fmt --all --check
44+
- name: Run clippy
45+
run: cargo clippy --all-targets --all-features --locked -- -D warnings
46+
47+
test:
48+
name: Test and coverage
49+
needs: changes
50+
if: needs.changes.outputs.rust == 'true'
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: dtolnay/rust-toolchain@stable
55+
with:
56+
components: llvm-tools-preview
57+
- uses: Swatinem/rust-cache@v2
58+
- uses: taiki-e/install-action@v2
59+
with:
60+
tool: cargo-llvm-cov
61+
- name: Test and collect coverage
62+
run: |
63+
cargo llvm-cov --all-features --locked --lcov --output-path lcov.info
64+
cargo llvm-cov report --summary-only
65+
- name: Upload coverage to Codecov
66+
uses: codecov/codecov-action@v5
67+
with:
68+
files: lcov.info
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
71+
# Spelling runs on everything, including docs.
72+
typos:
73+
name: Typos
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v4
77+
- uses: crate-ci/typos@v1
78+
79+
# Conventional Commits check for pull requests (advisory; direct pushes to main are
80+
# covered by a local commit-msg hook - see CONTRIBUTING.md).
81+
commits:
82+
name: Commit messages
83+
if: github.event_name == 'pull_request'
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
with:
88+
fetch-depth: 0
89+
- uses: crate-ci/committed@v1.1.11

‎.github/workflows/package.yml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Package
2+
3+
# On every packaging change, build the image (no push) so breakage is caught before a
4+
# release. Publishing the versioned image to GHCR happens in the Release workflow, in the
5+
# same run that cuts the release.
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
changes:
17+
name: Detect changes
18+
runs-on: ubuntu-latest
19+
outputs:
20+
pkg: ${{ steps.filter.outputs.pkg }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: dorny/paths-filter@v3
24+
id: filter
25+
with:
26+
filters: |
27+
pkg:
28+
- 'src/**'
29+
- 'Cargo.toml'
30+
- 'Cargo.lock'
31+
- 'Dockerfile'
32+
- '.dockerignore'
33+
- '.github/workflows/package.yml'
34+
35+
validate:
36+
name: Build image
37+
needs: changes
38+
if: needs.changes.outputs.pkg == 'true'
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: docker/setup-buildx-action@v3
43+
- name: Build image (no push)
44+
uses: docker/build-push-action@v6
45+
with:
46+
context: .
47+
file: Dockerfile
48+
push: false
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max

‎.github/workflows/release.yml‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read
9+
10+
# One release at a time; do not cancel one mid-flight.
11+
concurrency:
12+
group: release
13+
cancel-in-progress: false
14+
15+
env:
16+
IMAGE: ghcr.io/rolandjitsu/git-proxy-server
17+
18+
jobs:
19+
release:
20+
name: Release
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
outputs:
25+
released: ${{ steps.release.outputs.released }}
26+
version: ${{ steps.release.outputs.version }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
# Full history and tags so knope can read the commits since the last release.
31+
fetch-depth: 0
32+
- uses: knope-dev/action@v2.1.2
33+
with:
34+
version: 0.23.0
35+
- name: Configure the release identity
36+
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39+
# knope bumps the version, updates the changelog, tags, and creates the GitHub
40+
# release from the conventional commits since the last tag. Pushing with the
41+
# built-in token does not retrigger this workflow, so the publish job below runs in
42+
# this same run instead. `no_release` (no releasable commits since the last tag) is
43+
# a normal no-op, not a failure.
44+
- name: Release
45+
id: release
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: |
49+
set +e
50+
out="$(knope release 2>&1)"
51+
code=$?
52+
echo "$out"
53+
if [ "$code" -eq 0 ]; then
54+
tag="$(git tag --sort=-v:refname | head -n1)"
55+
echo "released=true" >> "$GITHUB_OUTPUT"
56+
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
57+
echo "::notice::Released ${tag}."
58+
elif echo "$out" | grep -q 'no_release'; then
59+
echo "::notice::No releasable commits since the last release; nothing to do."
60+
echo "released=false" >> "$GITHUB_OUTPUT"
61+
else
62+
exit "$code"
63+
fi
64+
65+
# Build and push the versioned image to GHCR, in the same run that cut the release, at
66+
# the tag knope just created. The published GHCR package starts private; make it public
67+
# once to allow anonymous `docker pull`.
68+
publish:
69+
name: Publish image
70+
needs: release
71+
if: needs.release.outputs.released == 'true'
72+
runs-on: ubuntu-latest
73+
permissions:
74+
contents: read
75+
packages: write
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
ref: v${{ needs.release.outputs.version }}
80+
- uses: docker/setup-buildx-action@v3
81+
- uses: docker/login-action@v3
82+
with:
83+
registry: ghcr.io
84+
username: ${{ github.actor }}
85+
password: ${{ secrets.GITHUB_TOKEN }}
86+
- name: Build and push the versioned image
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: .
90+
file: Dockerfile
91+
push: true
92+
tags: |
93+
${{ env.IMAGE }}:${{ needs.release.outputs.version }}
94+
${{ env.IMAGE }}:latest
95+
cache-from: type=gha
96+
cache-to: type=gha,mode=max

‎.gitignore‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# macOS
1+
/target
2+
Cargo.lock.bak
3+
*.swp
4+
5+
### macOS ###
26
.DS_Store
37
.localized
48
__MACOSX/
59
.AppleDouble
610
.LSOverride
711
Icon[]
8-
12+
._*

‎.pre-commit-config.yaml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Local git hooks, managed by prek (https://github.com/j178/prek) - a fast, Rust,
2+
# no-Python reimplementation of pre-commit. Enable once with: prek install
3+
#
4+
# Mirrors CI where it's cheap: typos + Conventional Commits on commit, rustfmt on the
5+
# staged Rust files, and clippy on push (too heavy per commit). Rust hooks only fire when
6+
# Rust files change (types: [rust]).
7+
default_install_hook_types: [pre-commit, commit-msg, pre-push]
8+
9+
repos:
10+
- repo: https://github.com/crate-ci/typos
11+
rev: v1.49.0
12+
hooks:
13+
- id: typos
14+
stages: [pre-commit]
15+
16+
- repo: https://github.com/crate-ci/committed
17+
rev: v1.1.11
18+
hooks:
19+
- id: committed
20+
stages: [commit-msg]
21+
22+
- repo: local
23+
hooks:
24+
- id: rustfmt
25+
name: rustfmt
26+
entry: rustfmt --edition 2024
27+
language: system
28+
types: [rust]
29+
stages: [pre-commit]
30+
31+
- id: cargo-clippy
32+
name: cargo clippy
33+
entry: cargo clippy --all-targets --all-features --locked -- -D warnings
34+
language: system
35+
types: [rust]
36+
pass_filenames: false
37+
stages: [pre-push]

‎AGENTS.md‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# AGENTS.md
2+
3+
Guidance for AI coding agents in this repo. Human contributors: see [CONTRIBUTING.md](./CONTRIBUTING.md).
4+
5+
## Workflow
6+
7+
- Clarify the design before implementing. For anything non-trivial, agree on the approach first;
8+
prefer a short design note over jumping to code.
9+
- One unit of change per commit. Never mix unrelated changes. Present the change for review
10+
before committing.
11+
- Every change ships with tests. Run local CI before calling it done, and do not claim it passes
12+
without running it.
13+
- Verify against the code and the tools: read before you answer, run before you assert.
14+
15+
Local CI:
16+
17+
```shell
18+
cargo fmt --all --check
19+
cargo clippy --all-targets --all-features --locked -- -D warnings
20+
cargo test --all-features
21+
```
22+
23+
## Writing: code, comments, docs, commits
24+
25+
- Concise and to the point. No fluff. Explain the non-obvious; do not narrate the obvious.
26+
- ASCII only. No em-dash and no `--`; write `-`. Use `->` not the arrow glyph, `!=` not the
27+
not-equal glyph, and so on.
28+
- Comments justify *why*, not *what*. Delete any comment that restates the code.
29+
- Do not use the word "seam"; say boundary, interface, or extension point.
30+
- Do not use "bespoke"; say "custom".
31+
32+
## Commits
33+
34+
- Conventional Commits (see CONTRIBUTING.md). Write the subject in the present tense, imperative
35+
voice: `feat: add fetch TTL`, not `added` or `adds`.
36+
- Disclose AI with an `Assisted-by: Claude:claude-opus-4-8` trailer. Never `Co-Authored-By`, and
37+
never add a human's `Signed-off-by`.
38+
39+
## Tests
40+
41+
- Unit tests inline (`#[cfg(test)] mod tests`); public-surface tests in `tests/`.
42+
- Put helpers *after* the tests that use them.
43+
- Prefer deterministic time: drive tokio's paused clock, not sleeps or `yield_now` loops.
44+
45+
## Terminology
46+
47+
- **upstream**: the origin git server the proxy fetches from. The proxy holds a single
48+
read-only credential for it and never writes to it.
49+
- **mirror**: the local bare repository (`clone --mirror`) the proxy serves clients from and
50+
keeps fresh with incremental fetches.
51+
- **serve**: responding to a client's `info/refs` / `git-upload-pack` from the mirror.
52+
- git-cache-proxy is strictly read-only and pull-only. Any change that could push or
53+
proactively replicate to upstream is out of scope.
54+
55+
## Code conventions
56+
57+
- All git protocol work is delegated to the system `git` binary. Do not reimplement pack
58+
negotiation; shell out to `git` so protocol correctness (v2, shallow, partial clones) is free.
59+
- Import a type by one path and use it consistently (e.g. a single `use std::sync::Arc`, not
60+
mixed inline `std::sync::Arc` paths).
61+
- Prefer `tokio::fs` in async paths unless `std::fs` is clearly fine (small, at startup, no
62+
blocking concern).
63+
- Document public items with rustdoc; keep it accurate and free of drift.
64+
65+
## CI workflows
66+
67+
- GitHub Actions live in `.github/workflows`. Write the workflow `name:`, every job name, and
68+
every named step in Sentence case, matching `ci.yml` (e.g. `name: CI`, `Check formatting`).
69+
- Keep workflows minimal and scoped to one purpose; prefer the built-in `GITHUB_TOKEN` over a
70+
personal access token.

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
All notable changes are documented here. This file is managed by
4+
[knope](https://knope.tech/) from the Conventional Commits on `main`; do not edit it by
5+
hand.

0 commit comments

Comments
 (0)