-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
223 lines (200 loc) · 7.37 KB
/
action.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# Copyright © 2022 Dimitri Prosper <[email protected]>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Create, Update and Delete to IBM Cloud Code Engine
branding:
icon: 'server'
color: 'blue'
description: 'Create, Update and Delete a project and deploy an app in IBM Cloud Code Engine.'
inputs:
APP_SECRET:
description: A secret of some sort, if needed by the application
required: false
CE_ACTION:
description: What to do in CE, create, create_project, create_app, create_secrets, create_bindings or delete
required: true
IMAGE:
description: Container image
required: false
ISSUE_NUMBER:
description: Issue Number
required: false
REGISTRY:
description: Container registry
required: false
default: https://index.docker.io/v1/
REGISTRY_USER:
description: Container registry user name
required: false
REGISTRY_PASSWORD:
description: Container registry user password
required: false
CE_REGISTRY_SECRET:
description: Name of secret for the registry in Code Engine
required: false
default: registry-secret
CE_PROJECT_NAME:
description: Code Engine Project name
required: false
default: demo-project
CE_APP_NAME:
description: Code Engine Application name
required: false
default: demo-app
APP_PORT:
description: Port number used by application
required: false
default: 3000
outputs:
url:
description: 'url of newly deployed app'
value: ${{ steps.ceapp.outputs.url }}
runs:
using: "composite"
steps:
# Create Steps
- name: Run create shell script
if: ${{ inputs.CE_ACTION == 'create' }}
id: ceapp
run: ${{ github.action_path }}/icce-create.sh
shell: bash
env:
APP_SECRET: ${{ inputs.APP_SECRET }}
CE_PROJECT_NAME: ${{ inputs.CE_PROJECT_NAME }}
CE_APP_NAME: ${{ inputs.CE_APP_NAME }}
IMAGE: ${{ inputs.IMAGE }}
REGISTRY: ${{ inputs.REGISTRY }}
REGISTRY_USER: ${{ inputs.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ inputs.REGISTRY_PASSWORD }}
CE_REGISTRY_SECRET: ${{ inputs.CE_REGISTRY_SECRET }}
APP_PORT: ${{ inputs.APP_PORT }}
- name: Message success
if: ${{ success() && inputs.CE_ACTION == 'create' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<!--- ${{ inputs.CE_PROJECT_NAME }} --->
:sparkles: [Open Application in Code Engine][1]
[1]: ${{ steps.ceapp.outputs.url }}`
});
- name: Message failure
if: ${{ failure() && inputs.CE_ACTION == 'create' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<!--- ${{ inputs.CE_PROJECT_NAME }} --->
body: `:bug: Project or app creation failed! Please review the actions log for the events and logs from your project.`,
});
# Delete Steps
- name: Find Comment
if: ${{ inputs.CE_ACTION == 'delete' }}
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ inputs.ISSUE_NUMBER }}
body-includes: Open Application in Code Engine
comment-author: 'github-actions[bot]'
direction: last
- uses: actions/github-script@v6
if: ${{ inputs.CE_ACTION == 'delete' }}
id: set-result
with:
script: |
let body = `${{ steps.fc.outputs.comment-body }}`
let project = body.substring(
body.indexOf("<!--- ") + 6,
body.lastIndexOf(" --->")
);
return project
result-encoding: string
- name: Run delete shell script
if: ${{ steps.set-result.outputs.result != '' && inputs.CE_ACTION == 'delete' }}
id: cedelete
run: ${{ github.action_path }}/icce-delete.sh
shell: bash
env:
CE_PROJECT_NAME: ${{ steps.set-result.outputs.result }}
- name: Message success
if: ${{ success() && steps.set-result.outputs.result != '' && inputs.CE_ACTION == 'delete' }}
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.fc.outputs.comment-id }},
body: `The project was successfuly deleted from Code Engine.`
})
- name: Message failure
if: ${{ failure() && steps.set-result.outputs.result != '' && inputs.CE_ACTION == 'delete' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:exclamation: The deletion of the project in Code Engine failed!`,
});
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `ACTION REQUIRED: Project deletion failure`,
body: `:exclamation: The deletion of the project ${{ inputs.CE_PROJECT_NAME }} in Code Engine failed!`,
labels: ['bug', 'automation'],
});
# Update Steps
- name: Run update shell script
if: ${{ inputs.CE_ACTION == 'update' }}
id: ceupdate
run: ${{ github.action_path }}/icce-update.sh
shell: bash
env:
CE_PROJECT_NAME: ${{ inputs.CE_PROJECT_NAME }}
CE_APP_NAME: ${{ inputs.CE_APP_NAME }}
IMAGE: ${{ inputs.IMAGE }}
CE_REGISTRY_SECRET: ${{ inputs.CE_REGISTRY_SECRET }}
- name: Message success
if: ${{ success() && inputs.CE_ACTION == 'update' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `The production release was successfuly updated.`
});
- name: Message failure
if: ${{ failure() && inputs.CE_ACTION == 'update' }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:exclamation: The production release update failed!`,
});
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `ACTION REQUIRED: Project update failure`,
body: `:exclamation: The production release update failed!`,
labels: ['bug', 'automation'],
});