Skip to content

Commit

Permalink
add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lwnmengjing committed Jul 17, 2024
1 parent ec57626 commit f8e99db
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
paths-ignore:
- 'docs/**'
- '.github/**'
- '.gitignore'
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Install dependencies
run: make deps
- name: Unit Test
run: make test

- name: Convert coverage report to table
run: go tool cover -func=coverage.out | tail -n +2 | awk '{print "|",$1,"|",$3,"|"}' > coverage_table.md

- name: Comment on PR with coverage table
if: github.event_name == 'pull_request'
working-directory: cmd/tools/pr
run: go mod tidy && go run main.go
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_NAME: ${{ github.repository }}
PR_NUMBER: ${{ github.event.number }}
COVERAGE_FILE: ../../../coverage_table.md
- name: Build
run: make build
- name: Vendor
run: go mod vendor

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
if: github.event_name != 'pull_request'
uses: docker/setup-buildx-action@v3

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v5
with:
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}'
flavor: |
latest=auto
tags: |
type=schedule
type=ref,event=tag
type=sha,prefix=,format=long,enable=true,priority=100
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ build:
generate:
go generate ./...
test:
go test ./...
go test -coverprofile=coverage.out ./...
deps:
go mod download

.PHONY: check
check:
Expand Down

0 comments on commit f8e99db

Please sign in to comment.