diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5427a88 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +name: Lint Test Build + +on: + push: + branches: + - main + - staging + pull_request: + branches: + - main + - staging + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Install golangci-lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 + golangci-lint version + + - name: Run golangci-lint + run: golangci-lint run --timeout=5m + + test: + name: Testing + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Install dependencies + run: go mod tidy + + - name: Run tests + run: go test ./... -v + + build: + name: Building + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Install dependencies + run: go mod tidy + + - name: Build the project + run: go build -o gocrab main.go + + - name: Verify binary exists + run: | + if [ ! -f "./gocrab" ]; then + echo "Build failed: binary not found." + exit 1 + fi diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 0000000..d36627c --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,36 @@ +name: Docker Release + +on: + workflow_run: + workflows: + - Lint Test Build + branches: + - main + types: + - completed +jobs: + docker: + name: Build and Push to Docker Hub + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and Push Docker Image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/gocrab:latest + ${{ secrets.DOCKER_USERNAME }}/gocrab:${{ github.sha }} diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml new file mode 100644 index 0000000..cda63ca --- /dev/null +++ b/.github/workflows/github-release.yml @@ -0,0 +1,80 @@ +name: Github Release + +on: + workflow_run: + workflows: + - Lint Test Build + branches: + - main + types: + - completed + +jobs: + release: + name: Release to GitHub + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.19 + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install dependencies + run: go mod download + + - name: Build binary + run: | + mkdir -p dist + GOOS=linux GOARCH=amd64 go build -o dist/GoCrab-linux-amd64 . + GOOS=darwin GOARCH=amd64 go build -o dist/GoCrab-darwin-amd64 . + GOOS=windows GOARCH=amd64 go build -o dist/GoCrab-windows-amd64.exe . + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref_name }} + release_name: "GoCrab ${{ github.ref_name }}" + body: | + Automated release for GoCrab version ${{ github.ref_name }}. + Includes pre-built binaries for Linux, macOS, and Windows. + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload Release Assets + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/GoCrab-linux-amd64 + asset_name: GoCrab-linux-amd64 + asset_content_type: application/octet-stream + + - name: Upload macOS Binary + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/GoCrab-darwin-amd64 + asset_name: GoCrab-darwin-amd64 + asset_content_type: application/octet-stream + + - name: Upload Windows Binary + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/GoCrab-windows-amd64.exe + asset_name: GoCrab-windows-amd64.exe + asset_content_type: application/octet-stream diff --git a/.github/workflows/gotest.yaml b/.github/workflows/gotest.yaml deleted file mode 100644 index 2ef88fa..0000000 --- a/.github/workflows/gotest.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: CI - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - backend: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.23' - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Install dependencies - run: go mod download - - - name: Run tests - run: | - cd tests - go test -v ./...