Emit main.go contents to log; update CI (#95)

* Log out main.go contents

* Ignore `caddy` binary when using `./xcaddy` for testing

* Update CI, switch linter to match Caddy repo
This commit is contained in:
Francis Lavoie 2022-04-07 18:33:47 -04:00 committed by GitHub
parent 58e714eb0e
commit 7d6084b6d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 22 deletions

View file

@ -1,6 +1,6 @@
# Used as inspiration: https://github.com/mvdan/github-actions-golang
name: Cross-Platform Tests
name: Tests
on:
push:
@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ '1.16', '1.17' ]
go: [ '1.17', '1.18' ]
# Set some variables per OS, usable via ${{ matrix.VAR }}
# XCADDY_BIN_PATH: the path to the compiled xcaddy binary, for artifact publishing
@ -39,12 +39,12 @@ jobs:
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Print Go version and environment
id: vars
@ -92,25 +92,12 @@ jobs:
run: |
go test -v -coverprofile="cover-profile.out" -short -race ./...
# From https://github.com/reviewdog/action-golangci-lint
golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- name: Checkout code into the Go module directory
uses: actions/checkout@v2
- name: Run golangci-lint
uses: reviewdog/action-golangci-lint@v1
# uses: docker://reviewdog/action-golangci-lint:v1 # pre-build docker image
with:
github_token: ${{ secrets.github_token }}
goreleaser-check:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- uses: goreleaser/goreleaser-action@v2
with:
version: latest

27
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Lint
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
# From https://github.com/golangci/golangci-lint-action
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.44
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

View file

@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
go: [ '1.17' ]
go: [ '1.18' ]
runs-on: ${{ matrix.os }}
steps:

2
.gitignore vendored
View file

@ -4,6 +4,8 @@ _gitignore/
# build artifacts
cmd/xcaddy/xcaddy
cmd/xcaddy/xcaddy.exe
cmd/xcaddy/caddy
cmd/xcaddy/caddy.exe
# mac
.DS_Store

View file

@ -40,3 +40,7 @@ issues:
- text: "G204" # G204: Audit use of command execution
linters:
- gosec
# we're writing out the main.go to a temp dir, not sensitive
- text: "G306" # G306: Expect WriteFile permissions to be 0600 or less (gosec)
linters:
- gosec

View file

@ -83,7 +83,7 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {
// write the main module file to temporary folder
mainPath := filepath.Join(tempFolder, "main.go")
log.Printf("[INFO] Writing main module: %s", mainPath)
log.Printf("[INFO] Writing main module: %s\n%s", mainPath, buf.Bytes())
err = ioutil.WriteFile(mainPath, buf.Bytes(), 0644)
if err != nil {
return nil, err
@ -230,7 +230,7 @@ func (env environment) runCommand(ctx context.Context, cmd *exec.Cmd, timeout ti
// to the child process, so wait for it to die
select {
case <-time.After(15 * time.Second):
cmd.Process.Kill()
_ = cmd.Process.Kill()
case <-cmdErrChan:
}
return ctx.Err()