ci: split release publishing from PR validation #515
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| # yamllint disable rule:line-length | |
| name: test template | |
| on: | |
| pull_request: | |
| paths: | |
| - .github/compose/coder-template-test.yaml | |
| - .github/workflows/test-template.yaml | |
| - templates/kubernetes/homelab-workspace/** | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| env: | |
| CODER_VERSION: 2.35.6 | |
| CODER_URL: http://localhost:7080 | |
| KIND_CLUSTER: coder-template-test | |
| TEMPLATE_NAME: homelab-workspace-test | |
| WORKSPACE_NAME: template-test | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image: ${{ steps.changes.outputs.image }} | |
| template: ${{ steps.changes.outputs.template }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| persist-credentials: false | |
| - name: Classify changed layer | |
| id: changes | |
| shell: bash | |
| run: | | |
| git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}" | |
| if git diff --quiet "${{ github.event.pull_request.base.sha }}" HEAD -- images/homelab-workspace; then | |
| echo image=false >> "$GITHUB_OUTPUT" | |
| else | |
| echo image=true >> "$GITHUB_OUTPUT" | |
| fi | |
| if git diff --quiet "${{ github.event.pull_request.base.sha }}" HEAD -- templates/kubernetes/homelab-workspace; then | |
| echo template=false >> "$GITHUB_OUTPUT" | |
| else | |
| echo template=true >> "$GITHUB_OUTPUT" | |
| fi | |
| integration: | |
| needs: changes | |
| # Combined image/template changes deliberately have no integration path yet. | |
| if: needs.changes.outputs.template == 'true' && needs.changes.outputs.image != 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| persist-credentials: false | |
| - name: Create Kubernetes test cluster | |
| run: kind create cluster --name "${KIND_CLUSTER}" | |
| - name: Start local Coder | |
| env: | |
| COMPOSE_FILE: .github/compose/coder-template-test.yaml | |
| CODER_KUBECONFIG: ${{ runner.temp }}/coder-template-test/kubeconfig-coder | |
| RUNNER_KUBECONFIG: ${{ runner.temp }}/coder-template-test/kubeconfig-runner | |
| shell: bash | |
| run: | | |
| mkdir -p "$(dirname "${CODER_KUBECONFIG}")" | |
| kind export kubeconfig --name "${KIND_CLUSTER}" --kubeconfig "${RUNNER_KUBECONFIG}" | |
| cp "${RUNNER_KUBECONFIG}" "${CODER_KUBECONFIG}" | |
| sed -Ei "s#https://127\\.0\\.0\\.1:[0-9]+#https://${KIND_CLUSTER}-control-plane:6443#" "${CODER_KUBECONFIG}" | |
| export CODER_KUBECONFIG | |
| docker compose -f "${COMPOSE_FILE}" up --detach database | |
| docker compose -f "${COMPOSE_FILE}" run --rm coder server create-admin-user \ | |
| --username ci --email ci@example.invalid --password ci-password | |
| docker compose -f "${COMPOSE_FILE}" up --detach coder | |
| - name: Wait for Coder and verify workspace routing | |
| shell: bash | |
| run: | | |
| # With no access URL, Coder creates its public development tunnel. The | |
| # Kind workspace reaches that URL while this runner keeps using localhost. | |
| timeout 5m bash -c "until curl --fail --silent --show-error \"${CODER_URL}/api/v2/buildinfo\" > /dev/null; do sleep 2; done" | |
| - name: Install and log in to Coder CLI | |
| shell: bash | |
| run: | | |
| curl --fail --silent --show-error https://coder.com/install.sh | sh -s -- --method standalone --version "${CODER_VERSION}" | |
| export CODER_SESSION_TOKEN | |
| CODER_SESSION_TOKEN="$(curl --fail --silent --show-error -X POST "${CODER_URL}/api/v2/users/login" \ | |
| -H 'Content-Type: application/json' \ | |
| --data '{"email":"ci@example.invalid","password":"ci-password"}' | jq --raw-output .session_token)" | |
| test -n "${CODER_SESSION_TOKEN}" && test "${CODER_SESSION_TOKEN}" != null | |
| coder login --use-token-as-session "${CODER_URL}" | |
| - name: Publish template and start workspace | |
| shell: bash | |
| run: | | |
| RELEASE_TAG="$(gh release view --repo "${{ github.repository }}" --json tagName --jq .tagName)" | |
| WORKSPACE_IMAGE="ghcr.io/ppat/coder-workspace:${RELEASE_TAG}" | |
| coder template push --directory templates/kubernetes/homelab-workspace \ | |
| --var "workspace_image=${WORKSPACE_IMAGE}" --var test_mode=true \ | |
| --name "${{ github.sha }}" --yes "${TEMPLATE_NAME}" | |
| coder create "${WORKSPACE_NAME}" --template "${TEMPLATE_NAME}" --yes | |
| coder ping "${WORKSPACE_NAME}" | |
| coder ssh "${WORKSPACE_NAME}" -- env | |
| - name: Show Coder logs on failure | |
| if: failure() | |
| env: | |
| CODER_KUBECONFIG: ${{ runner.temp }}/coder-template-test/kubeconfig-coder | |
| run: docker compose -f .github/compose/coder-template-test.yaml logs | |
| - name: Stop local Coder | |
| if: always() | |
| env: | |
| CODER_KUBECONFIG: ${{ runner.temp }}/coder-template-test/kubeconfig-coder | |
| run: docker compose -f .github/compose/coder-template-test.yaml down --volumes |