Skip to content

Commit

Permalink
chore: refurbish CI setup (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon authored Feb 10, 2023
1 parent da8faf4 commit 59174a0
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 78 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/go-test.yml

This file was deleted.

56 changes: 56 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Go
on:
push:
branches: [ main ]
paths:
- '**.go'
- 'go.mod'
- '.golangci.yml'
- '.github/workflows/go.yml'
pull_request:
paths:
- '**.go'
- 'go.mod'
- '.golangci.yml'
- '.github/workflows/go.yml'
env:
GOPROXY: "https://proxy.golang.org"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: --timeout=30m
- name: Check Go module tidiness
shell: bash
run: |
go mod tidy
STATUS=$(git status --porcelain go.mod go.sum)
if [ ! -z "$STATUS" ]; then
echo "Running go mod tidy modified go.mod and/or go.sum"
exit 1
fi
test:
name: Test
strategy:
matrix:
go-version: [ 1.18.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests with coverage
run: go test -v -race ./...
27 changes: 21 additions & 6 deletions .github/workflows/lsif.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
name: LSIF
on:
- push
push:
paths:
- '**.go'
- 'go.mod'
- '.github/workflows/lsif.yml'
env:
GOPROXY: "https://proxy.golang.org"

jobs:
lsif-go:
if: github.repository == 'sourcegraph/docsite'
runs-on: ubuntu-latest
container: sourcegraph/lsif-go
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Generate LSIF data
run: lsif-go
- name: Upload LSIF data
run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
uses: sourcegraph/lsif-go-action@master
- name: Upload LSIF data to sourcegraph.com
continue-on-error: true
uses: docker://sourcegraph/src-cli:latest
with:
args: lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
- name: Upload LSIF data to S2
continue-on-error: true
uses: docker://sourcegraph/src-cli:latest
with:
args: -endpoint=https://sourcegraph.sourcegraph.com lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/docsite/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
)

handler := func(args []string) error {
flagSet.Parse(args)
_ = flagSet.Parse(args)
site, _, err := siteFromFlags()
if err != nil {
return err
Expand All @@ -25,7 +25,7 @@ func init() {
}
if len(problems) > 0 {
for _, problem := range problems {
fmt.Fprintln(os.Stderr, problem)
_, _ = fmt.Fprintln(os.Stderr, problem)
}
return fmt.Errorf("%d problems found", len(problems))
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/docsite/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName string, usage *template.Te
}
}
if !flagSet.Parsed() {
flagSet.Parse(args)
_ = flagSet.Parse(args)
}

// Print usage if the command is "help".
Expand All @@ -82,21 +82,21 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName string, usage *template.Te
for _, cmd_ := range c {
cmd := cmd_
cmd.FlagSet.Usage = func() {
fmt.Fprintln(commandLine.Output(), "Usage:")
fmt.Fprintln(commandLine.Output())
fmt.Fprintf(commandLine.Output(), " %s [options] %s", cmdName, cmd.FlagSet.Name())
_, _ = fmt.Fprintln(commandLine.Output(), "Usage:")
_, _ = fmt.Fprintln(commandLine.Output())
_, _ = fmt.Fprintf(commandLine.Output(), " %s [options] %s", cmdName, cmd.FlagSet.Name())
if hasFlags(cmd.FlagSet) {
fmt.Fprint(commandLine.Output(), " [command options]")
_, _ = fmt.Fprint(commandLine.Output(), " [command options]")
}
fmt.Fprintln(commandLine.Output())
_, _ = fmt.Fprintln(commandLine.Output())
if cmd.LongDescription != "" {
fmt.Fprintln(commandLine.Output())
fmt.Fprintln(commandLine.Output(), cmd.LongDescription)
fmt.Fprintln(commandLine.Output())
_, _ = fmt.Fprintln(commandLine.Output())
_, _ = fmt.Fprintln(commandLine.Output(), cmd.LongDescription)
_, _ = fmt.Fprintln(commandLine.Output())
}
if hasFlags(cmd.FlagSet) {
fmt.Fprintln(commandLine.Output(), "The command options are:")
fmt.Fprintln(commandLine.Output())
_, _ = fmt.Fprintln(commandLine.Output(), "The command options are:")
_, _ = fmt.Fprintln(commandLine.Output())
cmd.FlagSet.PrintDefaults()
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/docsite/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func init() {
)

handler := func(args []string) error {
flagSet.Parse(args)
_ = flagSet.Parse(args)
site, _, err := siteFromFlags()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/docsite/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func init() {
flagSet := flag.NewFlagSet("info", flag.ExitOnError)

handler := func(args []string) error {
flagSet.Parse(args)
_ = flagSet.Parse(args)
_, conf, err := siteFromFlags()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/docsite/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
)

handler := func(args []string) error {
flagSet.Parse(args)
_ = flagSet.Parse(args)
site, _, err := siteFromFlags()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/docsite/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
)

handler := func(args []string) error {
flagSet.Parse(args)
_ = flagSet.Parse(args)

host, port, err := net.SplitHostPort(*httpAddr)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/docsite/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"unicode"

"github.com/pkg/errors"
"github.com/sourcegraph/docsite"
"golang.org/x/tools/godoc/vfs/httpfs"
"golang.org/x/tools/godoc/vfs/mapfs"

"github.com/sourcegraph/docsite"
)

func siteFromFlags() (*docsite.Site, *docsiteConfig, error) {
Expand Down Expand Up @@ -375,7 +376,6 @@ func zipFileSystemAtURL(url, dir string) (http.FileSystem, error) {
if err != nil {
return nil, err
}
body = nil
z = nil

return httpfs.New(mapfs.New(m)), nil
Expand Down
16 changes: 8 additions & 8 deletions cmd/docsite/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func TestMapFromZipArchive(t *testing.T) {
if err != nil {
t.Fatal(err)
}
f1.Write([]byte("1"))
_, _ = f1.Write([]byte("1"))
f2, err := zw.Create("c/2")
if err != nil {
t.Fatal(err)
}
f2.Write([]byte("2"))
zw.Close()
_, _ = f2.Write([]byte("2"))
_ = zw.Close()

zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if err != nil {
Expand All @@ -46,13 +46,13 @@ func TestMapFromZipArchive(t *testing.T) {
if err != nil {
t.Fatal(err)
}
f1.Write([]byte("../c/target"))
_, _ = f1.Write([]byte("../c/target"))
f2, err := zw.Create("c/target")
if err != nil {
t.Fatal(err)
}
f2.Write([]byte("x"))
zw.Close()
_, _ = f2.Write([]byte("x"))
_ = zw.Close()

zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if err != nil {
Expand All @@ -76,8 +76,8 @@ func TestMapFromZipArchive(t *testing.T) {
if err != nil {
t.Fatal(err)
}
f1.Write([]byte("../doesnotexist"))
zw.Close()
_, _ = f1.Write([]byte("../doesnotexist"))
_ = zw.Close()

zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func WalkFileSystem(fs http.FileSystem, filterFn func(path string) bool, walkFn
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("open walk root %s", path))
}
defer root.Close()
defer func() { _ = root.Close() }()
fi, err := root.Stat()
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("stat walk root %s", path))
Expand All @@ -41,7 +41,7 @@ func WalkFileSystem(fs http.FileSystem, filterFn func(path string) bool, walkFn
return errors.WithMessage(err, fmt.Sprintf("open %s", item.path))
}
entries, err := dir.Readdir(-1)
dir.Close()
_ = dir.Close()
if err != nil {
return errors.WithMessage(err, fmt.Sprintf("readdir %s", item.path))
}
Expand Down
6 changes: 2 additions & 4 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ func createMarkdownFuncs(site *Site) markdown.FuncMap {
return string(doc.HTML), nil
},
}
if testMarkdownFuncs != nil {
for name, f := range testMarkdownFuncs {
m[name] = f
}
for name, f := range testMarkdownFuncs {
m[name] = f
}
return m
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require (
github.com/alecthomas/chroma v0.10.0
github.com/mozillazg/go-slugify v0.2.0
github.com/pkg/errors v0.9.1
github.com/russross/blackfriday/v2 v2.0.1
github.com/shurcooL/sanitized_anchor_name v1.0.0
github.com/sourcegraph/go-jsonschema v0.0.0-20191016093751-6a4f2b621f5d
github.com/sourcegraph/jsonschemadoc v0.0.0-20190214000648-1850b818f08c
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sourcegraph/go-jsonschema v0.0.0-20190205151546-7939fa138765/go.mod h1:6DfNy4BLIggAeittTJ8o9z/6d1ly+YujBTSnv03i7Bk=
Expand Down
19 changes: 19 additions & 0 deletions golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
linters-settings:
nakedret:
max-func-lines: 0 # Disallow any unnamed return statement

linters:
enable:
- unused
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- nakedret
- gofmt
- rowserrcheck
- unconvert
- goimports
- unparam
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Site) Handler() http.Handler {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
setCacheControl(w, r, cacheMaxAgeShort)
if r.Method == "GET" {
w.Write(respData)
_, _ = w.Write(respData)
}
}))

Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *Site) Handler() http.Handler {

w.Header().Set("Content-Type", "text/html; charset=utf-8")
if r.Method == "GET" {
w.Write(respData)
_, _ = w.Write(respData)
}
})))

Expand Down

0 comments on commit 59174a0

Please sign in to comment.