-
Notifications
You must be signed in to change notification settings - Fork 5.3k
254 lines (251 loc) · 12.1 KB
/
publish-components.yaml
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
on:
push:
branches:
- master
paths:
- 'components/**'
jobs:
publish-components:
name: Publish Components to Pipedream Registry
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- uses: pnpm/[email protected]
with:
version: 9.14.2
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install -r --no-frozen-lockfile
- name: Setup Node Env
uses: actions/[email protected]
with:
node-version: 18
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
- name: Compile TypeScript
run: pnpm run build
- name: Install pd cli
env:
PD_API_KEY: ${{ secrets.PD_API_KEY }}
PD_ORG_ID: ${{ secrets.PD_ORG_ID }}
run: |
curl -O https://cli.pipedream.com/linux/amd64/latest/pd.zip
unzip pd.zip
mkdir -p $HOME/.config/pipedream
echo "api_key = $PD_API_KEY" > $HOME/.config/pipedream/config
echo "org_id = $PD_ORG_ID" >> $HOME/.config/pipedream/config
- name: Get Changed Files
id: files
uses: Ana06/[email protected]
with:
format: 'csv'
- name: Publish and add to registry components/*.*js (that aren't .app.js files)
id: publish
env:
PD_API_KEY: ${{ secrets.PD_API_KEY }}
PD_ORG_ID: ${{ secrets.PD_ORG_ID }}
ENDPOINT: ${{ secrets.ENDPOINT }}
shell: bash {0} # don't fast fail
run: |
PD_URL=https://api.pipedream.com/v1/components/registry
UNPUBLISHED=""
PUBLISHED=""
ERRORS=""
SKIPPED=""
# Ana06/[email protected] treats renamed files that are modified as modified. We shouldn't be renaming files without modification.
mapfile -d ',' -t added_modified_files < <(printf '%s' '${{ steps.files.outputs.added_modified }}')
for added_modified_file in "${added_modified_files[@]}";
do
# starts with components, ends with .*js (e.g. .js and .mjs) and not app.js,
# doesn't end with /common*.*js, and doesn't follow */common/
if [[ $added_modified_file == components/* ]] && [[ $added_modified_file == *.*js ]] && [[ $added_modified_file != *.app.*js ]] \
&& [[ $added_modified_file != */common*.*js ]] && [[ $added_modified_file != */common/* ]] && [[ $added_modified_file != components/*/test-event.mjs ]]
then
echo "retrieving previous version for ${added_modified_file}"
KEY=`echo $added_modified_file | tr '/' ' ' | awk '{ print $2 "-" $4 }'`
GLOBAL_REGISTRY_COMP=`curl --silent "$PD_URL/$KEY" -H "Authorization: Bearer $PD_API_KEY" -H "Accept: application/json"`
PREV_VERSION=`echo $GLOBAL_REGISTRY_COMP | jq -r ".data.version"`
echo "attempting to publish ${added_modified_file}"
PD_OUTPUT=`./pd publish ${added_modified_file} --json`
if [ $? -eq 0 ]
then
KEY=`echo $PD_OUTPUT | jq -r ".key"`
echo "published ${KEY}"
echo "${KEY} will be added to the registry"
curl "https://api.pipedream.com/graphql" -H "Content-Type: application/json" -H "Authorization: Bearer ${PD_API_KEY}" --data-binary $'{"query":"mutation setComponentRegistry($key: String!, $registry: Boolean!, $gitPath: String, $orgId: String){\\n setComponentRegistry(key: $key, registry: $registry, gitPath: $gitPath, orgId: $orgId){\\n savedComponent{\\n id\\n key\\n gitPath\\n }\\n }\\n}","variables":{"key":"'${KEY}'","registry":'true',"gitPath":"'${added_modified_file}'","orgId":"'${PD_ORG_ID}'"}}'
[[ "$PREV_VERSION" == "null" ]] && PUBLISHED+="*${added_modified_file}" || PUBLISHED+="*${added_modified_file}~$PREV_VERSION"
else
ERROR=`echo $PD_OUTPUT | jq -r ".error" || $PD_OUTPUT`
ERROR_MESSAGE="${ERROR} with ${added_modified_file}"
echo $ERROR_MESSAGE
ERRORS+="*${ERROR_MESSAGE}"
UNPUBLISHED+="*${added_modified_file}"
# add to array to spit out later
fi
else
echo "${added_modified_file} will not be added to the registry"
SKIPPED+="*${added_modified_file}"
fi
done
# print out everything that didn't publish
if [ ${#UNPUBLISHED[@]} -ne 0 ]; then
echo "the following files were not published"
printf '%s\n' "${UNPUBLISHED[@]}"
fi
# curl with form
curl -X POST -d "type=javascript" --data-urlencode event@$GITHUB_EVENT_PATH -d "github=$(printenv | grep "GITHUB_*")" -d "skipped=${SKIPPED}" -d "errors=${ERRORS}" -d "unpublished=${UNPUBLISHED}" -d "published=${PUBLISHED}" $ENDPOINT
if [ -n "$ERRORS" ]; then
exit 1
fi
- name: Remove pd cli config
run: |
rm $HOME/.config/pipedream/config
publish-typescript-components:
name: Publish TypeScript components
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- uses: pnpm/[email protected]
with:
version: 9.14.2
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup Node Env
uses: actions/[email protected]
with:
node-version: 18
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
- name: Install Dependencies
run: pnpm install -r --no-frozen-lockfile
- name: Install pd cli
env:
PD_API_KEY: ${{ secrets.PD_API_KEY }}
PD_ORG_ID: ${{ secrets.PD_ORG_ID }}
run: |
curl -O https://cli.pipedream.com/linux/amd64/latest/pd.zip
unzip pd.zip
mkdir -p $HOME/.config/pipedream
echo "api_key = $PD_API_KEY" > $HOME/.config/pipedream/config
echo "org_id = $PD_ORG_ID" >> $HOME/.config/pipedream/config
- name: Compile TypeScript
id: compile
run: pnpm run build > files.txt
- name: Get Changed Files
id: files
uses: Ana06/[email protected]
with:
format: 'csv'
- name: Publish TypeScript components (dry run)
env:
PD_API_KEY: ${{ secrets.PD_API_KEY }}
PD_ORG_ID: ${{ secrets.PD_ORG_ID }}
ENDPOINT: ${{ secrets.ENDPOINT }}
shell: bash {0} # don't fast fail
run: |
IFS=$'\n'
echo "The following files will be published on merge:"
# Remove initial tsc output
output_files=$(cat files.txt | sed 1,3d)
for f in $output_files
do
echo "$f"
done
PD_URL=https://api.pipedream.com/v1/components/registry
UNPUBLISHED=""
PUBLISHED=""
ERRORS=""
SKIPPED=""
# Ana06/[email protected] treats renamed files that are modified as modified. We shouldn't be renaming files without modification.
mapfile -d ',' -t added_modified_files < <(printf '%s' '${{ steps.files.outputs.added_modified }}')
# included in the components dir, ends with .ts and not app.ts,
# doesn't end with /common*.ts, and doesn't follow */common/
for added_modified_file in "${added_modified_files[@]}";
do
echo "Checking if $added_modified_file is a publishable ts file"
if [[ $added_modified_file == components/* ]] && [[ $added_modified_file == *.ts ]] && [[ $added_modified_file != *.app.ts ]] \
&& [[ $added_modified_file != */common*.ts ]] && [[ $added_modified_file != */common/* ]]
then
# XXX This is a hacky way to publish only TS components with changes. If a changed
# file "path-a/path-b/c.ts" has a corresponding compiled output file
# "path-a/dist/path-b/c.mjs", attempt to publish the output `.mjs` file.
changed_output_file=""
for f in $output_files; # check each output file for a match
do
# Replaces /dist/path/filename.mjs with /path/filename.ts
maybe_source_file=$(echo "$f" | sed 's/\/dist\//\//;s/.mjs/\.ts/')
if [[ ${maybe_source_file} == **/${added_modified_file} ]]
then
changed_output_file=${f}
break
fi
done
if [[ $changed_output_file == "" ]]
then
ERROR_MESSAGE="cannot find an output .mjs file with ${added_modified_file}"
echo $ERROR_MESSAGE
ERRORS+="*${ERROR_MESSAGE}"
UNPUBLISHED+="*${added_modified_file}"
else
echo "retrieving previous version for ${added_modified_file}"
KEY=`echo $added_modified_file | tr '/' ' ' | awk '{ print $2 "-" $4 }'`
GLOBAL_REGISTRY_COMP=`curl --silent "$PD_URL/$KEY" -H "Authorization: Bearer $PD_API_KEY" -H "Accept: application/json"`
PREV_VERSION=`echo $GLOBAL_REGISTRY_COMP | jq -r ".data.version"`
echo "attempting to publish ${changed_output_file}"
PD_OUTPUT=`./pd publish ${changed_output_file} --json`
if [ $? -eq 0 ]
then
KEY=`echo $PD_OUTPUT | jq -r ".key"`
echo "published ${KEY}"
echo "${KEY} will be added to the registry"
curl "https://api.pipedream.com/graphql" -H "Content-Type: application/json" -H "Authorization: Bearer ${PD_API_KEY}" --data-binary $'{"query":"mutation setComponentRegistry($key: String!, $registry: Boolean!, $gitPath: String, $orgId: String){\\n setComponentRegistry(key: $key, registry: $registry, gitPath: $gitPath, orgId: $orgId){\\n savedComponent{\\n id\\n key\\n gitPath\\n }\\n }\\n}","variables":{"key":"'${KEY}'","registry":'true',"gitPath":"'${added_modified_file}'","orgId":"'${PD_ORG_ID}'"}}'
[[ "$PREV_VERSION" == "null" ]] && PUBLISHED+="*${changed_output_file}" || PUBLISHED+="*${changed_output_file}~$PREV_VERSION"
else
ERROR=`echo $PD_OUTPUT | jq -r ".error"`
ERROR_MESSAGE="${ERROR} with ${changed_output_file}"
echo $ERROR_MESSAGE
ERRORS+="*${ERROR_MESSAGE}"
UNPUBLISHED+="*${changed_output_file}"
# add to array to spit out later
fi
fi
else
echo "${added_modified_file} will not be added to the registry"
SKIPPED+="*${added_modified_file}"
fi
done
# print out everything that didn't publish
if [ ${#UNPUBLISHED[@]} -ne 0 ]; then
echo "the following files were not published"
printf '%s\n' "${UNPUBLISHED[@]}"
fi
# curl with form
curl -X POST -d "type=typescript" --data-urlencode event@$GITHUB_EVENT_PATH -d "github=$(printenv | grep "GITHUB_*")" -d "skipped=${SKIPPED}" -d "errors=${ERRORS}" -d "unpublished=${UNPUBLISHED}" -d "published=${PUBLISHED}" $ENDPOINT
if [ -n "$ERRORS" ]; then
exit 1
fi
unset IFS
- name: Remove pd cli config
run: |
rm $HOME/.config/pipedream/config