diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..d22910d --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,79 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + GO_VERSION: "1.24" + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: go mod download + + - name: Verify dependencies + run: go mod verify + + - name: Build + run: go build -v ./... + + - name: Run go vet + run: go vet ./... + + - name: Run tests + run: go test -v -race ./... + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: go mod download + + - name: Check formatting + run: | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + echo "The following files are not formatted properly:" + gofmt -s -l . + exit 1 + fi + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Run staticcheck + run: staticcheck ./... + + benchmark: + name: Benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: go mod download + + - name: Run benchmarks + run: go test -bench=. -benchmem -count=1 ./... diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..108a30a --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,79 @@ +name: Release + +on: + push: + tags: + - 'v*' + +env: + GO_VERSION: "1.24" + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test -race ./... + + - name: Run go vet + run: go vet ./... + + build: + name: Build (${{ matrix.goos }}, ${{ matrix.goarch }}) + needs: test + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: linux + goarch: amd64 + suffix: "" + - goos: linux + goarch: arm64 + suffix: "" + - goos: darwin + goarch: amd64 + suffix: "" + - goos: darwin + goarch: arm64 + suffix: "" + - goos: windows + goarch: amd64 + suffix: ".exe" + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: go mod download + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + VERSION=${GITHUB_REF#refs/tags/} + COMMIT=$(git rev-parse --short HEAD) + DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) + LDFLAGS="-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT -X main.BuildDate=$DATE" + mkdir -p dist + go build -ldflags "$LDFLAGS" -o "dist/jdenticon-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}" ./cmd/jdenticon/ + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: jdenticon-${{ matrix.goos }}-${{ matrix.goarch }} + path: dist/