forked from IBM/code-engine-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
171 lines (146 loc) · 6.18 KB
/
action.yml
File metadata and controls
171 lines (146 loc) · 6.18 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Code Engine GitHub Action
description: Github action to interact with IBM Cloud Code Engine deploy Apps, Jobs and Functions
author: IBM
branding:
icon: cloud
color: blue
inputs:
api-key:
description: IAM API Key used to log into the IBM Cloud
required: true
resource-group:
description: An IBM Cloud Resource Group is a logical container used to organize and manage related cloud resources
required: false
region:
description: The Region refers to a geographical area where the project is are located
required: true
project:
description: A Code Engine Project Is the grouping of your Apps, Functions and Jobs
required: true
# App, Function or Job Specific inputs
component:
description: The type of component that should be deployed [App, Function, Job]
required: true
name:
description: Name of the App, Function or Job
required: true
runtime:
description: Runtime used for the Function only required for function
required: false
build-source:
description: path to the directory containing the source code
required: false
default: .
build-size:
description: The size to use for the build, which determines the amount of resources used. Valid values include small, medium, large, xlarge, and xxlarge.
required: false
default: medium
cpu:
description: CPU configuration set for the component. If not set default Code Engine values are used.
required: false
memory:
description: Memory configuration set for the component. If not set default Code Engine values are used.
required: false
# actual action code
runs:
using: composite
steps:
# Default steps required
- name: Install IBM Cloud CLI
shell: bash
run: curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
- name: Login to IBM Cloud And target Resouce Groupe and Region
shell: bash
run: |
ibmcloud login --apikey ${{ inputs.api-key }} -r ${{ inputs.region }}
- name: Set Resource Group
shell: bash
run: |
if [[ "${{ inputs.resource-group }}" != "" ]] ; then
ibmcloud target -g ${{ inputs.resource-group }}
else
ibmcloud target -g $(ibmcloud resource groups --default --output JSON | jq -r '.[0].id')
fi
- name: Install Code Engine Plugin
shell: bash
run: ibmcloud plugin install code-engine
# Select the project using Name or ID
# If the project doesn`t exist the project is created with the provided Name
- name: Select Code Engine Project
shell: bash
run: |
if ibmcloud ce project select --name "${{ inputs.project }}" || ibmcloud ce project select --id ${{ inputs.project }} ; then
echo "Project Selected"
else
ibmcloud ce project create --name "${{ inputs.project }}"
fi
# set resources for target
- name: Set resources
id: set-resources
shell: bash
run: |
# set the CPU value
if [[ "${{ inputs.cpu }}" != "" ]] ; then
echo "cpu=--cpu ${{ inputs.cpu }}" >> "$GITHUB_OUTPUT"
else
echo "cpu=" >> "$GITHUB_OUTPUT"
fi
# set the memory value
if [[ "${{ inputs.memory }}" != "" ]] ; then
echo "memory=--memory ${{ inputs.memory }}" >> "$GITHUB_OUTPUT"
else
echo "memory=" >> "$GITHUB_OUTPUT"
fi
# Functions Steps
- name: Create or Update Functions
shell: bash
id: fn-create
if: ( inputs.component == 'function' || inputs.component == 'func' || inputs.component == 'fn' )
run: |
if ibmcloud ce fn get --name ${{ inputs.name }} ; then
ibmcloud ce fn update --name ${{ inputs.name }} --runtime ${{ inputs.runtime }} --build-source ${{ inputs.build-source }} ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
else
ibmcloud ce fn create --name ${{ inputs.name }} --runtime ${{ inputs.runtime }} --build-source ${{ inputs.build-source }} ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
fi
# Application Steps
- name: Create or Update Application
shell: bash
id: create-app
if: ( inputs.component == 'application' || inputs.component == 'app' )
run: |
if ibmcloud ce application get --name ${{ inputs.name }} ; then
ibmcloud ce application update --name ${{ inputs.name }} --build-source ${{ inputs.build-source }} --build-size ${{ inputs.build-size }} ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
else
ibmcloud ce application create --name ${{ inputs.name }} --build-source ${{ inputs.build-source }} --build-size ${{ inputs.build-size }} ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
fi
# Job Steps
- name: Create or Update Job
shell: bash
id: create-job
if: inputs.component == 'job'
run: |
if ibmcloud ce job get --name ${{ inputs.name }} ; then
ibmcloud ce job update --name ${{ inputs.name }} --build-source ${{ inputs.build-source }} --build-size ${{ inputs.build-size }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
else
ibmcloud ce job create --name ${{ inputs.name }} --build-source ${{ inputs.build-source }} --build-size ${{ inputs.build-size }} --wait ${{ steps.set-resources.outputs.cpu }} ${{ steps.set-resources.outputs.memory }}
fi
- name: Get component
shell: bash
if: steps.fn-create.outcome == 'success' || steps.app-create.outcome == 'success' || steps.job-create.outcome == 'success'
run: |
case ${{ inputs.component }} in
function|func|fn)
ibmcloud ce fn get --name ${{ inputs.name }}
;;
application|app)
ibmcloud ce app get --name ${{ inputs.name }}
;;
job)
ibmcloud ce job get --name ${{ inputs.name }}
;;
*)
echo "Wrong Code Engine component used!"
echo "Use[ function | func | fn | application | app | job ]"
exit 1
;;
esac