Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 01:00 UTC
| 1 | # Used as inspiration: https://github.com/mvdan/github-actions-golang |
| 2 | |
| 3 | name: Tests |
| 4 | |
| 5 | on: |
| 6 | push: |
| 7 | branches: |
| 8 | - master |
| 9 | - 2.* |
| 10 | pull_request: |
| 11 | branches: |
| 12 | - master |
| 13 | - 2.* |
| 14 | |
| 15 | env: |
| 16 | GOFLAGS: '-tags=nobadger,nomysql,nopgx' |
| 17 | # https://github.com/actions/setup-go/issues/491 |
| 18 | GOTOOLCHAIN: local |
| 19 | |
| 20 | permissions: |
| 21 | contents: read |
| 22 | |
| 23 | jobs: |
| 24 | test: |
| 25 | strategy: |
| 26 | # Default is true, cancels jobs for other platforms in the matrix if one fails |
| 27 | fail-fast: false |
| 28 | matrix: |
| 29 | os: |
| 30 | - linux |
| 31 | - mac |
| 32 | - windows |
| 33 | go: |
| 34 | - '1.27' |
| 35 | |
| 36 | include: |
| 37 | # Set the minimum Go patch version for the given Go minor |
| 38 | # Usable via ${{ matrix.GO_SEMVER }} |
| 39 | - go: '1.27' |
| 40 | GO_SEMVER: '~1.27.0' |
| 41 | |
| 42 | # Set some variables per OS, usable via ${{ matrix.VAR }} |
| 43 | # OS_LABEL: the VM label from GitHub Actions (see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories) |
| 44 | # CADDY_BIN_PATH: the path to the compiled Caddy binary, for artifact publishing |
| 45 | # SUCCESS: the typical value for $? per OS (Windows/pwsh returns 'True') |
| 46 | - os: linux |
| 47 | OS_LABEL: ubuntu-latest |
| 48 | CADDY_BIN_PATH: ./cmd/caddy/caddy |
| 49 | SUCCESS: 0 |
| 50 | |
| 51 | - os: mac |
| 52 | OS_LABEL: macos-latest |
| 53 | CADDY_BIN_PATH: ./cmd/caddy/caddy |
| 54 | SUCCESS: 0 |
| 55 | |
| 56 | - os: windows |
| 57 | OS_LABEL: windows-latest |
| 58 | CADDY_BIN_PATH: ./cmd/caddy/caddy.exe |
| 59 | SUCCESS: 'True' |
| 60 | |
| 61 | runs-on: ${{ matrix.OS_LABEL }} |
| 62 | permissions: |
| 63 | contents: read |
| 64 | pull-requests: read |
| 65 | actions: write # to allow uploading artifacts and cache |
| 66 | steps: |
| 67 | - name: Harden the runner (Audit all outbound calls) |
| 68 | uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 |
| 69 | with: |
| 70 | egress-policy: audit |
| 71 | |
| 72 | - name: Checkout code |
| 73 | uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 74 | |
| 75 | - name: Install Go |
| 76 | uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 77 | with: |
| 78 | go-version: ${{ matrix.GO_SEMVER }} |
| 79 | check-latest: true |
| 80 | |
| 81 | # These tools would be useful if we later decide to reinvestigate |
| 82 | # publishing test/coverage reports to some tool for easier consumption |
| 83 | # - name: Install test and coverage analysis tools |
| 84 | # run: | |
| 85 | # go get github.com/axw/gocov/gocov |
| 86 | # go get github.com/AlekSi/gocov-xml |
| 87 | # go get -u github.com/jstemmer/go-junit-report |
| 88 | # echo "$(go env GOPATH)/bin" >> $GITHUB_PATH |
| 89 | |
| 90 | - name: Print Go version and environment |
| 91 | id: vars |
| 92 | shell: bash |
| 93 | run: | |
| 94 | printf "Using go at: $(which go)\n" |
| 95 | printf "Go version: $(go version)\n" |
| 96 | printf "\n\nGo environment:\n\n" |
| 97 | go env |
| 98 | printf "\n\nSystem environment:\n\n" |
| 99 | env |
| 100 | printf "Git version: $(git version)\n\n" |
| 101 | # Calculate the short SHA1 hash of the git commit |
| 102 | echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 103 | |
| 104 | - name: Get dependencies |
| 105 | run: | |
| 106 | go get -v -t -d ./... |
| 107 | # mkdir test-results |
| 108 | |
| 109 | - name: Build Caddy |
| 110 | working-directory: ./cmd/caddy |
| 111 | env: |
| 112 | CGO_ENABLED: 0 |
| 113 | run: | |
| 114 | go build -trimpath -ldflags="-w -s" -v |
| 115 | |
| 116 | - name: Smoke test Caddy |
| 117 | working-directory: ./cmd/caddy |
| 118 | run: | |
| 119 | ./caddy start |
| 120 | ./caddy stop |
| 121 | |
| 122 | - name: Publish Build Artifact |
| 123 | uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 |
| 124 | with: |
| 125 | name: caddy_${{ runner.os }}_go${{ matrix.go }}_${{ steps.vars.outputs.short_sha }} |
| 126 | path: ${{ matrix.CADDY_BIN_PATH }} |
| 127 | compression-level: 0 |
| 128 | |
| 129 | # Commented bits below were useful to allow the job to continue |
| 130 | # even if the tests fail, so we can publish the report separately |
| 131 | # For info about set-output, see https://stackoverflow.com/questions/57850553/github-actions-check-steps-status |
| 132 | - name: Run tests |
| 133 | # id: step_test |
| 134 | # continue-on-error: true |
| 135 | env: |
| 136 | GODEBUG: http2xconnect=1 |
| 137 | run: | |
| 138 | # (go test -coverprofile=cover-profile.out -race ./... 2>&1) > test-results/test-result.out |
| 139 | go test -coverprofile="cover-profile.out" -short -race ./... |
| 140 | # echo "status=$?" >> $GITHUB_OUTPUT |
| 141 | |
| 142 | # Relevant step if we reinvestigate publishing test/coverage reports |
| 143 | # - name: Prepare coverage reports |
| 144 | # run: | |
| 145 | # mkdir coverage |
| 146 | # gocov convert cover-profile.out > coverage/coverage.json |
| 147 | # # Because Windows doesn't work with input redirection like *nix, but output redirection works. |
| 148 | # (cat ./coverage/coverage.json | gocov-xml) > coverage/coverage.xml |
| 149 | |
| 150 | # To return the correct result even though we set 'continue-on-error: true' |
| 151 | # - name: Coerce correct build result |
| 152 | # if: matrix.os != 'windows' && steps.step_test.outputs.status != ${{ matrix.SUCCESS }} |
| 153 | # run: | |
| 154 | # echo "step_test ${{ steps.step_test.outputs.status }}\n" |
| 155 | # exit 1 |
| 156 | |
| 157 | s390x-test: |
| 158 | name: test (s390x on IBM Z) |
| 159 | permissions: |
| 160 | contents: read |
| 161 | pull-requests: read |
| 162 | runs-on: ubuntu-latest |
| 163 | if: github.event.pull_request.head.repo.full_name == 'caddyserver/caddy' && github.actor != 'dependabot[bot]' |
| 164 | continue-on-error: true # August 2020: s390x VM is down due to weather and power issues |
| 165 | steps: |
| 166 | - name: Harden the runner (Audit all outbound calls) |
| 167 | uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 |
| 168 | with: |
| 169 | egress-policy: audit |
| 170 | allowed-endpoints: ci-s390x.caddyserver.com:22 |
| 171 | |
| 172 | - name: Checkout code |
| 173 | uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 174 | - name: Run Tests |
| 175 | run: | |
| 176 | set +e |
| 177 | mkdir -p ~/.ssh && echo -e "${SSH_KEY//_/\\n}" > ~/.ssh/id_ecdsa && chmod og-rwx ~/.ssh/id_ecdsa |
| 178 | |
| 179 | # short sha is enough? |
| 180 | short_sha=$(git rev-parse --short HEAD) |
| 181 | |
| 182 | # To shorten the following lines |
| 183 | ssh_opts="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" |
| 184 | ssh_host="$CI_USER@ci-s390x.caddyserver.com" |
| 185 | |
| 186 | # The environment is fresh, so there's no point in keeping accepting and adding the key. |
| 187 | rsync -arz -e "ssh $ssh_opts" --progress --delete --exclude '.git' . "$ssh_host":/var/tmp/"$short_sha" |
| 188 | ssh $ssh_opts -t "$ssh_host" bash <<EOF |
| 189 | cd /var/tmp/$short_sha |
| 190 | go version |
| 191 | go env |
| 192 | printf "\n\n" |
| 193 | retries=3 |
| 194 | exit_code=0 |
| 195 | while ((retries > 0)); do |
| 196 | GODEBUG=http2xconnect=1 CGO_ENABLED=0 go test -p 1 ./... |
| 197 | exit_code=$? |
| 198 | if ((exit_code == 0)); then |
| 199 | break |
| 200 | fi |
| 201 | echo "\n\nTest failed: \$exit_code, retrying..." |
| 202 | ((retries--)) |
| 203 | done |
| 204 | echo "Remote exit code: \$exit_code" |
| 205 | exit \$exit_code |
| 206 | EOF |
| 207 | test_result=$? |
| 208 | |
| 209 | # There's no need leaving the files around |
| 210 | ssh $ssh_opts "$ssh_host" "rm -rf /var/tmp/'$short_sha'" |
| 211 | |
| 212 | echo "Test exit code: $test_result" |
| 213 | exit $test_result |
| 214 | env: |
| 215 | SSH_KEY: ${{ secrets.S390X_SSH_KEY }} |
| 216 | CI_USER: ${{ secrets.CI_USER }} |
| 217 | |
| 218 | goreleaser-check: |
| 219 | runs-on: ubuntu-latest |
| 220 | permissions: |
| 221 | contents: read |
| 222 | pull-requests: read |
| 223 | if: github.event.pull_request.head.repo.full_name == 'caddyserver/caddy' && github.actor != 'dependabot[bot]' |
| 224 | steps: |
| 225 | - name: Harden the runner (Audit all outbound calls) |
| 226 | uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 |
| 227 | with: |
| 228 | egress-policy: audit |
| 229 | |
| 230 | - name: Checkout code |
| 231 | uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 232 | |
| 233 | - uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 |
| 234 | with: |
| 235 | version: latest |
| 236 | args: check |
| 237 | - name: Install Go |
| 238 | uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 239 | with: |
| 240 | go-version: "~1.27" |
| 241 | check-latest: true |
| 242 | - name: Install xcaddy |
| 243 | run: | |
| 244 | go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest |
| 245 | xcaddy version |
| 246 | - uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 |
| 247 | with: |
| 248 | version: latest |
| 249 | args: build --single-target --snapshot |
| 250 | env: |
| 251 | TAG: ${{ github.event.pull_request.head.sha || github.sha }} |