-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (139 loc) · 4.52 KB
/
Copy pathpull-request.yaml
File metadata and controls
152 lines (139 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Pull Request
on:
pull_request:
branches:
- master
- "feature/**"
- "release/**"
types:
- closed
- labeled
- opened
- reopened
- synchronize
- unlabeled
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build & Push
if: github.event.pull_request.state == 'open' && !github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'deploy')
uses: ./.github/workflows/builder.yaml
permissions:
contents: read
packages: write
with:
context: .
image_name: ${{ vars.APP_NAME }}
github_username: ${{ github.repository_owner }}
secrets:
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
deploy-pr:
name: Deploy Instance
needs: build
permissions:
contents: read
uses: ./.github/workflows/deployer.yaml
with:
app_name: ${{ vars.APP_NAME }}
acronym: ${{ vars.ACRONYM }}
environment: pr
image_tag: ${{ needs.build.outputs.image_tag }}
job_name: pr-${{ github.event.number }}
namespace_prefix: ${{ vars.NAMESPACE_PREFIX }}
namespace_environment: dev
secrets:
openshift_server: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
seed-db:
name: Seed database
needs: deploy-pr
environment:
name: pr
permissions:
contents: read
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Login to OpenShift Cluster
uses: bcgov/action-oc-runner@111868d1fc50db0a40417ba321d865ef5c931bbd # v1.7.0
with:
oc_server: ${{ secrets.OPENSHIFT_SERVER }}
oc_token: ${{ secrets.OPENSHIFT_TOKEN }}
oc_namespace: ${{ vars.NAMESPACE_PREFIX }}-dev
- name: Run database seeds
shell: bash
run: |
kubectl exec $(oc get pods --selector='app.kubernetes.io/instance=pr-${{ github.event.number }},app.kubernetes.io/name=nr-permitconnect-navigator-service' -o custom-columns=POD:.metadata.name --no-headers | head -1) -- \
/usr/local/bin/node \
./node_modules/knex/bin/cli.js \
seed:run \
--specific=dev_groups.js \
--knexfile=./sbin/knexfile.js
comment-pr:
name: Comment on PR
needs:
- deploy-pr
- seed-db
permissions:
pull-requests: write
runs-on: ubuntu-latest
if: success()
steps:
- name: Release Comment on PR
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
if: success()
with:
header: release
message: |
Release ${{ github.sha }} deployed at <https://${{ vars.ACRONYM }}-dev-pr-${{ github.event.number }}.apps.silver.devops.gov.bc.ca>
destroy:
name: Destroy Instance
if: >
!github.event.pull_request.head.repo.fork &&
(
(
github.event.pull_request.state == 'closed' &&
contains(github.event.pull_request.labels.*.name, 'deploy')
) ||
(
github.event.action == 'unlabeled' &&
github.event.label.name == 'deploy'
)
)
environment:
name: pr
permissions:
contents: read
pull-requests: write
deployments: write
runs-on: ubuntu-latest
timeout-minutes: 12
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Login to OpenShift Cluster
uses: bcgov/action-oc-runner@111868d1fc50db0a40417ba321d865ef5c931bbd # v1.7.0
with:
oc_server: ${{ secrets.OPENSHIFT_SERVER }}
oc_token: ${{ secrets.OPENSHIFT_TOKEN }}
oc_namespace: ${{ vars.NAMESPACE_PREFIX }}-dev
- name: Remove PR Deployment
shell: bash
run: |
helm uninstall --namespace ${{ vars.NAMESPACE_PREFIX }}-dev pr-${{ github.event.number }} --timeout 10m --wait
oc delete --namespace ${{ vars.NAMESPACE_PREFIX }}-dev cm,secret --selector app.kubernetes.io/instance=pr-${{ github.event.number }}
- name: Remove Release Comment on PR
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
with:
header: release
delete: true
- name: Remove Github Deployment Environment
uses: strumwolf/delete-deployment-environment@v4
with:
environment: pr
onlyRemoveDeployments: true
token: ${{ secrets.GITHUB_TOKEN }}