@@ -64,23 +64,53 @@ jobs:
6464 if : github.event_name == 'pull_request'
6565 permissions :
6666 statuses : write
67- timeout-minutes : 1
67+ timeout-minutes : 2
68+ # Identifiers of the Coolify instance this repo previews on. Not secrets; the API token is.
69+ env :
70+ COOLIFY_URL : ${{ vars.COOLIFY_URL || 'https://coolify.hephaestus.aet.cit.tum.de' }}
71+ COOLIFY_PROJECT_UUID : ${{ vars.COOLIFY_PROJECT_UUID || 'lc8sows0ok8g880sg4o4o84w' }}
72+ COOLIFY_ENVIRONMENT_UUID : ${{ vars.COOLIFY_ENVIRONMENT_UUID || 'ek8o8800g4wks84c8w8wcckc' }}
73+ COOLIFY_APP_UUID : ${{ vars.COOLIFY_APP_UUID || 'wg44k0ccsoscsgcco8swc4ks' }}
6874 steps :
6975 - name : Post Coolify preview link
7076 uses : actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
7177 with :
7278 script : |
73- const sha = context.payload.pull_request.head.sha ;
79+ const { COOLIFY_URL, COOLIFY_PROJECT_UUID, COOLIFY_ENVIRONMENT_UUID, COOLIFY_APP_UUID } = process.env ;
7480 await github.rest.repos.createCommitStatus({
7581 owner: context.repo.owner,
7682 repo: context.repo.repo,
77- sha: sha,
83+ sha: context.payload.pull_request.head. sha,
7884 state: 'success',
79- target_url: 'https://coolify.hephaestus.aet.cit.tum.de/ project/lc8sows0ok8g880sg4o4o84w /environment/ek8o8800g4wks84c8w8wcckc /application/wg44k0ccsoscsgcco8swc4ks /preview-deployments' ,
85+ target_url: `${COOLIFY_URL}/ project/${COOLIFY_PROJECT_UUID} /environment/${COOLIFY_ENVIRONMENT_UUID} /application/${COOLIFY_APP_UUID} /preview-deployments` ,
8086 description: 'Click Details to view Coolify preview deployments',
8187 context: 'Preview / Coolify'
8288 });
8389
90+ # Coolify's preview switch is all-or-nothing: enabled, it deploys every open PR. It stays
91+ # disabled, and previews are created per PR from the Coolify UI. This keeps the ones that
92+ # exist current: the deploy API only accepts a PR that already has a preview and answers
93+ # "not found" for any other, so a PR without one is a no-op. Forks carry no secrets and are
94+ # skipped — a preview runs with production credentials.
95+ - name : Update an existing preview deployment
96+ if : github.event.action == 'synchronize' && github.event.pull_request.head.repo.full_name == github.repository
97+ env :
98+ COOLIFY_TOKEN : ${{ secrets.COOLIFY_API_TOKEN }}
99+ PR_NUMBER : ${{ github.event.pull_request.number }}
100+ run : |
101+ set -euo pipefail
102+ if [ -z "${COOLIFY_TOKEN}" ]; then
103+ echo "COOLIFY_API_TOKEN is not configured; skipping."
104+ exit 0
105+ fi
106+ response=$(curl -sS -X POST \
107+ -H "Authorization: Bearer ${COOLIFY_TOKEN}" \
108+ "${COOLIFY_URL}/api/v1/deploy?uuid=${COOLIFY_APP_UUID}&pr=${PR_NUMBER}")
109+ echo "${response}"
110+ if echo "${response}" | grep -q "not found"; then
111+ echo "PR #${PR_NUMBER} has no preview deployment; nothing to update."
112+ fi
113+
84114 Quality :
85115 uses : ./.github/workflows/ci-quality-gates.yml
86116 needs : [detect-changes]
0 commit comments