From b22db09c2fb8dee4de1596e85f4bef8dccf6debe Mon Sep 17 00:00:00 2001 From: db123-test Date: Mon, 4 May 2026 09:20:56 +0330 Subject: [PATCH] feat: add CI/CD workflow with linting, building, and docker Add GitHub Actions workflow that performs linting with golangci-lint, formats check, cross-compilation for linux/amd64, linux/arm64, and windows/amd64, and multi-platform docker image publishing to Gitea registry on pushes to main/master branches. --- .github/workflows/ci-cd.yml | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..0a7f17b --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,79 @@ +name: CI/CD + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + lint-and-format: + name: Lint & Format + runs-on: shell-ubuntu + steps: + - name: Checkout repo + run: git clone "$GITEA_CLONE_URL" . + + - name: Download dependencies + run: go mod download + + - name: Install golangci-lint + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.64.8 + + - name: Run golangci-lint + run: golangci-lint run --timeout=3m + + - name: Check formatting + run: | + if [ "$(gofmt -l $(find . -name '*.go' -not -path './vendor/*'))" ]; then + echo "Files not properly formatted:" + gofmt -l $(find . -name '*.go' -not -path './vendor/*') + exit 1 + fi + + build: + name: Build binaries + runs-on: shell-ubuntu + needs: lint-and-format + steps: + - name: Checkout repo + run: git clone "$GITEA_CLONE_URL" . + + - name: Build for Linux amd64 + run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o auth-gate-linux-amd64 . + + - name: Build for Linux arm64 + run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o auth-gate-linux-arm64 . + + - name: Build for Windows amd64 + run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o auth-gate-windows-amd64.exe + + - name: Package binaries + run: | + tar czf auth-gate-linux-amd64.tar.gz auth-gate-linux-amd64 + tar czf auth-gate-linux-arm64.tar.gz auth-gate-linux-arm64 + tar czf auth-gate-windows-amd64.tar.gz auth-gate-windows-amd64.exe + + docker: + name: Build & push Docker image + runs-on: shell-ubuntu + needs: lint-and-format + if: github.event_name == 'push' + steps: + - name: Checkout repo + run: git clone "$GITEA_CLONE_URL" . + + - name: Login to Gitea Registry + run: echo "${{ secrets.GITEA_TOKEN }}" | docker login git.yejayekhoob.com -u "${{ secrets.GITEA_USERNAME }}" --password-stdin + + - name: Set up Docker Buildx + run: docker buildx create --name builder --use + + - name: Build & push + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag "git.yejayekhoob.com/db123/auth-gate:${{ github.sha }}" \ + --tag "git.yejayekhoob.com/db123/auth-gate:latest" \ + --push \ + . \ No newline at end of file