Skip to content

amwolff/example-github-actions-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example GitHub Actions workflow for Go CI

Inspired by the awesome GitHub Actions for Go.

The workflow

$ cat .github/workflows/ci.yml
name: CI

on:
  push:
    branches: [ main ]
    tags: [ v* ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    name: Build & Test
    runs-on: ${{ matrix.os }}
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}

      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: Cache ~/go/pkg/mod
        uses: actions/cache@v2
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

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

      - name: Test
        run: go test -a -race -v ./...
    strategy:
      matrix:
        go-version: [ 1.15.x ]
        os: [ ubuntu-latest ]
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: v1.31
          args: -E goimports

Summary

This workflow

  • uses new GitHub's default branch name;
  • uses caching;
  • uses golangci-lint with default settings and goimports enabled;
  • is easy to use and extend!

You can add more Go versions and operating systems into the strategy matrix, modify Go compiler flags and play around with golangci-lint linters.

About

Easy to use and extend GitHub Actions workflow for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published