Skip to content

Commit

Permalink
add actions (#1)
Browse files Browse the repository at this point in the history
* add actions

* devcontainers

* fmt

* go 1.20 and 1.21
  • Loading branch information
franchb authored Sep 26, 2023
1 parent e01b5db commit efb6d5e
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:1.21-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {},
"extensions": [
"streetsidesoftware.code-spell-checker"
]
}
}

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [9000],

// Use 'portsAttributes' to set default properties for specific forwarded ports.
// More info: https://containers.dev/implementors/json_reference/#port-attributes
// "portsAttributes": {
// "9000": {
// "label": "Hello Remote World",
// "onAutoForward": "notify"
// }
//}

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "gomod"
commit-message:
prefix: "deps:"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "12:00"
- package-ecosystem: "github-actions"
commit-message:
prefix: "deps:"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "12:00"
80 changes: 80 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: build

permissions: {} # no need any permissions

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 10 * * 1' # run "At 10:00 on Monday"
workflow_call:
inputs:
skipTests:
description: 'Skip tests, useful when there is a dedicated CI job for tests'
default: false
required: false
type: boolean

jobs:
run:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
go: ['stable', 'oldstable']

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Vet
run: go vet ./...

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go Mod
run: go mod download

- name: Go Mod Verify
run: go mod verify

- name: Go Generate
run: go generate ./... && git diff --exit-code

- name: Go Build
run: go build -o /dev/null ./...

- name: Go Compile Tests
if: ${{ inputs.skipTests }}
run: go test -exec /bin/true ./...

- name: Go Test
if: ${{ !inputs.skipTests }}
run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./...

- name: Go Benchmark
if: ${{ !inputs.skipTests }}
run: go test -v -shuffle=on -run=- -bench=. -benchtime=1x ./...

- name: Upload Coverage
if: ${{ !inputs.skipTests }}
uses: codecov/codecov-action@v3
continue-on-error: true
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.txt
fail_ci_if_error: false
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: lint

permissions: {} # no need any permissions

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_call:

jobs:
run:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true

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

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 'stable'
check-latest: true

- name: Lint
uses: golangci/[email protected]
with:
version: latest
args: --timeout 5m
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test

on:
workflow_call:

jobs:
run:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
go: ['stable', 'oldstable']

steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
check-latest: true

- name: Checkout code
uses: actions/checkout@v4

- name: Run tests
run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./...

- name: Upload Coverage
uses: codecov/codecov-action@v3
continue-on-error: true
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.txt
fail_ci_if_error: false
36 changes: 36 additions & 0 deletions .github/workflows/vuln.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: vuln

permissions: {} # no need any permissions

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 10 * * 1' # run "At 10:00 on Monday"
workflow_call:

jobs:
run:
name: Vuln
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true

steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 'stable'
check-latest: true

- name: Checkout
uses: actions/checkout@v4

- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest

- name: Run govulncheck
run: govulncheck -test ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# .github-go
GitHub actions for Go projects

See [Reusing Workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/franchb/.github-go

go 1.20
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
println("github.com/franchb/.github-go ready")
}
9 changes: 9 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "testing"

func TestSimple(t *testing.T) {
if 0 == 1 {
t.Fatal("impossible")
}
}

0 comments on commit efb6d5e

Please sign in to comment.