|
| 1 | +--- |
| 2 | +# yamllint disable rule:line-length |
| 3 | +name: test template |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - .github/compose/** |
| 9 | + - .github/workflows/test-template.yaml |
| 10 | + - templates/kubernetes/homelab-workspace/** |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +env: |
| 20 | + CODER_URL: http://localhost:7080 |
| 21 | + KIND_CLUSTER: coder-template-test |
| 22 | + TEMPLATE_NAME: homelab-workspace-test |
| 23 | + WORKSPACE_NAME: template-test |
| 24 | + |
| 25 | +jobs: |
| 26 | + integration: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 30 |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 32 | + with: |
| 33 | + fetch-depth: 1 |
| 34 | + persist-credentials: false |
| 35 | + |
| 36 | + - name: Create Kubernetes test cluster |
| 37 | + run: kind create cluster --name "${KIND_CLUSTER}" |
| 38 | + |
| 39 | + - name: Start local Coder |
| 40 | + env: |
| 41 | + COMPOSE_FILE: .github/compose/coder-template-test.yaml |
| 42 | + CODER_KUBECONFIG: ${{ runner.temp }}/kubeconfig-coder |
| 43 | + RUNNER_KUBECONFIG: ${{ runner.temp }}/kubeconfig-runner |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + kind export kubeconfig --name "${KIND_CLUSTER}" --kubeconfig "${RUNNER_KUBECONFIG}" |
| 47 | + cp "${RUNNER_KUBECONFIG}" "${CODER_KUBECONFIG}" |
| 48 | + sed -Ei "s#https://127\\.0\\.0\\.1:[0-9]+#https://${KIND_CLUSTER}-control-plane:6443#" "${CODER_KUBECONFIG}" |
| 49 | + export CODER_KUBECONFIG |
| 50 | + docker compose -f "${COMPOSE_FILE}" up --detach |
| 51 | +
|
| 52 | + - name: Wait for local Coder |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + timeout 5m bash -c "until curl --fail --silent --show-error \"${CODER_URL}/api/v2/buildinfo\" > /dev/null; do sleep 2; done" |
| 56 | +
|
| 57 | + - name: Create local Coder user |
| 58 | + env: |
| 59 | + CODER_KUBECONFIG: ${{ runner.temp }}/kubeconfig-coder |
| 60 | + run: | |
| 61 | + docker compose -f .github/compose/coder-template-test.yaml exec --tty=false coder \ |
| 62 | + coder server create-admin-user --username ci --email ci@example.invalid --password ci-password |
| 63 | +
|
| 64 | + - name: Install and log in to Coder CLI |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + source .github/compose/.env |
| 68 | + curl --fail --silent --show-error https://coder.com/install.sh | sh -s -- --method standalone --version "${CODER_VERSION#v}" |
| 69 | + export CODER_SESSION_TOKEN |
| 70 | + CODER_SESSION_TOKEN="$(curl --fail --silent --show-error -X POST "${CODER_URL}/api/v2/users/login" \ |
| 71 | + -H 'Content-Type: application/json' \ |
| 72 | + --data '{"email":"ci@example.invalid","password":"ci-password"}' | jq --raw-output .session_token)" |
| 73 | + test -n "${CODER_SESSION_TOKEN}" && test "${CODER_SESSION_TOKEN}" != null |
| 74 | + coder login --use-token-as-session "${CODER_URL}" |
| 75 | +
|
| 76 | + - name: Publish template |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + RELEASE_TAG="$(gh release view --repo "${{ github.repository }}" --json tagName --jq .tagName)" |
| 80 | + WORKSPACE_IMAGE="ghcr.io/ppat/coder-workspace:${RELEASE_TAG}" |
| 81 | + coder template push --directory templates/kubernetes/homelab-workspace \ |
| 82 | + --var "workspace_image=${WORKSPACE_IMAGE}" --var test_mode=true \ |
| 83 | + --name "${{ github.sha }}" --yes "${TEMPLATE_NAME}" |
| 84 | +
|
| 85 | + - name: Start workspace |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + coder create "${WORKSPACE_NAME}" --template "${TEMPLATE_NAME}" --yes |
| 89 | +
|
| 90 | + - name: Ping workspace agent |
| 91 | + shell: bash |
| 92 | + run: coder ping --num 3 --timeout 30s "${WORKSPACE_NAME}" |
| 93 | + |
| 94 | + - name: Run command over workspace SSH |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + coder ssh "${WORKSPACE_NAME}" -- env |
| 98 | +
|
| 99 | + - name: Show Coder logs on failure |
| 100 | + if: failure() |
| 101 | + env: |
| 102 | + CODER_KUBECONFIG: ${{ runner.temp }}/kubeconfig-coder |
| 103 | + run: docker compose -f .github/compose/coder-template-test.yaml logs |
0 commit comments