-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
306 lines (275 loc) · 13.7 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
name: "Prismatic Integration Publisher"
description: "Import and publish an integration via Prismatic's Prism CLI"
branding:
icon: "upload-cloud"
color: "blue"
inputs:
INTEGRATION_ID:
description: "The ID of the integration to be published."
required: true
PATH_TO_YML:
description: "Path to the YAML file containing the integration configuration."
required: false
PATH_TO_CNI:
description: "The path to the Code Native Integration source code, usually the same location as the CNI's package.json. If not provided, the root will be used."
required: false
PRISMATIC_URL:
description: "The target Prismatic API to import to."
required: true
PRISM_REFRESH_TOKEN:
description: "The token granting access to the API at the PRISMATIC_URL provided."
required: true
SKIP_COMMIT_HASH_PUBLISH:
description: "Skip inclusion of commit hash in metadata."
required: false
default: false
SKIP_COMMIT_URL_PUBLISH:
description: "Skip inclusion of commit url in metadata."
required: false
default: false
SKIP_REPO_URL_PUBLISH:
description: "Skip inclusion of repository url in metadata."
required: false
default: false
SKIP_PULL_REQUEST_URL_PUBLISH:
description: "Skip inclusion of pull request url in metadata."
required: false
default: false
MAKE_AVAILABLE_IN_MARKETPLACE:
description: "Make version available in the marketplace."
required: false
default: false
OVERVIEW:
description: "Overview to describe the purpose of the integration."
required: false
default: ""
runs:
using: "composite"
steps:
- name: Set up logger and text colors
shell: bash
run: |
echo "ERROR=\033[31m" >> $GITHUB_ENV
echo "INFO=\033[1;4;34;38;2;96;120;226m" >> $GITHUB_ENV
echo "COLOR_RESET=\033[0m" >> $GITHUB_ENV
echo 'log() { local color=$1; local message=$2; echo -e ${color}${message}${COLOR_RESET}; }' > $GITHUB_WORKSPACE/logger.sh
- name: Get commit details from 'github' context
id: commit-details
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
log $INFO "Getting commit details from context..."
echo "COMMIT_HASH=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
echo "COMMIT_URL=https://github.com/${{ github.repository }}/commit/${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
- name: Get PR details from Github CLI
id: pr-details
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
log $INFO "Getting PR details from Github CLI..."
PR_DETAILS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0]')
if [[ -z "$PR_DETAILS" ]]; then
log $INFO "No PRs associated with this commit."
echo "PR_NUMBER=" >> $GITHUB_OUTPUT
echo "PR_URL=" >> $GITHUB_OUTPUT
else
PR_NUMBER=$(echo $PR_DETAILS | jq -r '.number')
PR_URL=$(echo $PR_DETAILS | jq -r '.html_url')
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "PR_URL=${PR_URL}" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Print source control details
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
log $INFO "The commit hash is ${{ steps.commit-details.outputs.COMMIT_HASH }}"
log $INFO "The commit url is ${{ steps.commit-details.outputs.COMMIT_URL }}"
if [ -n "${{ steps.pr-details.outputs.PR_URL }}" ]; then
log $INFO "The PR url is ${{ steps.pr-details.outputs.PR_URL }}"
fi
# Node may be installed in the parent workflow. This ensures the version is what Prism expects.
# This action will use a cached version if available.
- name: Set up Node using Github Action
uses: actions/setup-node@v4
with:
node-version: "18.19.1"
# Check for existence of required inputs.
- name: Check if PRISMATIC_URL is set
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
if [ -z "${{ inputs.PRISMATIC_URL }}" ]; then
log $ERROR "PRISMATIC_URL is not set"
exit 1
else
log $INFO "PRISMATIC_URL: ${{ inputs.PRISMATIC_URL }}"
fi
- name: Check if PRISM_REFRESH_TOKEN is set
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
if [ -z "${{ inputs.PRISM_REFRESH_TOKEN }}" ]; then
log $ERROR "PRISM_REFRESH_TOKEN is not set"
exit 1
fi
- name: Check if INTEGRATION_ID is set
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
if [ -z "${{ inputs.INTEGRATION_ID }}" ]; then
log $ERROR "INTEGRATION_ID is not set"
exit 1
else
log $INFO "INTEGRATION_ID: ${{ inputs.INTEGRATION_ID }}"
fi
- name: Check if PATH_TO_YML or PATH_TO_CNI is set
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
if [ -z "${{ inputs.PATH_TO_YML }}" ] && [ -z "${{ inputs.PATH_TO_CNI }}" ]; then
log $ERROR "Neither PATH_TO_YML nor PATH_TO_CNI is set"
exit 1
elif [ -n "${{ inputs.PATH_TO_CNI }}" ] && [ -n "${{ inputs.PATH_TO_YML }}" ]; then
log $ERROR "Both PATH_TO_YML and PATH_TO_CNI have been provided. Please provide only one of these inputs."
exit 1
elif [ -n "${{ inputs.PATH_TO_YML }}" ]; then
log $INFO "PATH_TO_YML: ${{ inputs.PATH_TO_YML }}"
elif [ -n "${{ inputs.PATH_TO_CNI }}" ]; then
log $INFO "Publishing code-native integration. PATH_TO_CNI: ${{ inputs.PATH_TO_CNI }}"
fi
- name: Print logo to console once
if: ${{ !env.LOGO_SHOWN }}
shell: bash
run: |
echo -e "
\n
\033[38;2;12;193;144m .+. \033[38;2;73;74;167m .#- -#-
\033[38;2;8;199;150m .#\033[38;2;12;193;144m.##\033[38;2;10;195;152m+\033[38;2;10;195;152m#+ \033[38;2;73;74;167m -#+ ##. -#+
\033[38;2;14;190;146m ###\033[38;2;28;168;164m#.\033[38;2;30;163;167m+\033[38;2;18;185;154m#+ \033[38;2;73;74;167m ... .-+-. ....-+- ... .-+-. ....-++. .-+-. .---.. ...##.... ... .-++-.
\033[38;2;16;187;148m ##\033[38;2;28;168;164m+\033[38;2;32;161;166m+ \033[38;2;35;155;171m### \033[38;2;73;74;167m -#####++###. +#####+ .## +##++### .####+######+###. +###+###+ .#######. -#+ .###++###-
\033[38;2;17;185;150m #- \033[38;2;32;161;166m+#+ \033[38;2;30;169;158m-\033[38;2;35;155;171m## \033[38;2;73;74;167m -##. .##. +#+ .## ##+. .##. +##. .##. . ..##. ##. -#+ .##. ..
\033[38;2;19;182;152m .##-\033[38;2;31;162;168m .###.\033[38;2;40;148;173m \033[38;2;40;148;174m-##. \033[38;2;73;74;167m -#+ ##- +#- .## -#####- .## -## .##. -#####+##. ##. -#+ +##
\033[38;2;20;180;154m .##. \033[38;2;31;162;167m.##+\033[38;2;37;153;172m##. \033[38;2;46;140;175m.##. \033[38;2;73;74;167m -##- .##. +#- .## . ##+ .## -## .##. ##. .##. ##. -#+ .##. ..
\033[38;2;22;177;156m .##.\033[38;2;33;158;169m .##. \033[38;2;47;140;175m.##-\033[38;2;55;131;174m .##- \033[38;2;73;74;167m -#####+####. +#- .## ########. .## -## .##. ####+####. ###+#. -#+ .###++###-
\033[38;2;24;174;158m -##.\033[38;2;36;155;171m ###\033[38;2;44;143;175m###\033[38;2;49;137;174m### \033[38;2;62;122;174m.#\033[38;2;62;122;174m#+ \033[38;2;73;74;167m -## .-+-. ... ... ..-. ... ... ... ..--. ... .--. ... .-+-.
\033[38;2;25;172;159m +## \033[38;2;66;118;173m#\033[38;2;69;115;173m## \033[38;2;73;74;167m -##
\033[38;2;26;170;160m .+\033[38;2;31;164;161m#\033[38;2;34;161;162m#\033[38;2;37;158;163m#\033[38;2;38;156;163m#\033[38;2;39;154;163m#\033[38;2;41;151;164m#\033[38;2;42;149;164m#\033[38;2;45;146;165m#\033[38;2;46;144;165m#\033[38;2;48;142;166m#\033[38;2;49;141;166m#\033[38;2;50;140;166m#\033[38;2;52;138;167m#\033[38;2;53;136;167m#\033[38;2;56;132;168m#\033[38;2;57;130;168m#\033[38;2;60;126;169m#\033[38;2;61;124;169m#\033[38;2;65;119;173m#\033[38;2;71;112;173m#\033[38;2;71;112;173m#\033[38;2;64;120;170m#. \033[38;2;73;74;167m -#.
\n
"
echo "LOGO_SHOWN=true" >> "$GITHUB_ENV"
- name: Install Prism
shell: bash
run: |
source $GITHUB_WORKSPACE/logger.sh
if ! npm list -g @prismatic-io/prism &> /dev/null; then
log $INFO "\U1F527 Prism CLI is not installed. Installing..."
npm install --global @prismatic-io/prism
else
log $INFO "Prism CLI is already installed."
fi
- name: Import Integration
shell: bash
run: |
if [ -n "${{ inputs.PATH_TO_YML }}" ]; then
prism integrations:import -i="${{ inputs.INTEGRATION_ID }}" -p="${{ inputs.PATH_TO_YML }}"
elif [ -n "${{ inputs.PATH_TO_CNI }}" ]; then
cd "${{ inputs.PATH_TO_CNI }}"
prism integrations:import -i="${{ inputs.INTEGRATION_ID }}"
else
echo "Neither PATH_TO_YML nor PATH_TO_CNI is set"
exit 1
fi
env:
PRISMATIC_URL: ${{ inputs.PRISMATIC_URL }}
PRISM_REFRESH_TOKEN: ${{ inputs.PRISM_REFRESH_TOKEN }}
- name: Publish Integration
id: publish-integration
shell: bash
run: |
CURRENT_DIR=$(realpath "$PWD")
if [ -n "${{ inputs.PATH_TO_CNI }}" ]; then
TARGET_DIR=$(realpath "${{ inputs.PATH_TO_CNI }}")
else
TARGET_DIR="$CURRENT_DIR"
fi
if [ "$CURRENT_DIR" != "$TARGET_DIR" ]; then
cd "$TARGET_DIR"
fi
COMMAND="prism integrations:publish \"${{ inputs.INTEGRATION_ID }}\""
if [ "${{ inputs.SKIP_COMMIT_HASH_PUBLISH }}" = "false" ]; then
COMMAND="$COMMAND --commitHash=${{ steps.commit-details.outputs.COMMIT_HASH }}"
fi
if [ "${{ inputs.SKIP_COMMIT_URL_PUBLISH }}" = "false" ]; then
COMMAND="$COMMAND --commitUrl=${{ steps.commit-details.outputs.COMMIT_URL }}"
fi
if [ "${{ inputs.SKIP_REPO_URL_PUBLISH }}" = "false" ]; then
COMMAND="$COMMAND --repoUrl=${{ github.repository }}"
fi
if [ "${{ inputs.SKIP_PULL_REQUEST_URL_PUBLISH }}" = "false" ]; then
COMMAND="$COMMAND --pullRequestUrl=${{ steps.pr-details.outputs.PR_URL }}"
fi
if [ -n "${{ inputs.CUSTOMER_ID }}" ]; then
COMMAND="$COMMAND --customer=${{ inputs.CUSTOMER_ID }}"
fi
OUTPUT=$($COMMAND)
echo "PUBLISHED_INTEGRATION_VERSION_ID=${OUTPUT}" >> $GITHUB_OUTPUT
env:
PRISMATIC_URL: ${{ inputs.PRISMATIC_URL }}
PRISM_REFRESH_TOKEN: ${{ inputs.PRISM_REFRESH_TOKEN }}
- name: Make available in marketplace
id: marketplace-available
if: ${{ inputs.MAKE_AVAILABLE_IN_MARKETPLACE == 'true' }}
shell: bash
run: |
set +e
source $GITHUB_WORKSPACE/logger.sh
log $INFO "Updating the marketplace version..."
prism integrations:marketplace "${{ steps.publish-integration.outputs.PUBLISHED_INTEGRATION_VERSION_ID }}" --available --overview="${{ inputs.OVERVIEW }}"
EXIT_CODE=$?
echo "MARKETPLACE_COMMAND_EXIT_CODE=$EXIT_CODE" >> $GITHUB_OUTPUT
env:
PRISMATIC_URL: ${{ inputs.PRISMATIC_URL }}
PRISM_REFRESH_TOKEN: ${{ inputs.PRISM_REFRESH_TOKEN }}
- name: Provide summary of action
shell: bash
run: |
{
echo "### Integration Published :rocket:"
echo "|![Prismatic Logo](https://app.prismatic.io/logo_fullcolor_white.svg)| Publish Info |"
echo "| --------------------- | --------------- |"
echo "| Integration ID | ${{ inputs.INTEGRATION_ID}} |"
echo "| Published Integration Version ID | ${{ steps.publish-integration.outputs.PUBLISHED_INTEGRATION_VERSION_ID }} |"
echo "| Target Stack | ${{ inputs.PRISMATIC_URL }} |"
echo "| Designer Link | ${{ inputs.PRISMATIC_URL }}/designer/${{ inputs.INTEGRATION_ID }} |"
echo "| Commit Link | ${{ steps.commit-details.outputs.COMMIT_URL }} |"
if [ -n "${{ steps.pr-details.outputs.PR_URL }}" ]; then
echo "| PR Link | ${{ steps.pr-details.outputs.PR_URL }} |"
fi
if [ -z "${{ steps.marketplace-available.outputs.MARKETPLACE_COMMAND_EXIT_CODE }}" ] || [ "${{ steps.marketplace-available.outputs.MARKETPLACE_COMMAND_EXIT_CODE }}" -ne 0 ]; then
echo "| Made available in marketplace | ❌ |"
else
echo "| Made available in marketplace | ✅ |"
fi
if [ "${{ inputs.SKIP_COMMIT_HASH_PUBLISH }}" = "false" ]; then
echo "| Commit Hash Published | ✅ |"
else
echo "| Commit Hash Published | ❌ |"
fi
if [ "${{ inputs.SKIP_COMMIT_URL_PUBLISH }}" = "false" ]; then
echo "| Commit Link Published | ✅ |"
else
echo "| Commit Link Published | ❌ |"
fi
if [ "${{ inputs.SKIP_REPO_URL_PUBLISH }}" = "false" ]; then
echo "| Repository Link Published | ✅ |"
else
echo "| Repository Link Published | ❌ |"
fi
if [ "${{ inputs.SKIP_PULL_REQUEST_URL_PUBLISH }}" = "false" ]; then
echo "| PR Link Published | ✅ |"
else
echo "| PR Link Published | ❌ |"
fi
} >> "$GITHUB_STEP_SUMMARY"