v0.58 #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go CI/CD | |
on: | |
push: | |
branches: | |
- main # Trigger on pushes to the 'main' branch | |
pull_request: | |
branches: | |
- main # Trigger on pull requests targeting the 'main' branch | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' # Adjust if necessary | |
- name: Get dependencies | |
run: go get -v -t ./... | |
- name: Lint with golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: v1.55 # Use latest version if preferred | |
- name: Test | |
run: go test -v ./... | |
- name: Build Go binary | |
run: go build -v -o main . | |
deploy: | |
needs: build | |
if: github.ref == 'refs/heads/main' # Only deploy on push to main | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Build Docker Image | |
run: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
docker build -t "${{ secrets.DOCKER_USERNAME }}/<your-docker-image-name>:${{ github.sha }}" . | |
docker push "${{ secrets.DOCKER_USERNAME }}/<your-docker-image-name>:${{ github.sha }}" | |
- name: Verify Docker Image Push | |
run: | | |
docker pull "${{ secrets.DOCKER_USERNAME }}/<your-docker-image-name>:${{ github.sha }}" |