Skip to content

Commit 3a2ad7c

Browse files
committed
first commit
0 parents  commit 3a2ad7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+10386
-0
lines changed

.github/CONTRIBUTING.md

Whitespace-only changes.
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
name: Build, Test, and Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main ]
9+
release:
10+
types: [ published ]
11+
workflow_dispatch:
12+
inputs:
13+
push:
14+
description: "Actually push image to GHCR"
15+
type: boolean
16+
default: false
17+
tag:
18+
description: "Optional tag to apply when testing (e.g., test-123)"
19+
type: string
20+
required: false
21+
22+
jobs:
23+
build-test:
24+
name: Build and Test
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0 # Required for version determination from git tags
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v5
34+
with:
35+
go-version: '1.21'
36+
check-latest: true
37+
cache: true
38+
39+
- name: Install dependencies
40+
run: make mod-download
41+
42+
- name: Format check
43+
run: |
44+
make fmt
45+
git diff --exit-code || (echo "Code is not properly formatted. Run 'make fmt' locally." && exit 1)
46+
47+
- name: Vet check
48+
run: make vet
49+
50+
- name: Run tests
51+
run: make test
52+
53+
- name: Run tests with coverage
54+
run: make test-coverage
55+
56+
- name: Upload coverage report
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: coverage-report
60+
path: coverage.html
61+
62+
- name: Build
63+
run: make build
64+
65+
release:
66+
name: Release
67+
needs: build-test
68+
if: ${{ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v')) }}
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: write # Required for creating GitHub releases
72+
steps:
73+
- name: Checkout code
74+
uses: actions/checkout@v4
75+
with:
76+
fetch-depth: 0 # Required for version determination from git tags
77+
78+
- name: Set up Go
79+
uses: actions/setup-go@v5
80+
with:
81+
go-version: '1.21'
82+
check-latest: true
83+
cache: true
84+
85+
- name: Install dependencies
86+
run: make mod-download
87+
88+
- name: Build multi-platform binaries
89+
run: make build-all
90+
91+
- name: Create release
92+
id: create_release
93+
uses: softprops/action-gh-release@v2
94+
with:
95+
files: |
96+
./bin/prox-linux-amd64
97+
./bin/prox-linux-arm64
98+
./bin/prox-darwin-amd64
99+
./bin/prox-darwin-arm64
100+
./bin/prox-windows-amd64.exe
101+
draft: false
102+
prerelease: false
103+
generate_release_notes: true
104+
105+
docker:
106+
name: Docker Build and Push
107+
needs: build-test
108+
if: ${{ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v')) || (github.event_name == 'workflow_dispatch') }}
109+
runs-on: ubuntu-latest
110+
permissions:
111+
contents: read
112+
packages: write # Required for pushing to GitHub Container Registry
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v4
116+
117+
- name: Set up QEMU
118+
uses: docker/setup-qemu-action@v3
119+
120+
- name: Set up Docker Buildx
121+
uses: docker/setup-buildx-action@v3
122+
123+
- name: Login to GitHub Container Registry
124+
if: ${{ github.event_name != 'workflow_dispatch' }}
125+
uses: docker/login-action@v3
126+
with:
127+
registry: ghcr.io
128+
username: ${{ github.repository_owner }}
129+
password: ${{ secrets.GHCR_TOKEN || secrets.GITHUB_TOKEN }}
130+
131+
- name: Login to GitHub Container Registry (manual)
132+
if: ${{ github.event_name == 'workflow_dispatch' && inputs.push }}
133+
uses: docker/login-action@v3
134+
with:
135+
registry: ghcr.io
136+
username: ${{ github.repository_owner }}
137+
password: ${{ secrets.GHCR_TOKEN || secrets.GITHUB_TOKEN }}
138+
139+
- name: Create GHCR package namespace if needed
140+
if: ${{ github.event_name != 'workflow_dispatch' || inputs.push }}
141+
run: |
142+
# Use a more explicit token approach
143+
TOKEN="${{ secrets.GHCR_TOKEN }}"
144+
if [ -z "$TOKEN" ]; then
145+
TOKEN="${{ secrets.GITHUB_TOKEN }}"
146+
echo "Using GITHUB_TOKEN (may have limited permissions for first push)"
147+
else
148+
echo "Using GHCR_TOKEN"
149+
fi
150+
151+
# Check if package exists
152+
if ! docker manifest inspect ghcr.io/${{ github.repository_owner }}/prox:latest >/dev/null 2>&1; then
153+
echo "Package doesn't exist, creating namespace with a test push..."
154+
155+
# Create a minimal image and push it to establish the package
156+
cat > Dockerfile.init << 'EOF'
157+
FROM alpine:latest
158+
RUN echo "Package initialization" > /tmp/init
159+
EOF
160+
161+
docker build -f Dockerfile.init -t ghcr.io/${{ github.repository_owner }}/prox:init .
162+
163+
# Try to push the init image to create the package namespace
164+
if docker push ghcr.io/${{ github.repository_owner }}/prox:init; then
165+
echo "✅ Package namespace created successfully"
166+
# Clean up the init tag
167+
rm -f Dockerfile.init
168+
else
169+
echo "⚠️ Failed to create package namespace, but continuing..."
170+
echo "This might be due to token permissions. Consider using a PAT with write:packages scope."
171+
fi
172+
else
173+
echo "✅ Package already exists, proceeding..."
174+
fi
175+
176+
- name: Docker metadata
177+
id: meta
178+
uses: docker/metadata-action@v5
179+
with:
180+
images: ghcr.io/${{ github.repository_owner }}/prox
181+
tags: |
182+
type=semver,pattern={{version}}
183+
type=raw,value=latest
184+
185+
- name: Build image (manual)
186+
if: ${{ github.event_name == 'workflow_dispatch' }}
187+
uses: docker/build-push-action@v5
188+
with:
189+
context: .
190+
push: ${{ inputs.push }}
191+
platforms: linux/amd64,linux/arm64
192+
tags: |
193+
${{ steps.meta.outputs.tags }}
194+
${{ inputs.tag != '' && format('ghcr.io/{0}/prox:{1}', github.repository_owner, inputs.tag) || '' }}
195+
labels: ${{ steps.meta.outputs.labels }}
196+
197+
- name: Build and push Docker image (tags/releases)
198+
if: ${{ github.event_name != 'workflow_dispatch' }}
199+
uses: docker/build-push-action@v5
200+
with:
201+
context: .
202+
push: true
203+
platforms: linux/amd64,linux/arm64
204+
tags: ${{ steps.meta.outputs.tags }}
205+
labels: ${{ steps.meta.outputs.labels }}
206+
207+
- name: Verify push success
208+
if: ${{ (github.event_name != 'workflow_dispatch' || inputs.push) && success() }}
209+
run: |
210+
echo "✅ Images pushed successfully!"
211+
echo "Available tags:"
212+
docker manifest inspect ghcr.io/${{ github.repository_owner }}/prox:latest || echo "❌ Latest tag verification failed"
213+
214+
- name: Push failure guidance
215+
if: ${{ (github.event_name != 'workflow_dispatch' || inputs.push) && failure() }}
216+
run: |
217+
echo "❌ Push failed with 403 Forbidden error"
218+
echo ""
219+
echo "🔧 To fix this issue:"
220+
echo "1. Create a Personal Access Token (PAT) at: https://github.com/settings/tokens"
221+
echo "2. Grant these permissions: write:packages, read:packages"
222+
echo "3. Add it as repository secret 'GHCR_TOKEN' at:"
223+
echo " https://github.com/${{ github.repository }}/settings/secrets/actions"
224+
echo "4. Re-run this workflow"
225+
echo ""
226+
echo "📖 More info: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry"

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Binaries
2+
prox
3+
bin/
4+
*.exe
5+
*.exe~
6+
*.dll
7+
*.so
8+
*.dylib
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool
14+
*.out
15+
coverage.html
16+
17+
# Dependency directories
18+
vendor/
19+
20+
# Temporary files
21+
tmp/
22+
.tmp/
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS generated files
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db
39+
40+
# Config files (may contain sensitive info)
41+
config.local
42+
*.local
43+
44+
# Log files
45+
*.log

CONTRIBUTING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Contributing to Prox
2+
3+
We love your input! We want to make contributing to Prox as easy and transparent as possible, whether it's:
4+
5+
- Reporting a bug
6+
- Discussing the current state of the code
7+
- Submitting a fix
8+
- Proposing new features
9+
- Becoming a maintainer
10+
11+
## Development Process
12+
13+
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.
14+
15+
### Pull Requests
16+
17+
1. Fork the repo and create your branch from `main`.
18+
2. If you've added code that should be tested, add tests.
19+
3. If you've changed APIs, update the documentation.
20+
4. Ensure the test suite passes.
21+
5. Make sure your code follows the project's code style.
22+
6. Issue that pull request!
23+
24+
### Testing
25+
26+
Before submitting a pull request, make sure all tests pass:
27+
28+
```bash
29+
make test
30+
```
31+
32+
For more comprehensive checks, run:
33+
34+
```bash
35+
make release-check
36+
```
37+
38+
This will run formatting checks, static analysis, and all tests.
39+
40+
## CI/CD Pipeline
41+
42+
The project uses GitHub Actions for Continuous Integration and Deployment:
43+
44+
### Automatic Processes
45+
46+
- All PRs and pushes to main are tested
47+
- Tagged commits trigger automatic releases
48+
- Release builds include binaries for multiple platforms and Docker images
49+
50+
### Required Permissions
51+
52+
For the GitHub Actions workflow to function properly:
53+
54+
- `contents: write` - Required for creating releases
55+
- `packages: write` - Required for publishing Docker images to GitHub Container Registry
56+
57+
These permissions are already configured in the workflow file.
58+
59+
### Environment Setup
60+
61+
No additional environment setup is required for regular contributors. The GitHub Actions workflow handles everything automatically.
62+
63+
## Release Process
64+
65+
To create a new release:
66+
67+
1. Ensure all changes are merged to the main branch
68+
2. Create and push a new tag:
69+
70+
```bash
71+
git tag -a v1.0.0 -m "Release v1.0.0"
72+
git push origin v1.0.0
73+
```
74+
75+
The CI pipeline will automatically:
76+
- Run tests and validation
77+
- Build binaries for all platforms
78+
- Create a GitHub release
79+
- Build and push Docker images
80+
81+
## Code Style
82+
83+
- Follow Go best practices
84+
- Run `make fmt` before committing to ensure code is properly formatted
85+
- Use meaningful commit messages
86+
- Comment your code where appropriate
87+
88+
Thank you for contributing to Prox!

0 commit comments

Comments
 (0)