Skip to content

Commit

Permalink
Enhance GitHub Actions workflows: added linting, test coverage, and D…
Browse files Browse the repository at this point in the history
…ocker build steps
  • Loading branch information
AbdoAnss committed Dec 10, 2024
1 parent 0ae04a2 commit 95ab1a8
Showing 1 changed file with 70 additions and 6 deletions.
76 changes: 70 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go CI
name: Go CI/CD

on:
push:
Expand All @@ -9,7 +9,8 @@ on:
- main

jobs:
build-and-test:
test:
name: Test
runs-on: ubuntu-latest

steps:
Expand All @@ -30,10 +31,73 @@ jobs:
${{ runner.os }}-go-
- name: Install dependencies
run: |
go mod tidy || echo "Skipping go mod tidy as no dependencies exist"
run: go mod tidy

- name: Run unit tests
run: go test ./... -v -coverprofile=coverage.out

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.out
fail_ci_if_error: true

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run tests
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Install golangci-lint
run: |
go test ./... || echo "No tests to run"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.54.2
- name: Run golangci-lint
run: golangci-lint run ./...

build:
name: Build
runs-on: ubuntu-latest
needs: [test, lint]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Build application
run: go build -v ./...

docker-build:
name: Docker Build
runs-on: ubuntu-latest
needs: [build]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/go-fantasy-pl:latest

0 comments on commit 95ab1a8

Please sign in to comment.