Skip to content

Commit af47739

Browse files
robbertbosanneschuth
authored andcommitted
feat(deploy): add wait-for-ready feature
Add optional health checking to wait for deployments to be reachable before continuing. New inputs: - wait-for-ready: enable waiting (default: false) - health-endpoint: path to check (default: /) - wait-timeout: max wait time in seconds (default: 300) - wait-interval: time between checks (default: 10) Also updates README: - Add wait-for-ready documentation and examples - Replace manual health check script with built-in feature - Use generic example URLs instead of specific domains - Format tables for better readability
1 parent 9246aa8 commit af47739

3 files changed

Lines changed: 79 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `.github/dependabot.yml` for automated GitHub Actions updates
1313
- `.gitignore` for local settings and Claude plans
1414
- `.claude/` configuration for AI assistant (coding rules, skills, workflow)
15+
- **deploy** action: Wait for ready feature
16+
- Wait for deployment to be reachable before continuing
17+
- New inputs: `wait-for-ready`, `health-endpoint`, `wait-timeout`, `wait-interval`
18+
- Polls deployment URL until HTTP 2xx/3xx or timeout
19+
- PR comment only appears after deployment is healthy (when combined with `comment-on-pr`)
1520

1621
### Changed
1722
- `.pre-commit-config.yaml`: require minimum version 4.5.0

deploy/README.md

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ Deploys a container image to ZAD Operations Manager.
1717
| `comment-on-pr` | No | `false` | Post/update a comment on the PR with the deployment URL |
1818
| `github-token` | No | `github.token` | GitHub token for PR commenting (defaults to automatic token) |
1919
| `comment-header` | No | `## 🚀 Preview Deployment` | Custom header for the PR comment |
20+
| `wait-for-ready` | No | `false` | Wait for deployment to be reachable |
21+
| `health-endpoint` | No | `/` | Endpoint to check for readiness |
22+
| `wait-timeout` | No | `300` | Maximum wait time in seconds |
23+
| `wait-interval` | No | `10` | Seconds between readiness checks |
2024

2125
## Outputs
2226

23-
| Name | Description |
24-
|------|-------------|
27+
| Name | Description |
28+
|-------|---------------------------------|
2529
| `url` | URL of the deployed application |
2630

2731
## Example Usage
@@ -30,17 +34,13 @@ Deploys a container image to ZAD Operations Manager.
3034

3135
```yaml
3236
- name: Deploy to ZAD
33-
id: deploy
3437
uses: RijksICTGilde/zad-actions/deploy@v1
3538
with:
3639
api-key: ${{ secrets.ZAD_API_KEY }}
37-
project-id: regel-k4c
40+
project-id: my-project
3841
deployment-name: production
39-
component: editor
40-
image: ghcr.io/minbzk/regelrecht-mvp:latest
41-
42-
- name: Show deployment URL
43-
run: echo "Deployed to ${{ steps.deploy.outputs.url }}"
42+
component: web
43+
image: ghcr.io/org/app:latest
4444
```
4545
4646
### PR Preview with Cloned Config
@@ -51,11 +51,11 @@ Deploys a container image to ZAD Operations Manager.
5151
uses: RijksICTGilde/zad-actions/deploy@v1
5252
with:
5353
api-key: ${{ secrets.ZAD_API_KEY }}
54-
project-id: regel-k4c
54+
project-id: my-project
5555
deployment-name: pr${{ github.event.pull_request.number }}
56-
component: editor
57-
image: ghcr.io/minbzk/regelrecht-mvp:pr-${{ github.event.number }}
58-
clone-from: production
56+
component: web
57+
image: ghcr.io/org/app:${{ github.sha }}
58+
clone-from: development
5959
```
6060
6161
### PR Preview with Automatic Comment
@@ -76,8 +76,8 @@ deploy-preview:
7676
project-id: my-project
7777
deployment-name: pr${{ github.event.pull_request.number }}
7878
component: web
79-
image: ghcr.io/org/app:pr-${{ github.event.number }}
80-
clone-from: production
79+
image: ghcr.io/org/app:${{ github.sha }}
80+
clone-from: development
8181
comment-on-pr: true
8282
```
8383
@@ -87,7 +87,7 @@ The action will create a comment like this on the PR:
8787
>
8888
> Your changes have been deployed to a preview environment:
8989
>
90-
> **URL:** https://web-pr123-my-project.rig.prd1.gn2.quattro.rijksapps.nl
90+
> **URL:** https://web-pr85-my-project.your-domain.example.com
9191
>
9292
> This deployment will be automatically cleaned up when the PR is closed.
9393
@@ -110,15 +110,15 @@ deploy:
110110
project-id: my-project
111111
deployment-name: pr${{ github.event.pull_request.number }}
112112
component: web
113-
image: ghcr.io/org/app:pr-${{ github.event.number }}
113+
image: ghcr.io/org/app:${{ github.sha }}
114114
```
115115
116116
## Permissions
117117
118-
| Feature | Required Permission |
119-
|---------|---------------------|
120-
| Basic deployment | None (only ZAD API key) |
121-
| PR commenting | `pull-requests: write` |
118+
| Feature | Required Permission |
119+
|------------------|---------------------------|
120+
| Basic deployment | None (only ZAD API key) |
121+
| PR commenting | `pull-requests: write` |
122122

123123
For PR commenting, ensure your job has the required permission (the token defaults to `github.token`):
124124

@@ -131,12 +131,12 @@ permissions:
131131

132132
The output URL follows the standard ZAD pattern:
133133
```
134-
https://{component}-{deployment}-{project}.rig.prd1.gn2.quattro.rijksapps.nl
134+
https://{component}-{deployment}-{project}.your-domain.example.com
135135
```
136136

137137
For example:
138-
- `component: editor`, `deployment: pr73`, `project: regel-k4c`
139-
- URL: `https://editor-pr73-regel-k4c.rig.prd1.gn2.quattro.rijksapps.nl`
138+
- `component: web`, `deployment: pr85`, `project: my-project`
139+
- URL: `https://web-pr85-my-project.your-domain.example.com`
140140

