-
Notifications
You must be signed in to change notification settings - Fork 211
123 lines (114 loc) · 5.09 KB
/
application-onboarding-or-promotion-automation.yml
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
name: Automation for application onboarding or promotion
on:
workflow_dispatch:
inputs:
application_name:
description: Application name
required: true
type: string
application_environment:
description: Application environment
required: true
type: choice
options:
- dev
- staging
- sandbox
- prod
- utility
maintainer_github_user:
description: Maintainer GitHub username
required: true
type: string
task:
description: Onboarding or promoting
required: true
type: choice
options:
- onboarding
- promoting
workflow_call:
inputs:
application_name:
description: Application name
required: true
type: string
application_environment:
description: Application environment
required: true
type: string
maintainer_github_user:
description: Maintainer GitHub username
required: true
type: string
task:
description: Onboarding or promoting
required: true
type: string
jobs:
application-onboarding-or-promotion:
runs-on: ubuntu-latest
steps:
- name: Check out ArgoCD infra repo
uses: actions/checkout@v2
with:
repository: department-of-veterans-affairs/vsp-infra-argocd
token: ${{ secrets.VA_VSP_BOT_GITHUB_TOKEN }}
path: vsp-infra-argocd
- name: Check if application already exists
id: application_check
run: |
export application_exists=$(cat vsp-infra-argocd/chart/values.yaml | yq -o=json | jq -e '.projects|any(.name == "${{ inputs.application_name }}")' || true)
if [ -z "$application_exists" ]; then export application_exists=false; fi
echo "application_exists=$(echo ${application_exists})" >> $GITHUB_OUTPUT
- name: Check if application environment exists
id: environment_check
run: |
export environment_exists=$(yq '[.projects[] | select(.name == "${{ inputs.application_name }}")] | .[].environments | contains(["${{ inputs.application_environment }}"])' vsp-infra-argocd/chart/values.yaml || true)
if [ -z "$environment_exists" ]; then export environment_exists=false; fi
echo "environment_exists=$(echo ${environment_exists})" >> $GITHUB_OUTPUT
- name: If application and environment exist
if: |
steps.application_check.outputs.application_exists == 'true' &&
steps.environment_check.outputs.environment_exists == 'true'
uses: KeisukeYamashita/create-comment@v1
with:
token: ${{ secrets.VA_VSP_BOT_GITHUB_TOKEN }}
comment: |
${{ inputs.application_name }} is already deployed to ${{ inputs.application_environment }} as defined
in the `projects` here https://github.com/department-of-veterans-affairs/vsp-infra-argocd/blob/main/chart/values.yaml
- name: If application does not exist
if: steps.application_check.outputs.application_exists == 'false'
run: |
cd vsp-infra-argocd/chart
yq -i '.projects += [{"name": "${{ inputs.application_name }}", "environments":[]}]' values.yaml
git add -A
- name: If environment does not exist
if: steps.environment_check.outputs.environment_exists == 'false'
run: |
cd vsp-infra-argocd/chart
yq -i '(.projects[] | select(.name == "${{ inputs.application_name }}")).environments += ["${{ inputs.application_environment }}"]' values.yaml
git add -A
- name: Create pull request
if: |
steps.application_exists.outputs.application_exists == 'false' ||
steps.environment_check.outputs.environment_exists == 'false'
id: cpr
uses: peter-evans/create-pull-request@v4
with:
path: vsp-infra-argocd
token: ${{ secrets.VA_VSP_BOT_GITHUB_TOKEN }}
add-paths: chart/values.yaml
branch: "chore/${{ inputs.task }}-${{ inputs.application_name }}-${{ inputs.application_environment }}"
commit-message: |
{"application": "${{ inputs.application_name }}", "maintainer": "${{ inputs.maintainer_github_user }}", "environment": "${{ inputs.application_environment }}", "task": "${{ inputs.task }}"}
title: ${{ inputs.task }} ${{ inputs.application_name }} to the ${{ inputs.application_environment }} environment
body: Automated PR triggered by issue ${{ github.event.issue.html_url }} for ${{ inputs.task }} ${{ inputs.application_name }} to ${{ inputs.application_environment }}
- name: Comment on pull request
if: steps.cpr.outputs.pull-request-number
uses: KeisukeYamashita/create-comment@v1
with:
token: ${{ secrets.VA_VSP_BOT_GITHUB_TOKEN }}
comment: |
The following PR has been created for ${{ inputs.task }} ${{ inputs.application_name }} to the ${{ inputs.application_environment }} environment
${{ steps.cpr.outputs.pull-request-url }}