Skip to content

fix(runner): clean claude runner checkouts after every session #466

fix(runner): clean claude runner checkouts after every session

fix(runner): clean claude runner checkouts after every session #466

name: Drupal Integration Tests
# Creates drupal-core workspaces on staging-coder.ddev.com and verifies they
# reach a working state (Drush DB connection, web root present, site accessible).
#
# Two jobs:
# drupal-plain — matrix of D11 and D12, no issue fork, runs on every
# push to main and nightly
# drupal-issue-fork — single workspace using a real drupal.org issue fork,
# runs on every push to main, PRs, and nightly
#
# Repository variable:
# DRUPAL_TEST_ISSUE_FORK - drupal.org issue number (bare, e.g. 3585397) or
# prefixed form (drupal-3585397). The Drupal version
# and branch are resolved automatically via the
# drupal.org and GitLab APIs — only the issue number
# is needed. Default: 3585397.
#
# To change the test issue: pick one that is "Needs
# review", targets main (12.x), and has an issue fork
# on git.drupalcode.org. Set this variable in
# GitHub → Settings → Secrets and variables → Actions
# → Variables. See docs/admin/server-setup.md for
# the full CI setup procedure.
#
# Requires:
# Repository variable: TEST_CODER_URL - https://staging-coder.ddev.com
# Repository secret: OP_SERVICE_ACCOUNT_TOKEN - 1Password service account with read access
# 1Password item: op://test-secrets/TEST_CODER_SESSION_TOKEN/credential
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
# Ref-scoped so a new commit on the same PR (or the same push-to-main queue)
# cancels its own stale run, but never touches another PR's or main's run.
#
# Serialization against other workflows/refs that provision real workspaces on
# the shared staging-coder.ddev.com box is NOT done via a shared job-level
# `concurrency:` group -- a single PR push fires several box-provisioning jobs
# across this file, integration-test.yml, and
# drupal-contrib-integration-test.yml at nearly the same instant, and GitHub's
# concurrency groups only keep one job running plus one pending; every other
# simultaneous contender gets silently CANCELLED, not queued. Instead, each
# box-touching job below (including drupal-plain-gh and drupal-issue-fork-gh,
# which otherwise run in parallel within a single workflow run) calls
# scripts/ci-acquire-staging-lock.sh right before creating its workspace,
# which claims one of a fixed number of lock-slot workspaces (an atomic
# Coder-side compare-and-swap on workspace name) and waits its turn if all
# slots are held -- see that script's header comment for detail.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: '0 4 * * *'
push:
branches: [main]
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
description: Enable remote debugging session
type: boolean
required: false
default: false
jobs:
drupal-plain:
name: Drupal ${{ matrix.drupal_version }} (plain)
# Disabled: self-hosted sysbox runner; use drupal-plain-gh instead.
# To re-enable: restore `if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }}`
if: false
runs-on: [self-hosted, sysbox]
# Long enough to cover queued time behind other box-provisioning jobs
# (see scripts/ci-acquire-staging-lock.sh) plus this job's own runtime.
timeout-minutes: 75
strategy:
matrix:
drupal_version: ["12", "11"]
fail-fast: false
defaults:
run:
shell: bash -euo pipefail {0}
env:
WORKSPACE_NAME: cd-${{ matrix.drupal_version }}-${{ github.run_number }}-${{ github.run_attempt }}
CI: "true"
DDEV_NONINTERACTIVE: "true"
NO_COLOR: "1"
steps:
- uses: actions/checkout@v6
- name: Load 1Password secrets
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
TEST_CODER_SESSION_TOKEN: "op://test-secrets/TEST_CODER_SESSION_TOKEN/credential"
- name: Login to Coder
if: ${{ env.TEST_CODER_SESSION_TOKEN != '' }}
run: coder login --token "${{ env.TEST_CODER_SESSION_TOKEN }}" "${{ vars.TEST_CODER_URL }}"
- name: Setup upterm session
uses: owenthereal/action-upterm@v1
with:
limit-access-to-actor: true
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Push template (inactive)
run: |
coder templates push drupal-core \
--directory drupal-core \
--activate=false \
--name ${{ env.WORKSPACE_NAME }} \
--yes \
--variable image_version="$(cat VERSION)" \
--variable workspace_image_registry=index.docker.io/ddev/coder-ddev \
--variable cache_path=/home/rfay/cache/drupal-core-seed \
--variable github_token=${{ secrets.GITHUB_TOKEN }}
- name: Create workspace
run: |
coder create ${{ env.WORKSPACE_NAME }} \
--template drupal-core \
--template-version ${{ env.WORKSPACE_NAME }} \
--parameter "vscode_extensions=[]" \
--parameter drupal_version=${{ matrix.drupal_version }} \
--parameter issue_fork= \
--parameter issue_branch= \
--parameter install_profile=minimal \
--parameter drupal_site_public=false \
--use-parameter-defaults \
--yes
- name: Show provisioner errors if workspace creation failed
if: failure()
run: ./scripts/ci-show-provisioner-errors.sh "${{ env.WORKSPACE_NAME }}" "${{ env.WORKSPACE_NAME }}"
- &verify-agent
name: Verify workspace — agent connected
run: coder ssh ${{ env.WORKSPACE_NAME }} --wait=yes -- echo "Agent connected"
- &verify-docker
name: Verify workspace — Docker daemon running
run: coder ssh ${{ env.WORKSPACE_NAME }} -- docker ps
- &verify-ddev
name: Verify workspace — DDEV installed
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev --version
- &verify-webroot
name: Verify workspace — web root exists
run: coder ssh ${{ env.WORKSPACE_NAME }} -- test -f /home/coder/drupal-core/index.php
- &verify-drush
name: Verify workspace — Drush DB connected
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev drush status --fields=db-status | grep -i connected
- &verify-phpunit
# Regression check for #211: amateescu/ddev-drupal-dev's own
# SIMPLETEST_BASE_URL=${DDEV_PRIMARY_URL} is empty because this
# template always omits ddev-router, which broke every phpunit
# functional test. See the SIMPLETEST_BASE_URL override written in
# template.tf's Step 4.
name: Verify workspace — PHPUnit functional test runs (#211)
run: |
coder ssh ${{ env.WORKSPACE_NAME }} -- \
ddev phpunit --filter testTitle core/modules/system/tests/src/Functional/System/PageTitleTest.php
- &record-host-dir
name: Record expected host directory
run: |
OWNER=$(coder whoami --output json | jq -r 'if type == "array" then .[0].username else .username end')
echo "OWNER=$OWNER" >> "$GITHUB_ENV"
echo "HOST_DIR=/coder-workspaces/${OWNER}-${{ env.WORKSPACE_NAME }}" >> "$GITHUB_ENV"
- &verify-http
name: Verify workspace — Drupal site externally accessible
run: |
CODER_DOMAIN="${{ vars.TEST_CODER_URL }}"
CODER_DOMAIN="${CODER_DOMAIN#https://}"
SITE_URL="https://drupal-site--${{ env.WORKSPACE_NAME }}--${OWNER}.${CODER_DOMAIN}"
echo "Checking $SITE_URL"
# drupal-site app has share="owner" so requests must carry a Coder session token
HTTP_STATUS=$(curl -sL --max-time 30 --retry 3 --retry-delay 5 \
-H "Coder-Session-Token: ${TEST_CODER_SESSION_TOKEN}" \
-o /tmp/drupal-response.html \
-w "%{http_code}" \
"$SITE_URL")
echo "HTTP status: $HTTP_STATUS"
if [[ ! "$HTTP_STATUS" =~ ^[23] ]]; then
echo "ERROR: unexpected HTTP status $HTTP_STATUS" >&2
head -50 /tmp/drupal-response.html >&2 || true
exit 1
fi
if ! grep -qi "log in" /tmp/drupal-response.html; then
echo "ERROR: response does not contain 'log in' — Drupal may not have started" >&2
head -50 /tmp/drupal-response.html >&2
exit 1
fi
echo "OK: Drupal site is accessible and shows login page"
# drupal_site_public defaults to false: an anonymous request (no
# session token) must be bounced to Coder's own login, never reach
# Drupal. This is the private-by-default half of issue #204's fix.
ANON_FINAL_URL=$(curl -sL --max-time 30 -o /dev/null -w "%{url_effective}" "$SITE_URL")
echo "Anonymous request final URL: $ANON_FINAL_URL"
if [[ "$ANON_FINAL_URL" != *"/login"* ]]; then
echo "ERROR: anonymous request was not redirected to Coder login — drupal_site_public=false is not private" >&2
exit 1
fi
echo "OK: anonymous request redirected to Coder login (site is private by default)"
- &delete-workspace
name: Delete workspace
if: always()
run: coder delete ${{ env.WORKSPACE_NAME }} --yes || true
- &verify-host-dir-removed
name: Verify host directory removed
if: always()
run: |
if [[ -z "${HOST_DIR:-}" ]]; then
echo "HOST_DIR not set — workspace may not have been created, skipping"
exit 0
fi
if [[ -d "$HOST_DIR" ]]; then
echo "ERROR: Host directory was not removed by destroy provisioner: $HOST_DIR" >&2
ls -la "$HOST_DIR" >&2 || true
exit 1
fi
echo "OK: host directory removed: $HOST_DIR"
- &archive-template-version
name: Archive CI template version
if: always()
run: coder templates versions archive drupal-core ${{ env.WORKSPACE_NAME }} --yes || true
drupal-plain-gh:
name: Drupal ${{ matrix.drupal_version }} (plain, GH)
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }}
runs-on: ubuntu-latest
# Long enough to cover queued time behind other box-provisioning jobs
# (see scripts/ci-acquire-staging-lock.sh) plus this job's own runtime.
timeout-minutes: 75
strategy:
# PRs run a single Drupal version (smoke); push-to-main and nightly run the
# full matrix. Cuts per-PR workspace load on staging. See ci-reap.yml.
matrix:
drupal_version: ${{ github.event_name == 'pull_request' && fromJSON('["12"]') || fromJSON('["12", "11"]') }}
fail-fast: false
defaults:
run:
shell: bash -euo pipefail {0}
env:
WORKSPACE_NAME: gd-${{ matrix.drupal_version }}-${{ github.event.pull_request.number && format('pr{0}', github.event.pull_request.number) || github.ref_name == 'main' && 'main' || format('x{0}', github.run_number) }}-${{ github.run_number }}-${{ github.run_attempt }}
CI: "true"
DDEV_NONINTERACTIVE: "true"
NO_COLOR: "1"
steps:
- uses: actions/checkout@v6
- name: Load 1Password secrets
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
TEST_CODER_SESSION_TOKEN: "op://test-secrets/TEST_CODER_SESSION_TOKEN/credential"
- uses: coder/setup-action@v1
with:
access_url: ${{ vars.TEST_CODER_URL }}
coder_session_token: ${{ env.TEST_CODER_SESSION_TOKEN }}
- name: Push template (inactive)
run: |
coder templates push drupal-core \
--directory drupal-core \
--activate=false \
--name ${{ env.WORKSPACE_NAME }} \
--yes \
--variable image_version="$(cat VERSION)" \
--variable workspace_image_registry=index.docker.io/ddev/coder-ddev \
--variable cache_path=/home/rfay/cache/drupal-core-seed \
--variable github_token=${{ secrets.GITHUB_TOKEN }}
- name: Reap predecessor workspaces (cancelled prior runs of this cell)
run: ./scripts/ci-reap-family.sh "${WORKSPACE_NAME%-*-*}-" "$WORKSPACE_NAME"
- name: Acquire staging box lock
run: ./scripts/ci-acquire-staging-lock.sh
env:
CI_LOCK_SLOTS: ${{ vars.CI_LOCK_SLOTS }}
- name: Create workspace
run: |
coder create ${{ env.WORKSPACE_NAME }} \
--template drupal-core \
--template-version ${{ env.WORKSPACE_NAME }} \
--parameter "vscode_extensions=[]" \
--parameter drupal_version=${{ matrix.drupal_version }} \
--parameter issue_fork= \
--parameter issue_branch= \
--parameter install_profile=minimal \
--parameter drupal_site_public=false \
--use-parameter-defaults \
--yes
- name: Show provisioner errors if workspace creation failed
if: failure()
run: ./scripts/ci-show-provisioner-errors.sh "${{ env.WORKSPACE_NAME }}" "${{ env.WORKSPACE_NAME }}"
- *verify-agent
- *verify-docker
- *verify-ddev
- *verify-webroot
- *verify-drush
- *verify-phpunit
- *record-host-dir
- *verify-http
- name: Enable public sharing and rebuild
# `coder update`/`coder restart` alone silently ignore --parameter
# unless the workspace is otherwise outdated. --always-prompt forces
# every rich parameter to be re-resolved (never pulled from the
# existing build), so every value from the original `coder create`
# must be repeated here — anything left out falls back to the
# template default via --use-parameter-defaults, not its prior value.
run: |
coder restart ${{ env.WORKSPACE_NAME }} --always-prompt --use-parameter-defaults \
--parameter "vscode_extensions=[]" \
--parameter drupal_version=${{ matrix.drupal_version }} \
--parameter issue_fork= \
--parameter issue_branch= \
--parameter install_profile=minimal \
--parameter drupal_site_public=true \
--yes
- name: Verify workspace — agent reconnected after restart
run: coder ssh ${{ env.WORKSPACE_NAME }} --wait=yes -- echo "Agent reconnected"
- name: Verify workspace — Drupal site public when drupal_site_public=true
run: |
CODER_DOMAIN="${{ vars.TEST_CODER_URL }}"
CODER_DOMAIN="${CODER_DOMAIN#https://}"
SITE_URL="https://drupal-site--${{ env.WORKSPACE_NAME }}--${OWNER}.${CODER_DOMAIN}"
echo "Checking $SITE_URL anonymously"
HTTP_STATUS=$(curl -sL --max-time 30 --retry 3 --retry-delay 5 \
-o /tmp/drupal-public-response.html \
-w "%{http_code}" \
"$SITE_URL")
echo "HTTP status: $HTTP_STATUS"
if [[ ! "$HTTP_STATUS" =~ ^2 ]]; then
echo "ERROR: unexpected HTTP status $HTTP_STATUS for a public anonymous request" >&2
head -50 /tmp/drupal-public-response.html >&2 || true
exit 1
fi
if ! grep -qi "drupal" /tmp/drupal-public-response.html; then
echo "ERROR: anonymous response does not look like the Drupal site — drupal_site_public=true did not make it public" >&2
head -50 /tmp/drupal-public-response.html >&2
exit 1
fi
echo "OK: anonymous request reached the public Drupal site (drupal_site_public=true works)"
- *delete-workspace
- name: Release staging box lock
if: always()
run: ./scripts/ci-release-staging-lock.sh
- name: Archive CI template version
if: always()
run: coder templates versions archive drupal-core ${{ env.WORKSPACE_NAME }} --yes || true
drupal-issue-fork:
name: Drupal issue fork ${{ vars.DRUPAL_TEST_ISSUE_FORK || '3585397' }}
# Disabled: self-hosted sysbox runner; use drupal-issue-fork-gh instead.
# To re-enable: restore `if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }}`
if: false
runs-on: [self-hosted, sysbox]
# Long enough to cover queued time behind other box-provisioning jobs
# (see scripts/ci-acquire-staging-lock.sh) plus this job's own runtime.
timeout-minutes: 75
defaults:
run:
shell: bash -euo pipefail {0}
env:
WORKSPACE_NAME: cd-fork-${{ github.run_number }}-${{ github.run_attempt }}
CI: "true"
DDEV_NONINTERACTIVE: "true"
NO_COLOR: "1"
ISSUE_FORK: ${{ vars.DRUPAL_TEST_ISSUE_FORK || '3585397' }}
steps:
- uses: actions/checkout@v6
- name: Load 1Password secrets
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
TEST_CODER_SESSION_TOKEN: "op://test-secrets/TEST_CODER_SESSION_TOKEN/credential"
- name: Login to Coder
if: ${{ env.TEST_CODER_SESSION_TOKEN != '' }}
run: coder login --token "${{ env.TEST_CODER_SESSION_TOKEN }}" "${{ vars.TEST_CODER_URL }}"
- name: Setup upterm session
uses: owenthereal/action-upterm@v1
with:
limit-access-to-actor: true
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Resolve issue branch and Drupal version from issue number
run: |
# Strip optional "drupal-" prefix so bare numbers and prefixed values both work
ISSUE_NUM="${ISSUE_FORK#drupal-}"
# Derive the default branch of the issue fork from the GitLab API
ISSUE_BRANCH=$(curl -sf \
"https://git.drupalcode.org/api/v4/projects/issue%2Fdrupal-${ISSUE_NUM}" \
| jq -r '.default_branch')
if [[ -z "$ISSUE_BRANCH" || "$ISSUE_BRANCH" == "null" ]]; then
echo "ERROR: Could not resolve default branch for issue fork $ISSUE_NUM" >&2
exit 1
fi
# Derive the target Drupal major version from the issue's drupal.org field_issue_version
RAW_VERSION=$(curl -sf \
"https://www.drupal.org/api-d7/node/${ISSUE_NUM}.json" \
| jq -r '.field_issue_version // ""')
# field_issue_version looks like "11.x-dev" or "12.x-dev" or "10.2.x-dev"
DRUPAL_VERSION=$(echo "$RAW_VERSION" | grep -oE '^[0-9]+' || echo "12")
echo "Resolved: branch=$ISSUE_BRANCH drupal_version=$DRUPAL_VERSION"
echo "ISSUE_BRANCH=$ISSUE_BRANCH" >> "$GITHUB_ENV"
echo "ISSUE_FORK_VERSION=$DRUPAL_VERSION" >> "$GITHUB_ENV"
- name: Push template (inactive)
run: |
coder templates push drupal-core \
--directory drupal-core \
--activate=false \
--name cd-${{ github.run_number }}-${{ github.run_attempt }} \
--yes \
--variable image_version="$(cat VERSION)" \
--variable workspace_image_registry=index.docker.io/ddev/coder-ddev \
--variable cache_path=/home/rfay/cache/drupal-core-seed \
--variable github_token=${{ secrets.GITHUB_TOKEN }}
- name: Create workspace
run: |
coder create ${{ env.WORKSPACE_NAME }} \
--template drupal-core \
--template-version cd-${{ github.run_number }}-${{ github.run_attempt }} \
--parameter "vscode_extensions=[]" \
--parameter drupal_version=${{ env.ISSUE_FORK_VERSION }} \
--parameter issue_fork=${{ env.ISSUE_FORK }} \
--parameter issue_branch=${{ env.ISSUE_BRANCH }} \
--parameter install_profile=minimal \
--parameter drupal_site_public=false \
--use-parameter-defaults \
--yes
- name: Show provisioner errors if workspace creation failed
if: failure()
run: ./scripts/ci-show-provisioner-errors.sh "cd-${{ github.run_number }}-${{ github.run_attempt }}" "${{ env.WORKSPACE_NAME }}"
- name: Verify workspace — agent connected
run: coder ssh ${{ env.WORKSPACE_NAME }} --wait=yes -- echo "Agent connected"
- name: Verify workspace — Docker daemon running
run: coder ssh ${{ env.WORKSPACE_NAME }} -- docker ps
- name: Verify workspace — DDEV installed
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev --version
- name: Verify workspace — web root exists
run: coder ssh ${{ env.WORKSPACE_NAME }} -- test -f /home/coder/drupal-core/index.php
- name: Verify workspace — issue branch checked out
run: |
CURRENT=$(coder ssh ${{ env.WORKSPACE_NAME }} -- git -C /home/coder/drupal-core branch --show-current | tr -d '\r\n')
echo "Current branch: $CURRENT Expected: ${{ env.ISSUE_BRANCH }}"
[[ "$CURRENT" == "${{ env.ISSUE_BRANCH }}" ]] || { echo "ERROR: wrong branch" >&2; exit 1; }
- name: Verify workspace — Drush DB connected
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev drush status --fields=db-status | grep -i connected
- name: Record expected host directory
run: |
OWNER=$(coder whoami --output json | jq -r 'if type == "array" then .[0].username else .username end')
echo "OWNER=$OWNER" >> "$GITHUB_ENV"
echo "HOST_DIR=/coder-workspaces/${OWNER}-${{ env.WORKSPACE_NAME }}" >> "$GITHUB_ENV"
- name: Verify workspace — Drupal site externally accessible
run: |
CODER_DOMAIN="${{ vars.TEST_CODER_URL }}"
CODER_DOMAIN="${CODER_DOMAIN#https://}"
SITE_URL="https://drupal-site--${{ env.WORKSPACE_NAME }}--${OWNER}.${CODER_DOMAIN}"
echo "Checking $SITE_URL"
# drupal-site app has share="owner" so requests must carry a Coder session token
HTTP_STATUS=$(curl -sL --max-time 30 --retry 3 --retry-delay 5 \
-H "Coder-Session-Token: ${TEST_CODER_SESSION_TOKEN}" \
-o /tmp/drupal-response.html \
-w "%{http_code}" \
"$SITE_URL")
echo "HTTP status: $HTTP_STATUS"
if [[ ! "$HTTP_STATUS" =~ ^[23] ]]; then
echo "ERROR: unexpected HTTP status $HTTP_STATUS" >&2
head -50 /tmp/drupal-response.html >&2 || true
exit 1
fi
if ! grep -qi "log in" /tmp/drupal-response.html; then
echo "ERROR: response does not contain 'log in' — Drupal may not have started" >&2
head -50 /tmp/drupal-response.html >&2
exit 1
fi
echo "OK: Drupal site is accessible and shows login page"
# drupal_site_public defaults to false: an anonymous request (no
# session token) must be bounced to Coder's own login, never reach
# Drupal. This is the private-by-default half of issue #204's fix.
ANON_FINAL_URL=$(curl -sL --max-time 30 -o /dev/null -w "%{url_effective}" "$SITE_URL")
echo "Anonymous request final URL: $ANON_FINAL_URL"
if [[ "$ANON_FINAL_URL" != *"/login"* ]]; then
echo "ERROR: anonymous request was not redirected to Coder login — drupal_site_public=false is not private" >&2
exit 1
fi
echo "OK: anonymous request redirected to Coder login (site is private by default)"
- name: Delete workspace
if: always()
run: coder delete ${{ env.WORKSPACE_NAME }} --yes || true
- name: Verify host directory removed
if: always()
run: |
if [[ -z "${HOST_DIR:-}" ]]; then
echo "HOST_DIR not set — workspace may not have been created, skipping"
exit 0
fi
if [[ -d "$HOST_DIR" ]]; then
echo "ERROR: Host directory was not removed by destroy provisioner: $HOST_DIR" >&2
ls -la "$HOST_DIR" >&2 || true
exit 1
fi
echo "OK: host directory removed: $HOST_DIR"
- name: Archive CI template version
if: always()
run: coder templates versions archive drupal-core cd-${{ github.run_number }}-${{ github.run_attempt }} --yes || true
drupal-issue-fork-gh:
name: Drupal issue fork ${{ vars.DRUPAL_TEST_ISSUE_FORK || '3585397' }} (GH)
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }}
runs-on: ubuntu-latest
# Long enough to cover queued time behind other box-provisioning jobs
# (see scripts/ci-acquire-staging-lock.sh) plus this job's own runtime.
timeout-minutes: 75
defaults:
run:
shell: bash -euo pipefail {0}
env:
WORKSPACE_NAME: gd-fork-${{ github.event.pull_request.number && format('pr{0}', github.event.pull_request.number) || github.ref_name == 'main' && 'main' || format('x{0}', github.run_number) }}-${{ github.run_number }}-${{ github.run_attempt }}
CI: "true"
DDEV_NONINTERACTIVE: "true"
NO_COLOR: "1"
ISSUE_FORK: ${{ vars.DRUPAL_TEST_ISSUE_FORK || '3585397' }}
steps:
- uses: actions/checkout@v6
- name: Load 1Password secrets
uses: 1password/load-secrets-action@v4
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
TEST_CODER_SESSION_TOKEN: "op://test-secrets/TEST_CODER_SESSION_TOKEN/credential"
- uses: coder/setup-action@v1
with:
access_url: ${{ vars.TEST_CODER_URL }}
coder_session_token: ${{ env.TEST_CODER_SESSION_TOKEN }}
- name: Resolve issue branch and Drupal version from issue number
run: |
ISSUE_NUM="${ISSUE_FORK#drupal-}"
ISSUE_BRANCH=$(curl -sf \
"https://git.drupalcode.org/api/v4/projects/issue%2Fdrupal-${ISSUE_NUM}" \
| jq -r '.default_branch')
if [[ -z "$ISSUE_BRANCH" || "$ISSUE_BRANCH" == "null" ]]; then
echo "ERROR: Could not resolve default branch for issue fork $ISSUE_NUM" >&2
exit 1
fi
RAW_VERSION=$(curl -sf \
"https://www.drupal.org/api-d7/node/${ISSUE_NUM}.json" \
| jq -r '.field_issue_version // ""')
DRUPAL_VERSION=$(echo "$RAW_VERSION" | grep -oE '^[0-9]+' || echo "12")
echo "Resolved: branch=$ISSUE_BRANCH drupal_version=$DRUPAL_VERSION"
echo "ISSUE_BRANCH=$ISSUE_BRANCH" >> "$GITHUB_ENV"
echo "ISSUE_FORK_VERSION=$DRUPAL_VERSION" >> "$GITHUB_ENV"
- name: Push template (inactive)
run: |
coder templates push drupal-core \
--directory drupal-core \
--activate=false \
--name gd-${{ github.run_number }}-${{ github.run_attempt }} \
--yes \
--variable image_version="$(cat VERSION)" \
--variable workspace_image_registry=index.docker.io/ddev/coder-ddev \
--variable cache_path=/home/rfay/cache/drupal-core-seed \
--variable github_token=${{ secrets.GITHUB_TOKEN }}
- name: Reap predecessor workspaces (cancelled prior runs of this cell)
run: ./scripts/ci-reap-family.sh "${WORKSPACE_NAME%-*-*}-" "$WORKSPACE_NAME"
- name: Acquire staging box lock
run: ./scripts/ci-acquire-staging-lock.sh
env:
CI_LOCK_SLOTS: ${{ vars.CI_LOCK_SLOTS }}
- name: Create workspace
run: |
coder create ${{ env.WORKSPACE_NAME }} \
--template drupal-core \
--template-version gd-${{ github.run_number }}-${{ github.run_attempt }} \
--parameter "vscode_extensions=[]" \
--parameter drupal_version=${{ env.ISSUE_FORK_VERSION }} \
--parameter issue_fork=${{ env.ISSUE_FORK }} \
--parameter issue_branch=${{ env.ISSUE_BRANCH }} \
--parameter install_profile=minimal \
--parameter drupal_site_public=false \
--use-parameter-defaults \
--yes
- name: Show provisioner errors if workspace creation failed
if: failure()
run: ./scripts/ci-show-provisioner-errors.sh "gd-${{ github.run_number }}-${{ github.run_attempt }}" "${{ env.WORKSPACE_NAME }}"
- name: Verify workspace — agent connected
run: coder ssh ${{ env.WORKSPACE_NAME }} --wait=yes -- echo "Agent connected"
- name: Verify workspace — Docker daemon running
run: coder ssh ${{ env.WORKSPACE_NAME }} -- docker ps
- name: Verify workspace — DDEV installed
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev --version
- name: Verify workspace — web root exists
run: coder ssh ${{ env.WORKSPACE_NAME }} -- test -f /home/coder/drupal-core/index.php
- name: Verify workspace — issue branch checked out
run: |
CURRENT=$(coder ssh ${{ env.WORKSPACE_NAME }} -- git -C /home/coder/drupal-core branch --show-current | tr -d '\r\n')
echo "Current branch: $CURRENT Expected: ${{ env.ISSUE_BRANCH }}"
[[ "$CURRENT" == "${{ env.ISSUE_BRANCH }}" ]] || { echo "ERROR: wrong branch" >&2; exit 1; }
- name: Verify workspace — git tree is clean
run: |
DIRTY=$(coder ssh ${{ env.WORKSPACE_NAME }} -- git -C /home/coder/drupal-core status --short | tr -d '\r')
if [[ -n "$DIRTY" ]]; then
echo "ERROR: dirty git tree after issue branch checkout:" >&2
echo "$DIRTY" >&2
exit 1
fi
echo "OK: git tree is clean"
- name: Verify workspace — Drush DB connected
run: coder ssh ${{ env.WORKSPACE_NAME }} -- ddev drush status --fields=db-status | grep -i connected
- name: Record owner
run: |
OWNER=$(coder whoami --output json | jq -r 'if type == "array" then .[0].username else .username end')
echo "OWNER=$OWNER" >> "$GITHUB_ENV"
- name: Verify workspace — Drupal site externally accessible
run: |
CODER_DOMAIN="${{ vars.TEST_CODER_URL }}"
CODER_DOMAIN="${CODER_DOMAIN#https://}"
SITE_URL="https://drupal-site--${{ env.WORKSPACE_NAME }}--${OWNER}.${CODER_DOMAIN}"
echo "Checking $SITE_URL"
HTTP_STATUS=$(curl -sL --max-time 30 --retry 3 --retry-delay 5 \
-H "Coder-Session-Token: ${TEST_CODER_SESSION_TOKEN}" \
-o /tmp/drupal-response.html \
-w "%{http_code}" \
"$SITE_URL")
echo "HTTP status: $HTTP_STATUS"
if [[ ! "$HTTP_STATUS" =~ ^[23] ]]; then
echo "ERROR: unexpected HTTP status $HTTP_STATUS" >&2
head -50 /tmp/drupal-response.html >&2 || true
exit 1
fi
if ! grep -qi "log in" /tmp/drupal-response.html; then
echo "ERROR: response does not contain 'log in' — Drupal may not have started" >&2
head -50 /tmp/drupal-response.html >&2
exit 1
fi
echo "OK: Drupal site is accessible and shows login page"
# drupal_site_public defaults to false: an anonymous request (no
# session token) must be bounced to Coder's own login, never reach
# Drupal. This is the private-by-default half of issue #204's fix.
ANON_FINAL_URL=$(curl -sL --max-time 30 -o /dev/null -w "%{url_effective}" "$SITE_URL")
echo "Anonymous request final URL: $ANON_FINAL_URL"
if [[ "$ANON_FINAL_URL" != *"/login"* ]]; then
echo "ERROR: anonymous request was not redirected to Coder login — drupal_site_public=false is not private" >&2
exit 1
fi
echo "OK: anonymous request redirected to Coder login (site is private by default)"
- name: Delete workspace
if: always()
run: coder delete ${{ env.WORKSPACE_NAME }} --yes || true
- name: Release staging box lock
if: always()
run: ./scripts/ci-release-staging-lock.sh
- name: Archive CI template version
if: always()
run: coder templates versions archive drupal-core gd-${{ github.run_number }}-${{ github.run_attempt }} --yes || true