Skip to content

Commit

Permalink
Emit main.go contents to log; update CI (#95)
Browse files Browse the repository at this point in the history
* Log out main.go contents

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

* Update CI, switch linter to match Caddy repo
  • Loading branch information
francislavoie authored Apr 7, 2022
1 parent 58e714e commit 7d6084b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used as inspiration: https://github.com/mvdan/github-actions-golang

name: Cross-Platform Tests
name: Tests

on:
push:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
go: [ '1.17' ]
go: [ '1.18' ]
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ _gitignore/
# build artifacts
cmd/xcaddy/xcaddy
cmd/xcaddy/xcaddy.exe
cmd/xcaddy/caddy
cmd/xcaddy/caddy.exe

# mac
.DS_Store
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7d6084b

Please sign in to comment.