|
| 1 | +name: Provision Zulip Dev Server |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + zulip_ref: |
| 7 | + description: "Git ref (branch/tag/commit) for zulip/zulip" |
| 8 | + required: false |
| 9 | + default: "main" |
| 10 | + type: string |
| 11 | + zulip_repo: |
| 12 | + description: "Repository to checkout Zulip from" |
| 13 | + required: false |
| 14 | + default: "zulip/zulip" |
| 15 | + type: string |
| 16 | + wait_timeout_seconds: |
| 17 | + description: "How long to wait for Zulip to become ready" |
| 18 | + required: false |
| 19 | + default: "600" |
| 20 | + type: string |
| 21 | + # Cache ‘epoch’ knobs—bump these to bust cache when needed: |
| 22 | + cache_epoch_pnpm: |
| 23 | + description: "Epoch for pnpm store cache" |
| 24 | + required: false |
| 25 | + default: "v1" |
| 26 | + type: string |
| 27 | + cache_epoch_uv: |
| 28 | + description: "Epoch for uv cache" |
| 29 | + required: false |
| 30 | + default: "v1" |
| 31 | + type: string |
| 32 | + cache_epoch_emoji: |
| 33 | + description: "Epoch for emoji cache" |
| 34 | + required: false |
| 35 | + default: "v1" |
| 36 | + type: string |
| 37 | + |
| 38 | + outputs: |
| 39 | + site_url: |
| 40 | + description: "URL to the running Zulip server" |
| 41 | + value: ${{ jobs.provision.outputs.site_url }} |
| 42 | + log_path: |
| 43 | + description: "Path of the Zulip log file on runner" |
| 44 | + value: ${{ jobs.provision.outputs.log_path }} |
| 45 | + |
| 46 | +permissions: |
| 47 | + contents: read |
| 48 | + |
| 49 | +jobs: |
| 50 | + provision: |
| 51 | + name: Provision Zulip (${{ inputs.mode }}) @ ${{ inputs.zulip_ref }} |
| 52 | + runs-on: ubuntu-latest |
| 53 | + timeout-minutes: 90 |
| 54 | + |
| 55 | + env: |
| 56 | + ZULIP_PORT: 9991 |
| 57 | + ZULIP_URL: http://localhost:9991 |
| 58 | + ZULIP_DEV_LOG: ${{ runner.temp }}/zulip-dev.log |
| 59 | + ZULIP_RUN_PID: ${{ runner.temp }}/zulip-dev.pid |
| 60 | + # Matches Zulip CI cache locations: |
| 61 | + PNPM_STORE_PATH: /__w/.pnpm-store |
| 62 | + UV_CACHE_DIR: ~/.cache/uv |
| 63 | + EMOJI_CACHE_DIR: /srv/zulip-emoji-cache |
| 64 | + |
| 65 | + outputs: |
| 66 | + site_url: ${{ steps.outputs-step.outputs.site_url }} |
| 67 | + log_path: ${{ steps.outputs-step.outputs.log_path }} |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout Zulip (ref ${{ inputs.zulip_ref }}) |
| 71 | + uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + repository: ${{ inputs.zulip_repo }} |
| 74 | + ref: ${{ inputs.zulip_ref }} |
| 75 | + path: zulip |
| 76 | + |
| 77 | + - name: Create cache directories |
| 78 | + run: | |
| 79 | + sudo mkdir -p "${EMOJI_CACHE_DIR}" |
| 80 | + sudo chown -R $USER "${EMOJI_CACHE_DIR}" |
| 81 | + mkdir -p "${PNPM_STORE_PATH}" |
| 82 | +
|
| 83 | + - name: Restore pnpm store cache |
| 84 | + uses: actions/cache@v4 |
| 85 | + with: |
| 86 | + path: ${{ env.PNPM_STORE_PATH }} |
| 87 | + key: ${{ inputs.cache_epoch_pnpm }}-pnpm-${{ inputs.zulip_ref }}-${{ hashFiles('zulip/pnpm-lock.yaml') }} |
| 88 | + restore-keys: | |
| 89 | + ${{ inputs.cache_epoch_pnpm }}-pnpm-${{ inputs.zulip_ref }}- |
| 90 | + ${{ inputs.cache_epoch_pnpm }}-pnpm- |
| 91 | +
|
| 92 | + - name: Restore uv cache |
| 93 | + uses: actions/cache@v4 |
| 94 | + with: |
| 95 | + path: ${{ env.UV_CACHE_DIR }} |
| 96 | + key: ${{ inputs.cache_epoch_uv }}-uv-${{ inputs.zulip_ref }}-${{ hashFiles('zulip/uv.lock') }} |
| 97 | + restore-keys: | |
| 98 | + ${{ inputs.cache_epoch_uv }}-uv-${{ inputs.zulip_ref }}- |
| 99 | + ${{ inputs.cache_epoch_uv }}-uv- |
| 100 | +
|
| 101 | + - name: Restore emoji cache |
| 102 | + uses: actions/cache@v4 |
| 103 | + with: |
| 104 | + path: ${{ env.EMOJI_CACHE_DIR }} |
| 105 | + key: ${{ inputs.cache_epoch_emoji }}-emoji-${{ inputs.zulip_ref }}-${{ hashFiles('zulip/tools/setup/emoji/emoji_map.json', 'zulip/tools/setup/emoji/build_emoji', 'zulip/tools/setup/emoji/emoji_setup_utils.py', 'zulip/tools/setup/emoji/emoji_names.py', 'zulip/package.json') }} |
| 106 | + restore-keys: | |
| 107 | + ${{ inputs.cache_epoch_emoji }}-emoji-${{ inputs.zulip_ref }}- |
| 108 | + ${{ inputs.cache_epoch_emoji }}-emoji- |
| 109 | +
|
| 110 | + - name: Provision |
| 111 | + working-directory: zulip |
| 112 | + run: | |
| 113 | + set -euxo pipefail |
| 114 | + # Ensure pnpm store path the same as in Zulip CI |
| 115 | + export PNPM_HOME="${PNPM_STORE_PATH}" |
| 116 | + # Provision installs OS deps (via sudo), node, uv env, etc. |
| 117 | + ./tools/provision |
| 118 | +
|
| 119 | + - name: Start Zulip |
| 120 | + working-directory: zulip |
| 121 | + run: | |
| 122 | + set -euxo pipefail |
| 123 | + source ./tools/ci/activate-venv |
| 124 | + # Start in background and capture PID |
| 125 | + nohup ./tools/run-dev >"${ZULIP_DEV_LOG}" 2>&1 & |
| 126 | + echo $! > "${ZULIP_RUN_PID}" |
| 127 | +
|
| 128 | + - name: Wait for Zulip to be ready |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + set -euo pipefail |
| 132 | + echo "Waiting for Zulip at ${ZULIP_URL}" |
| 133 | + deadline=$(( $(date +%s) + ${{ inputs.wait_timeout_seconds }} )) |
| 134 | + until curl --get --silent --fail "${ZULIP_URL}/api/v1/server_settings" >/dev/null; do |
| 135 | + if [ "$(date +%s)" -gt "$deadline" ]; then |
| 136 | + echo "Zulip did not become ready within timeout." >&2 |
| 137 | + echo "=== Tail of log ===" >&2 |
| 138 | + tail -n 200 "${ZULIP_DEV_LOG}" || true |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + sleep 2 |
| 142 | + done |
| 143 | + echo "Zulip is up." |
| 144 | +
|
| 145 | + - name: Export outputs |
| 146 | + id: outputs-step |
| 147 | + run: | |
| 148 | + echo "site_url=${ZULIP_URL}" >> "$GITHUB_OUTPUT" |
| 149 | + echo "log_path=${ZULIP_DEV_LOG}" >> "$GITHUB_OUTPUT" |
| 150 | +
|
| 151 | + - name: Upload Zulip log |
| 152 | + if: always() |
| 153 | + uses: actions/upload-artifact@v4 |
| 154 | + with: |
| 155 | + name: zulip-log-${{ inputs.mode }}-${{ inputs.zulip_ref }} |
| 156 | + path: ${{ env.ZULIP_DEV_LOG }} |
| 157 | + if-no-files-found: ignore |
| 158 | + retention-days: 7 |
| 159 | + |
| 160 | + - name: Show log on failure |
| 161 | + if: failure() |
| 162 | + run: | |
| 163 | + echo "===== zulip-dev.log =====" |
| 164 | + tail -n +1 "${ZULIP_DEV_LOG}" || true |
| 165 | +
|
| 166 | + - name: Stop Zulip |
| 167 | + if: always() |
| 168 | + run: | |
| 169 | + if [ -f "${ZULIP_RUN_PID}" ]; then |
| 170 | + kill "$(cat "${ZULIP_RUN_PID}")" || true |
| 171 | + fi |
| 172 | + pkill -f "tools/run-dev" || true |
0 commit comments