diff --git a/.github/workflows/go-cross.yml b/.github/workflows/go-cross.yml new file mode 100644 index 00000000..9929e37f --- /dev/null +++ b/.github/workflows/go-cross.yml @@ -0,0 +1,45 @@ +name: Go Matrix +on: [push, pull_request] + +jobs: + + cross: + name: Go + runs-on: ${{ matrix.os }} + env: + CGO_ENABLED: 0 + + strategy: + matrix: + go-version: [ 1.14, 1.15, 1.x ] + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + # https://github.com/marketplace/actions/checkout + - name: Checkout code + uses: actions/checkout@v2 + + # https://github.com/marketplace/actions/cache + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + ~/Library/Caches/go-build # Build cache (Mac) + '%LocalAppData%\go-build' # Build cache (Windows) + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Test + run: go test -v -cover ./... + + - name: Build + run: go build -v -ldflags "-s -w" -trimpath -o ./dist/lego ./cmd/lego/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..758b3dfd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,127 @@ +name: Main + +on: + push: + branches: + - master + tags: + - v* + pull_request: + +jobs: + + main: + name: Main Process + runs-on: ubuntu-latest + env: + GO_VERSION: 1.15 + GOLANGCI_LINT_VERSION: v1.33.0 + HUGO_VERSION: 0.54.0 + SEIHON_VERSION: v0.5.1 + CGO_ENABLED: 0 + LEGO_E2E_TESTS: CI + MEMCACHED_HOSTS: localhost:11211 + + steps: + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + # https://github.com/marketplace/actions/checkout + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # https://github.com/marketplace/actions/cache + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Check and get dependencies + run: | + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + go mod download + + - name: Documentation validation + run: make validate-doc + + # https://golangci-lint.run/usage/install#other-ci + - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + golangci-lint --version + + - name: Install Pebble and challtestsrv + run: GO111MODULE=off go get -u github.com/letsencrypt/pebble/... + + - name: Set up a Memcached server + uses: niden/actions-memcached@v7 + + - name: Setup /etc/hosts + run: | + echo "127.0.0.1 acme.wtf" | sudo tee -a /etc/hosts + echo "127.0.0.1 lego.wtf" | sudo tee -a /etc/hosts + echo "127.0.0.1 acme.lego.wtf" | sudo tee -a /etc/hosts + echo "127.0.0.1 légô.wtf" | sudo tee -a /etc/hosts + echo "127.0.0.1 xn--lg-bja9b.wtf" | sudo tee -a /etc/hosts + + - name: Make + run: | + make + make clean + + - name: Install Hugo + run: | + wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.deb + sudo dpkg -i /tmp/hugo.deb + + - name: Build Documentation + run: make docs-build + + # https://github.com/marketplace/actions/github-pages + - name: Deploy to GitHub Pages + uses: crazy-max/ghaction-github-pages@v2 + if: github.event_name == 'push' + with: + target_branch: gh-pages + build_dir: docs/public + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # https://goreleaser.com/ci/actions/ + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + if: startsWith(github.ref, 'refs/tags/v') + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} + + # Install Docker image multi-arch builder + - name: Install Seihon ${{ env.SEIHON_VERSION }} + if: startsWith(github.ref, 'refs/tags/v') + run: | + curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION} + seihon --version + + - name: Docker Login + if: startsWith(github.ref, 'refs/tags/v') + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + + - name: Publish Docker Images (Seihon) + if: startsWith(github.ref, 'refs/tags/v') + run: make publish-images diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 218953e5..00000000 --- a/.travis.yml +++ /dev/null @@ -1,105 +0,0 @@ -language: go - -cache: - directories: - - $GOPATH/pkg/mod - -jobs: - fast_finish: true - include: - - go: 1.14.x - - go: 1.15.x - env: STABLE=true - - go: 1.x - - go: tip - allow_failures: - - go: tip - -go_import_path: github.com/go-acme/lego - -env: - global: - - MEMCACHED_HOSTS=localhost:11211 - - GO111MODULE=on - -services: - - memcached - -addons: - hosts: - # for e2e tests - - acme.wtf - - lego.wtf - - acme.lego.wtf - - légô.wtf - - xn--lg-bja9b.wtf - -before_install: - - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_26c593b079d9_key -iv $encrypted_26c593b079d9_iv -in .gitcookies.enc -out .gitcookies -d || true' - - # Install Pebble and challtestsrv - - GO111MODULE=off go get -u github.com/letsencrypt/pebble/... - - # Install linters and misspell - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION} - - golangci-lint --version - - # Hugo - documentation - - wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.54.0/hugo_0.54.0_Linux-64bit.deb - - sudo dpkg -i /tmp/hugo.deb - - # Install Docker image multi-arch builder - - curl -sfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | bash -s -- -b "${GOPATH}/bin" ${SEIHON_VERSION} - - seihon --version - -install: - - go mod tidy - - git diff --exit-code go.mod - - git diff --exit-code go.sum - - go mod download - -before_script: - - make validate-doc - -after_success: - - make clean - -before_deploy: - - > - if ! [ "$BEFORE_DEPLOY_RUN" ]; then - export BEFORE_DEPLOY_RUN=1; - make docs-build; - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin; - fi - -deploy: - - provider: pages - local_dir: docs/public - skip_cleanup: true - github_token: ${GITHUB_TOKEN} - on: - condition: $STABLE = true - - - provider: script - skip_cleanup: true - script: curl -sL https://git.io/goreleaser | bash - on: - tags: true - condition: $STABLE = true - - - provider: releases - api_key: ${GITHUB_TOKEN} - file: dist/lego_* - skip_cleanup: true - overwrite: true - file_glob: true - on: - tags: true - condition: $STABLE = true - - - provider: script - skip_cleanup: true - script: make publish-images - on: - tags: true - condition: $STABLE = true diff --git a/Makefile b/Makefile index 05005875..0e752877 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,6 @@ export GO111MODULE=on export CGO_ENABLED=0 -SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/') - LEGO_IMAGE := goacme/lego MAIN_DIRECTORY := ./cmd/lego/ @@ -40,9 +38,6 @@ e2e: clean checks: golangci-lint run -fmt: - gofmt -s -l -w $(SRCS) - # Release helper .PHONY: patch minor major detach diff --git a/e2e/loader/loader.go b/e2e/loader/loader.go index 69ebc00b..1ac47003 100644 --- a/e2e/loader/loader.go +++ b/e2e/loader/loader.go @@ -38,9 +38,8 @@ type EnvLoader struct { } func (l *EnvLoader) MainTest(m *testing.M) int { - _, force := os.LookupEnv("LEGO_E2E_TESTS") - if _, ci := os.LookupEnv("CI"); !ci && !force { - fmt.Fprintln(os.Stderr, "skipping test: e2e tests are disabled. (no 'CI' or 'LEGO_E2E_TESTS' env var)") + if _, e2e := os.LookupEnv("LEGO_E2E_TESTS"); !e2e { + fmt.Fprintln(os.Stderr, "skipping test: e2e tests are disabled. (no 'LEGO_E2E_TESTS' env var)") fmt.Println("PASS") return 0 } diff --git a/platform/wait/wait_test.go b/platform/wait/wait_test.go index fc6673c1..e87f055e 100644 --- a/platform/wait/wait_test.go +++ b/platform/wait/wait_test.go @@ -8,13 +8,12 @@ import ( func TestForTimeout(t *testing.T) { c := make(chan error) go func() { - err := For("", 3*time.Second, 1*time.Second, func() (bool, error) { + c <- For("", 3*time.Second, 1*time.Second, func() (bool, error) { return false, nil }) - c <- err }() - timeout := time.After(4 * time.Second) + timeout := time.After(5 * time.Second) select { case <-timeout: t.Fatal("timeout exceeded") diff --git a/providers/dns/exec/exec_test.go b/providers/dns/exec/exec_test.go index 619fbf86..3a2edbbf 100644 --- a/providers/dns/exec/exec_test.go +++ b/providers/dns/exec/exec_test.go @@ -3,6 +3,7 @@ package exec import ( "fmt" "os" + "strings" "testing" "github.com/go-acme/lego/v4/log" @@ -37,7 +38,7 @@ func TestDNSProvider_Present(t *testing.T) { Mode: "", }, expected: expected{ - args: "present _acme-challenge.domain. pW9ZKG0xz_PCriK-nCMOjADy9eJcgGWIzkkj2fN4uZM\n", + args: "present _acme-challenge.domain. pW9ZKG0xz_PCriK-nCMOjADy9eJcgGWIzkkj2fN4uZM", }, }, { @@ -55,7 +56,7 @@ func TestDNSProvider_Present(t *testing.T) { Mode: "RAW", }, expected: expected{ - args: "present -- domain token keyAuth\n", + args: "present -- domain token keyAuth", }, }, } @@ -78,7 +79,7 @@ func TestDNSProvider_Present(t *testing.T) { require.Error(t, err) } else { require.NoError(t, err) - assert.Equal(t, test.expected.args, message) + assert.Equal(t, test.expected.args, strings.TrimSpace(message)) } }) } @@ -110,7 +111,7 @@ func TestDNSProvider_CleanUp(t *testing.T) { Mode: "", }, expected: expected{ - args: "cleanup _acme-challenge.domain. pW9ZKG0xz_PCriK-nCMOjADy9eJcgGWIzkkj2fN4uZM\n", + args: "cleanup _acme-challenge.domain. pW9ZKG0xz_PCriK-nCMOjADy9eJcgGWIzkkj2fN4uZM", }, }, { @@ -128,7 +129,7 @@ func TestDNSProvider_CleanUp(t *testing.T) { Mode: "RAW", }, expected: expected{ - args: "cleanup -- domain token keyAuth\n", + args: "cleanup -- domain token keyAuth", }, }, } @@ -151,7 +152,7 @@ func TestDNSProvider_CleanUp(t *testing.T) { require.Error(t, err) } else { require.NoError(t, err) - assert.Equal(t, test.expected.args, message) + assert.Equal(t, test.expected.args, strings.TrimSpace(message)) } }) } diff --git a/providers/dns/gcloud/googlecloud_test.go b/providers/dns/gcloud/googlecloud_test.go index 8379e6ae..35efb3ef 100644 --- a/providers/dns/gcloud/googlecloud_test.go +++ b/providers/dns/gcloud/googlecloud_test.go @@ -52,7 +52,8 @@ func TestNewDNSProvider(t *testing.T) { envGoogleApplicationCredentials: "not-a-secret-file", envMetadataHost: "http://lego.wtf", // defined here to avoid the client cache. }, - expected: "googlecloud: unable to get Google Cloud client: google: error getting credentials using GOOGLE_APPLICATION_CREDENTIALS environment variable: open not-a-secret-file: no such file or directory", + // the error message varies according to the OS used. + expected: "googlecloud: unable to get Google Cloud client: google: error getting credentials using GOOGLE_APPLICATION_CREDENTIALS environment variable: ", }, { desc: "missing project", @@ -95,7 +96,8 @@ func TestNewDNSProvider(t *testing.T) { require.NotNil(t, p.config) require.NotNil(t, p.client) } else { - require.EqualError(t, err, test.expected) + require.Error(t, err) + require.Contains(t, err.Error(), test.expected) } }) } diff --git a/providers/dns/oraclecloud/oraclecloud_test.go b/providers/dns/oraclecloud/oraclecloud_test.go index 1f94fb61..81c905c4 100644 --- a/providers/dns/oraclecloud/oraclecloud_test.go +++ b/providers/dns/oraclecloud/oraclecloud_test.go @@ -101,7 +101,7 @@ func TestNewDNSProvider(t *testing.T) { EnvRegion: "us-phoenix-1", EnvCompartmentOCID: "123", }, - expected: "oraclecloud: can not create client, bad configuration: x509: decryption password incorrect", + expected: "oraclecloud: can not create client, bad configuration: ", }, { desc: "missing OCI_TENANCY_OCID", @@ -191,7 +191,8 @@ func TestNewDNSProvider(t *testing.T) { require.NotNil(t, p.config) require.NotNil(t, p.client) } else { - require.EqualError(t, err, test.expected) + require.Error(t, err) + require.Contains(t, err.Error(), test.expected) } }) }