diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..4703554 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: [mholt] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c507238 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,115 @@ +# Used as inspiration: https://github.com/mvdan/github-actions-golang + +name: Cross-Platform Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + strategy: + # Default is true, cancels jobs for other platforms in the matrix if one fails + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + go-version: [ 1.14.x ] + + # Set some variables per OS, usable via ${{ matrix.VAR }} + # XCADDY_BIN_PATH: the path to the compiled Caddy binary, for artifact publishing + # SUCCESS: the typical value for $? per OS (Windows/pwsh returns 'True') + include: + - os: ubuntu-latest + XCADDY_BIN_PATH: ./cmd/xcaddy/xcaddy + SUCCESS: 0 + + - os: macos-latest + XCADDY_BIN_PATH: ./cmd/xcaddy/xcaddy + SUCCESS: 0 + + - os: windows-latest + XCADDY_BIN_PATH: ./cmd/xcaddy/xcaddy.exe + SUCCESS: 'True' + + runs-on: ${{ matrix.os }} + + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Print Go version and environment + id: vars + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env + # Calculate the short SHA1 hash of the git commit + echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + echo "::set-output name=go_cache::$(go env GOCACHE)" + + - name: Cache the build cache + uses: actions/cache@v1 + with: + path: ${{ steps.vars.outputs.go_cache }} + key: ${{ runner.os }}-go-ci-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-ci + + - name: Get dependencies + run: | + go get -v -t -d ./... + + - name: Build xCaddy + working-directory: ./cmd/xcaddy + env: + CGO_ENABLED: 0 + run: | + go build -trimpath -ldflags="-w -s" -v + + - name: Publish Build Artifact + uses: actions/upload-artifact@v1 + with: + name: xcaddy_${{ runner.os }}_${{ steps.vars.outputs.short_sha }} + path: ${{ matrix.XCADDY_BIN_PATH }} + + - name: Run tests + 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: goreleaser/goreleaser-action@v1 + with: + version: latest + args: check + env: + TAG: ${{ steps.vars.outputs.short_sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6178cc5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + release: + name: Release + strategy: + matrix: + os: [ ubuntu-latest ] + go-version: [ 1.14.x ] + runs-on: ${{ matrix.os }} + + steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + # So GoReleaser can generate the changelog properly + - name: Unshallowify the repo clone + run: git fetch --prune --unshallow + + - name: Print Go version and environment + id: vars + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env + echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + echo "::set-output name=go_cache::$(go env GOCACHE)" + + - name: Cache the build cache + uses: actions/cache@v1 + with: + path: ${{ steps.vars.outputs.go_cache }} + key: ${{ runner.os }}-go-release-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-release + + # GoReleaser will take care of publishing those artifacts into the release + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v1 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 63e3502..021f349 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ buildenv_*/ -_gitignore/ \ No newline at end of file +_gitignore/ +dist/ \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c1816f9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,42 @@ +linters-settings: + errcheck: + ignore: fmt:.*,io/ioutil:^Read.* + ignoretests: true + misspell: + locale: US + +linters: + enable: + - bodyclose + - prealloc + - unconvert + - errcheck + - gofmt + - goimports + - gosec + - ineffassign + - misspell + +run: + # default concurrency is a available CPU number. + # concurrency: 4 # explicitly omit this value to fully utilize available resources. + deadline: 5m + issues-exit-code: 1 + tests: false + +# output configuration options +output: + format: 'colored-line-number' + print-issued-lines: true + print-linter-name: true + +issues: + exclude-rules: + # we aren't calling unknown URL + - text: "G107" # G107: Url provided to HTTP request as taint input + linters: + - gosec + # we're shelling out to known commands, not relying on user-defined input. + - text: "G204" # G204: Audit use of command execution + linters: + - gosec diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..bc8414b --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,74 @@ +before: + hooks: + - go mod download + +builds: +- env: + - CGO_ENABLED=0 + - GO111MODULE=on + main: main.go + dir: ./cmd/xcaddy + binary: xcaddy + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - arm + - arm64 + - s390x + - ppc64le + goarm: + - 5 + - 6 + - 7 + ignore: + - goos: darwin + goarch: arm + - goos: darwin + goarch: ppc64le + - goos: darwin + goarch: s390x + - goos: windows + goarch: ppc64le + - goos: windows + goarch: s390x + - goos: freebsd + goarch: ppc64le + - goos: freebsd + goarch: s390x + - goos: freebsd + goarch: arm + goarm: 5 + flags: + - -trimpath + ldflags: + - -s -w + +archives: + - format_overrides: + - goos: windows + format: zip + replacements: + darwin: mac +checksum: + algorithm: sha512 + + +release: + github: + owner: caddyserver + name: xcaddy + draft: true + prerelease: auto + +changelog: + sort: asc + filters: + exclude: + - '^chore:' + - '^ci:' + - '^docs?:' + - '^tests?:'