@@ -2,67 +2,106 @@ name: PR Preview
22
33on :
44 pull_request :
5- types : [opened, synchronize, reopened, closed]
5+ types :
6+ - opened
7+ - reopened
8+ - synchronize
9+ - closed
10+ workflow_dispatch :
611
7- concurrency : preview-${{ github.ref }}
12+ concurrency :
13+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+ cancel-in-progress : true
815
9- permissions :
10- contents : write
11- pull-requests : write
16+ env :
17+ REGISTRY : ghcr.io
18+ IMAGE_NAME : ${{ github.repository }}/preview
1219
1320jobs :
14- preview :
21+ build :
22+ if : github.event.action != 'closed'
1523 runs-on : ubuntu-latest
24+ permissions :
25+ contents : read
26+ packages : write
27+ outputs :
28+ image : ${{ steps.meta.outputs.tags }}
1629 steps :
17- - name : Checkout repository
30+ - name : Checkout
1831 uses : actions/checkout@v4
1932
20- - name : Set up Python
21- if : github.event.action != 'closed'
22- uses : actions/setup-python@v4
23- with :
24- python-version : ' 3.12'
25-
26- - name : Install Python dependencies
27- if : github.event.action != 'closed'
28- run : pip install pyyaml jsonschema
29-
30- - name : Generate JSON from YAML definitions
31- if : github.event.action != 'closed'
32- run : |
33- mkdir -p form-app/src/assets
33+ - name : Set up Docker Buildx
34+ uses : docker/setup-buildx-action@v3
3435
35- python script/run_all.py \
36- --schema schemas/formSchema.json \
37- --source sources/prescan_DPIA.yaml \
38- --begrippen-yaml sources/begrippenkader-dpia.yaml \
39- --output-json form-app/src/assets/PreScanDPIA.json \
40- --output-md docs/questions/questions_prescan_DPIA.md
41-
42- python script/run_all.py \
43- --schema schemas/formSchema.json \
44- --source sources/DPIA.yaml \
45- --begrippen-yaml sources/begrippenkader-dpia.yaml \
46- --output-json form-app/src/assets/DPIA.json \
47- --output-md docs/questions/questions_DPIA.md
36+ - name : Log in to Container Registry
37+ uses : docker/login-action@v3
38+ with :
39+ registry : ${{ env.REGISTRY }}
40+ username : ${{ github.actor }}
41+ password : ${{ secrets.GITHUB_TOKEN }}
4842
49- - name : Set up Node.js
50- if : github.event.action != 'closed'
51- uses : actions/setup-node@v4
43+ - name : Extract metadata
44+ id : meta
45+ uses : docker/metadata-action@v5
5246 with :
53- node-version : ' 20 '
54- cache : ' npm '
55- cache-dependency-path : ' form-app/package-lock.json '
47+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+ tags : |
49+ type=sha,format=short,prefix=pr-${{ github.event.pull_request.number }}-
5650
57- - name : Install Node dependencies
58- if : github.event.action != 'closed'
59- run : cd form-app && npm ci
51+ - name : Build and push container image
52+ uses : docker/build-push-action@v6
53+ with :
54+ context : .
55+ push : true
56+ tags : ${{ steps.meta.outputs.tags }}
57+ labels : ${{ steps.meta.outputs.labels }}
58+ cache-from : type=gha
59+ cache-to : type=gha,mode=max
6060
61- - name : Build the Vue application
62- if : github.event.action != 'closed'
63- run : cd form-app && npm run build
61+ deploy-preview :
62+ if : github.event_name == 'pull_request' && github.event.action != 'closed'
63+ runs-on : ubuntu-latest
64+ permissions :
65+ contents : read
66+ deployments : write
67+ pull-requests : write
68+ needs : build
69+ environment :
70+ name : pr-${{ github.event.pull_request.number }}
71+ url : ${{ steps.deploy.outputs.url }}
72+ steps :
73+ - name : Deploy to ZAD
74+ id : deploy
75+ uses : RijksICTGilde/zad-actions/deploy@v3
76+ with :
77+ api-key : ${{ secrets.ZAD_API_KEY }}
78+ project-id : dt-9s2
79+ deployment-name : pr-${{ github.event.pull_request.number }}
80+ component : web
81+ image : ${{ needs.build.outputs.image }}
82+ comment-on-pr : true
83+ qr-code : true
84+ wait-for-ready : true
6485
65- - name : Deploy PR preview
66- uses : rossjrw/pr-preview-action@v1
86+ cleanup-preview :
87+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
88+ runs-on : ubuntu-latest
89+ permissions :
90+ deployments : write
91+ packages : delete
92+ pull-requests : write
93+ steps :
94+ - name : Cleanup ZAD deployment
95+ uses : RijksICTGilde/zad-actions/cleanup@v3
6796 with :
68- source-dir : form-app/dist/
97+ api-key : ${{ secrets.ZAD_API_KEY }}
98+ project-id : dt-9s2
99+ deployment-name : pr-${{ github.event.pull_request.number }}
100+ delete-github-env : true
101+ delete-github-deployments : true
102+ delete-pr-comment : true
103+ delete-container : true
104+ container-org : ${{ github.repository_owner }}
105+ container-name : ${{ github.event.repository.name }}/preview
106+ container-tag : pr-${{ github.event.pull_request.number }}
107+ github-admin-token : ${{ secrets.GITHUB_ADMIN_TOKEN }}
0 commit comments