Skip to content

Commit 1231538

Browse files
author
Michael
authored
Merge pull request #77 from digital-land/feature/pipeline-strategy
Feature/pipeline strategy
2 parents 955714b + 2fa9627 commit 1231538

File tree

5 files changed

+217
-88
lines changed

5 files changed

+217
-88
lines changed
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,12 @@ on:
1111
description: The environment to deploy to.
1212

1313
jobs:
14+
test:
15+
uses: ./.github/workflows/test.yml
1416
detect-environments:
15-
runs-on: ubuntu-latest
16-
outputs:
17-
environments: ${{ steps.environments.outputs.result }}
18-
steps:
19-
- uses: actions/github-script@v6
20-
id: environments
21-
with:
22-
github-token: ${{ secrets.GITHUB_TOKEN }}
23-
result-encoding: json
24-
script: |
25-
const allowed = ['development', 'staging', 'production'];
26-
27-
if (context.payload?.inputs?.environment) {
28-
return allowed.includes(context.payload.inputs.environment)
29-
? [context.payload.inputs.environment]
30-
: [];
31-
}
32-
33-
const { data: { environments } } = await github.rest.repos.getAllEnvironments({
34-
owner: context.repo.owner,
35-
repo: context.repo.repo
36-
});
37-
38-
return environments.map(e => e.name).filter(name => allowed.includes(name));
17+
uses: ./.github/workflows/detect-environments.yml
18+
with:
19+
environment: ${{ github.event.inputs.environment }}
3920

4021
deploy:
4122
runs-on: ubuntu-latest
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Detect Environment to Deploy
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
description: "The environment to deploy(Optional)"
8+
required: false
9+
type: string
10+
outputs:
11+
environments:
12+
description: "List of environment names"
13+
value: ${{ jobs.run.outputs.environments }}
14+
15+
16+
jobs:
17+
run:
18+
runs-on: ubuntu-latest
19+
20+
outputs:
21+
environments: ${{ steps.environments.outputs.result }}
22+
23+
steps:
24+
- uses: actions/github-script@v6
25+
id: environments
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
result-encoding: json
29+
script: |
30+
const allowed = ['development', 'staging', 'production'];
31+
// If triggered manually with an environment in the allowed array, return it
32+
if (context.payload?.inputs?.environment) {
33+
const env = context.payload.inputs.environment
34+
return allowed.includes(env) ? [env] : [];
35+
}
36+
37+
// fetch all repo environments
38+
const { data: { environments } } = await github.rest.repos.getAllEnvironments({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo
41+
});
42+
43+
// Otherwise fetch all defined GitHub Environments
44+
return environments.map(e => e.name).filter(name => allowed.includes(name));

.github/workflows/test.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Test
2+
run-name: Test - ${{ github.head_ref || github.ref_name }} by @${{ github.actor }}
3+
4+
on:
5+
push:
6+
branches-ignore: [main]
7+
workflow_dispatch:
8+
workflow_call:
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.10'
20+
- run: make init
21+
- run: make lint
22+
23+
test:
24+
runs-on: ubuntu-22.04
25+
services:
26+
postgres:
27+
image: postgres:16.2-alpine
28+
env:
29+
POSTGRES_PASSWORD: postgres
30+
options: >-
31+
--health-cmd pg_isready
32+
--health-interval 10s
33+
--health-timeout 5s
34+
--health-retries 5
35+
ports:
36+
- 5432:5432
37+
env:
38+
DATABASE_URL: postgresql://postgres:postgres@localhost/config_manager
39+
ENVIRONMENT: development
40+
PGPASSWORD: postgres
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
46+
- uses: actions/setup-python@v4
47+
with:
48+
python-version: '3.10'
49+
50+
- run: make init
51+
52+
- name: Setup database
53+
run: |
54+
psql -h localhost -c "CREATE DATABASE config_manager WITH TEMPLATE postgres" -U postgres
55+
56+
- name: Unit Tests
57+
run: |
58+
make test-unit
59+
echo "## Unit Tests" >> $GITHUB_STEP_SUMMARY
60+
# cat unit-tests.md >> $GITHUB_STEP_SUMMARY
61+
62+
- name: Integration Tests
63+
run: |
64+
make test-integration
65+
echo "## Integration Tests" >> $GITHUB_STEP_SUMMARY
66+
# cat integration-tests.md >> $GITHUB_STEP_SUMMARY
67+
68+
- name: Acceptance Tests
69+
run: |
70+
make test-acceptance
71+
echo "## Acceptance Tests" >> $GITHUB_STEP_SUMMARY
72+
# cat acceptance-tests.md >> $GITHUB_STEP_SUMMARY
73+
74+
- name: Accessibility Tests
75+
run: |
76+
make test-accessibility
77+
echo "## Accessibility Tests" >> $GITHUB_STEP_SUMMARY
78+
# cat accessibility-tests.md >> $GITHUB_STEP_SUMMARY
79+
80+
- uses: actions/upload-artifact@v4
81+
if: always()
82+
with:
83+
name: playwright-report
84+
path: playwright-report/
85+
retention-days: 30

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,19 @@ load-data:
4747

4848
drop-data:
4949
flask data drop
50+
51+
test-unit:
52+
@echo "Running Unit test...."
53+
@echo "Not yet implemented"
54+
55+
test-integration:
56+
@echo "Running Integration test...."
57+
@echo "Not yet implemented"
58+
59+
test-acceptance:
60+
@echo "Running Acceptance test...."
61+
@echo "Not yet implemented"
62+
63+
test-accessibility:
64+
@echo "Running Accessibility test...."
65+
@echo "Not yet implemented"

0 commit comments

Comments
 (0)