141141
### Multi-Component Deployment
142142

@@ -167,8 +167,8 @@ Deploy to different environments based on branch:
167167
deploy:
168168
runs-on: ubuntu-latest
169169
steps:
170-
- name: Deploy to staging
171-
if: github.ref == 'refs/heads/develop'
170+
- name: Deploy to preview
171+
if: github.ref == 'refs/heads/staging'
172172
uses: RijksICTGilde/zad-actions/deploy@v1
173173
with:
174174
api-key: ${{ secrets.ZAD_API_KEY }}
@@ -186,36 +186,23 @@ deploy:
186186
deployment-name: production
187187
component: web
188188
image: ghcr.io/org/app:${{ github.sha }}
189-
clone-from: staging
190189
```
191190

192191
### Deploy with Deployment Status Check
193192

194-
Wait for deployment to be healthy:
193+
Wait for deployment to be healthy using the built-in `wait-for-ready` feature:
195194

196195
```yaml
197196
- name: Deploy to ZAD
198-
id: deploy
199197
uses: RijksICTGilde/zad-actions/deploy@v1
200198
with:
201199
api-key: ${{ secrets.ZAD_API_KEY }}
202200
project-id: my-project
203201
deployment-name: production
204202
component: web
205203
image: ghcr.io/org/app:latest
206-
207-
- name: Wait for deployment to be ready
208-
run: |
209-
for i in {1..30}; do
210-
if curl -s -o /dev/null -w "%{http_code}" "${{ steps.deploy.outputs.url }}/health" | grep -q "200"; then
211-
echo "Deployment is healthy!"
212-
exit 0
213-
fi
214-
echo "Waiting for deployment... (attempt $i/30)"
215-
sleep 10
216-
done
217-
echo "Deployment health check timed out"
218-
exit 1
204+
wait-for-ready: true
205+
health-endpoint: /health
219206
```
220207

221208
## How It Works

deploy/action.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ inputs:
4747
description: 'Custom header for the PR comment (default: "## 🚀 Preview Deployment")'
4848
required: false
4949
default: '## 🚀 Preview Deployment'
50+
wait-for-ready:
51+
description: 'Wait for deployment to be reachable before continuing'
52+
required: false
53+
default: 'false'
54+
health-endpoint:
55+
description: 'Endpoint to check for readiness (e.g., /, /health)'
56+
required: false
57+
default: '/'
58+
wait-timeout:
59+
description: 'Maximum time to wait for deployment in seconds'
60+
required: false
61+
default: '300'
62+
wait-interval:
63+
description: 'Seconds between readiness checks'
64+
required: false
65+
default: '10'
5066

5167
outputs:
5268
url:
@@ -181,6 +197,35 @@ runs:
181197
exit 1
182198
fi
183199
200+
- name: Wait for deployment to be ready
201+
if: inputs.wait-for-ready == 'true'
202+
shell: bash
203+
env:
204+
DEPLOYMENT_URL: ${{ steps.deploy.outputs.url }}
205+
HEALTH_ENDPOINT: ${{ inputs.health-endpoint }}
206+
WAIT_TIMEOUT: ${{ inputs.wait-timeout }}
207+
WAIT_INTERVAL: ${{ inputs.wait-interval }}
208+
run: |
209+
URL="${DEPLOYMENT_URL}${HEALTH_ENDPOINT}"
210+
echo "Waiting for $URL to be ready..."
211+
212+
ELAPSED=0
213+
while [ "$ELAPSED" -lt "$WAIT_TIMEOUT" ]; do
214+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$URL" || echo "000")
215+
216+
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 400 ]; then
217+
echo "Deployment is ready (HTTP $HTTP_CODE)"
218+
exit 0
219+
fi
220+
221+
echo "Waiting... (HTTP $HTTP_CODE, ${ELAPSED}s elapsed)"
222+
sleep "$WAIT_INTERVAL"
223+
ELAPSED=$((ELAPSED + WAIT_INTERVAL))
224+
done
225+
226+
echo "::error::Deployment did not become ready within ${WAIT_TIMEOUT}s"
227+
exit 1
228+
184229
- name: Comment on PR
185230
if: inputs.comment-on-pr == 'true' && github.event_name == 'pull_request'
186231
shell: bash

0 commit comments

Comments
 (0)