Add a setup step to export Go binary path to bashrc before configuring the proxy mirror, ensuring Go commands are available in the build environment.
79 lines
2.4 KiB
YAML
79 lines
2.4 KiB
YAML
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 "${{ secrets.G_CLONE_URL }}" .
|
|
|
|
- name: Setup go
|
|
run : echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc
|
|
|
|
- name: Set go proxy mirror
|
|
run: go env -w GOPROXY=https://go.iranserver.com/repository/go/ && go env -w GOSUMDB=off
|
|
|
|
- name: Download dependencies
|
|
run: go mod download
|
|
|
|
- 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 "${{ secrets.G_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 "${{ secrets.G_CLONE_URL }}" .
|
|
|
|
- name: Login to Gitea Registry
|
|
run: echo "${{ secrets.G_TOKEN }}" | docker login git.yejayekhoob.com -u "${{ secrets.G_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 \
|
|
. |