Skip to content

Commit 9c38288

Browse files
authored
Merge pull request #125 from rossjrw/workflow-call-tests
Run integration tests through workflow call
2 parents 3e4ed15 + fd2ba86 commit 9c38288

File tree

3 files changed

+377
-313
lines changed

3 files changed

+377
-313
lines changed
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
name: Integration Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: "Git ref to checkout"
8+
required: true
9+
type: string
10+
sha:
11+
description: "Git SHA for the commit"
12+
required: true
13+
type: string
14+
secrets:
15+
test-deploy-token:
16+
description: "GitHub token for test deployments"
17+
required: true
18+
19+
jobs:
20+
# Git-level tests verify repository state without waiting for Pages deployment
21+
test-git-lifecycle:
22+
name: "[Git] Lifecycle"
23+
runs-on: ubuntu-latest
24+
env:
25+
TEST_ID: test-git-lifecycle
26+
TEST_UMBRELLA_DIR: pr-preview-run-${{ github.run_id }}
27+
TEST_DEPLOY_REPO: rozzjrw/pr-preview-action-testing
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
ref: ${{ inputs.sha }}
33+
34+
- name: Modify fixture
35+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}-INITIALISED<\/p>/' test/fixtures/html/index.html
36+
37+
- name: Deploy
38+
uses: ./
39+
with:
40+
pr-number: ${{ env.TEST_ID }}
41+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
42+
token: ${{ secrets.test-deploy-token }}
43+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
44+
preview-branch: ${{ env.TEST_ID }}
45+
source-dir: test/fixtures/html
46+
action: deploy
47+
comment: false
48+
wait-for-pages-deployment: false
49+
git-config-name: GitHub Actions
50+
git-config-email: actions@github.com
51+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
52+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
53+
54+
- name: Verify deployed
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
57+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
58+
PREVIEW_BRANCH: ${{ env.TEST_ID }}
59+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
60+
run: bash test/integration/test-git-lifecycle.sh "deployed" "${{ env.TEST_ID }}-INITIALISED"
61+
62+
- name: Modify fixture
63+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}-REDEPLOYED<\/p>/' test/fixtures/html/index.html
64+
65+
- name: Redeploy
66+
uses: ./
67+
with:
68+
pr-number: ${{ env.TEST_ID }}
69+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
70+
token: ${{ secrets.test-deploy-token }}
71+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
72+
preview-branch: ${{ env.TEST_ID }}
73+
source-dir: test/fixtures/html
74+
action: deploy
75+
comment: false
76+
wait-for-pages-deployment: false
77+
git-config-name: GitHub Actions
78+
git-config-email: actions@github.com
79+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
80+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
81+
82+
- name: Verify redeployed
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
85+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
86+
PREVIEW_BRANCH: ${{ env.TEST_ID }}
87+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
88+
run: bash test/integration/test-git-lifecycle.sh "deployed" "${{ env.TEST_ID }}-REDEPLOYED"
89+
90+
- name: Remove
91+
uses: ./
92+
with:
93+
pr-number: ${{ env.TEST_ID }}
94+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
95+
token: ${{ secrets.test-deploy-token }}
96+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
97+
preview-branch: ${{ env.TEST_ID }}
98+
action: remove
99+
comment: false
100+
wait-for-pages-deployment: false
101+
git-config-name: GitHub Actions
102+
git-config-email: actions@github.com
103+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
104+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
105+
106+
- name: Verify removed
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
109+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
110+
PREVIEW_BRANCH: ${{ env.TEST_ID }}
111+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
112+
run: bash test/integration/test-git-lifecycle.sh "removed"
113+
114+
- name: Cleanup
115+
if: failure()
116+
run: |
117+
echo "Action removal failed or was incomplete, performing manual cleanup..."
118+
source test/lib/cleanup-test-deployment.sh
119+
cleanup_deployment "${{ env.TEST_DEPLOY_REPO }}" "${{ env.TEST_ID }}" "${{ secrets.test-deploy-token }}" "${{ env.TEST_UMBRELLA_DIR }}"
120+
121+
test-git-custom-umbrella:
122+
name: "[Git] Custom umbrella"
123+
runs-on: ubuntu-latest
124+
env:
125+
TEST_ID: test-git-custom-umbrella
126+
TEST_UMBRELLA_DIR: pr-preview-run-${{ github.run_id }}
127+
CUSTOM_UMBRELLA_DIR: custom-previews-run-${{ github.run_id }}
128+
TEST_DEPLOY_REPO: rozzjrw/pr-preview-action-testing
129+
steps:
130+
- name: Checkout
131+
uses: actions/checkout@v4
132+
with:
133+
ref: ${{ inputs.sha }}
134+
135+
- name: Modify fixture
136+
run: sed -i 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}<\/p>/' test/fixtures/html/index.html
137+
138+
- name: Deploy
139+
uses: ./
140+
with:
141+
pr-number: ${{ env.TEST_ID }}
142+
umbrella-dir: ${{ env.CUSTOM_UMBRELLA_DIR }}
143+
token: ${{ secrets.test-deploy-token }}
144+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
145+
preview-branch: ${{ env.TEST_ID }}
146+
source-dir: test/fixtures/html
147+
action: deploy
148+
comment: false
149+
wait-for-pages-deployment: false
150+
git-config-name: GitHub Actions
151+
git-config-email: actions@github.com
152+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
153+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
154+
155+
- name: Verify
156+
env:
157+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
158+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
159+
PREVIEW_BRANCH: ${{ env.TEST_ID }}
160+
TEST_UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
161+
CUSTOM_UMBRELLA_DIR: ${{ env.CUSTOM_UMBRELLA_DIR }}
162+
run: bash test/integration/test-git-custom-umbrella.sh
163+
164+
- name: Cleanup
165+
if: always()
166+
run: |
167+
source test/lib/cleanup-test-deployment.sh
168+
cleanup_deployment "${{ env.TEST_DEPLOY_REPO }}" "${{ env.TEST_ID }}" "${{ secrets.test-deploy-token }}" "${{ env.TEST_UMBRELLA_DIR }}" "${{ env.CUSTOM_UMBRELLA_DIR }}"
169+
170+
test-git-concurrent:
171+
name: "[Git] Concurrency"
172+
runs-on: ubuntu-latest
173+
env:
174+
TEST_ID: test-git-concurrent
175+
TEST_UMBRELLA_DIR: pr-preview-run-${{ github.run_id }}
176+
TEST_DEPLOY_REPO: rozzjrw/pr-preview-action-testing
177+
steps:
178+
- name: Checkout
179+
uses: actions/checkout@v4
180+
with:
181+
ref: ${{ inputs.sha }}
182+
183+
- name: Modify fixture
184+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}-1<\/p>/' test/fixtures/html/index.html
185+
186+
- name: Deploy PR 1
187+
uses: ./
188+
with:
189+
pr-number: ${{ env.TEST_ID }}-1
190+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
191+
token: ${{ secrets.test-deploy-token }}
192+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
193+
preview-branch: ${{ env.TEST_ID }}
194+
source-dir: test/fixtures/html
195+
action: deploy
196+
comment: false
197+
wait-for-pages-deployment: false
198+
git-config-name: GitHub Actions
199+
git-config-email: actions@github.com
200+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
201+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
202+
203+
- name: Modify fixture
204+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}-2<\/p>/' test/fixtures/html/index.html
205+
206+
- name: Deploy PR 2
207+
uses: ./
208+
with:
209+
pr-number: ${{ env.TEST_ID }}-2
210+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
211+
token: ${{ secrets.test-deploy-token }}
212+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
213+
preview-branch: ${{ env.TEST_ID }}
214+
source-dir: test/fixtures/html
215+
action: deploy
216+
comment: false
217+
wait-for-pages-deployment: false
218+
git-config-name: GitHub Actions
219+
git-config-email: actions@github.com
220+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
221+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
222+
223+
- name: Modify fixture
224+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}-2-redeployed<\/p>/' test/fixtures/html/index.html
225+
226+
- name: Deploy PR 2 (again)
227+
uses: ./
228+
with:
229+
pr-number: ${{ env.TEST_ID }}-2
230+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
231+
token: ${{ secrets.test-deploy-token }}
232+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
233+
preview-branch: ${{ env.TEST_ID }}
234+
source-dir: test/fixtures/html
235+
action: deploy
236+
comment: false
237+
wait-for-pages-deployment: false
238+
git-config-name: GitHub Actions
239+
git-config-email: actions@github.com
240+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
241+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
242+
243+
- name: Verify
244+
env:
245+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
246+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
247+
PREVIEW_BRANCH: ${{ env.TEST_ID }}
248+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
249+
run: bash test/integration/test-git-concurrent.sh
250+
251+
- name: Cleanup
252+
if: always()
253+
run: |
254+
source test/lib/cleanup-test-deployment.sh
255+
cleanup_deployment "${{ env.TEST_DEPLOY_REPO }}" "${{ env.TEST_ID }}" "${{ secrets.test-deploy-token }}" "${{ env.TEST_UMBRELLA_DIR }}"
256+
257+
# Pages deployment test runs after git tests pass
258+
# This is the only test that uses the actual Pages branch and waits for deployment
259+
test-pages-lifecycle:
260+
name: "[Pages] Lifecycle"
261+
needs:
262+
[test-git-custom-umbrella, test-git-lifecycle, test-git-concurrent]
263+
runs-on: ubuntu-latest
264+
env:
265+
TEST_ID: test-pages-lifecycle
266+
TEST_UMBRELLA_DIR: pr-preview-run-${{ github.run_id }}
267+
TEST_DEPLOY_REPO: rozzjrw/pr-preview-action-testing
268+
TEST_DEPLOY_REPO_BRANCH: main
269+
steps:
270+
- name: Checkout
271+
uses: actions/checkout@v4
272+
with:
273+
ref: ${{ inputs.sha }}
274+
275+
- name: Modify fixture
276+
run: sed -i.bak 's/<p id="testid">.*<\/p>/<p id="testid">${{ env.TEST_ID }}<\/p>/' test/fixtures/html/index.html
277+
278+
- name: Deploy and wait
279+
uses: ./
280+
with:
281+
pr-number: ${{ env.TEST_ID }}
282+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
283+
token: ${{ secrets.test-deploy-token }}
284+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
285+
preview-branch: ${{ env.TEST_DEPLOY_REPO_BRANCH }}
286+
source-dir: test/fixtures/html
287+
action: deploy
288+
comment: false
289+
wait-for-pages-deployment: true
290+
git-config-name: GitHub Actions
291+
git-config-email: actions@github.com
292+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
293+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
294+
295+
- name: Verify
296+
env:
297+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
298+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
299+
PREVIEW_BRANCH: ${{ env.TEST_DEPLOY_REPO_BRANCH }}
300+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
301+
run: bash test/integration/test-pages-lifecycle.sh "deployed"
302+
303+
- name: Remove
304+
uses: ./
305+
with:
306+
pr-number: ${{ env.TEST_ID }}
307+
umbrella-dir: ${{ env.TEST_UMBRELLA_DIR }}
308+
token: ${{ secrets.test-deploy-token }}
309+
deploy-repository: ${{ env.TEST_DEPLOY_REPO }}
310+
preview-branch: ${{ env.TEST_DEPLOY_REPO_BRANCH }}
311+
action: remove
312+
comment: false
313+
wait-for-pages-deployment: true
314+
git-config-name: GitHub Actions
315+
git-config-email: actions@github.com
316+
deploy-commit-message: deploy ${{ env.TEST_ID }} ${{ github.run_id }}
317+
remove-commit-message: remove ${{ env.TEST_ID }} ${{ github.run_id }}
318+
319+
- name: Verify removed
320+
env:
321+
GITHUB_TOKEN: ${{ secrets.test-deploy-token }}
322+
DEPLOY_REPO: ${{ env.TEST_DEPLOY_REPO }}
323+
PREVIEW_BRANCH: ${{ env.TEST_DEPLOY_REPO_BRANCH }}
324+
UMBRELLA_DIR: ${{ env.TEST_UMBRELLA_DIR }}
325+
run: bash test/integration/test-pages-lifecycle.sh "removed"
326+
327+
- name: Cleanup
328+
if: failure()
329+
run: |
330+
echo "Action removal failed or was incomplete, performing manual cleanup..."
331+
source test/lib/cleanup-test-deployment.sh
332+
cleanup_deployment "${{ env.TEST_DEPLOY_REPO }}" "${{ env.TEST_ID }}" "${{ secrets.test-deploy-token }}" "${{ env.TEST_UMBRELLA_DIR }}"

0 commit comments

Comments
 (0)