forked from wso2/vscode-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (209 loc) · 9.26 KB
/
publish-vsix.yml
File metadata and controls
225 lines (209 loc) · 9.26 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
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
name: Publish VSIX to VSCode Marketplace and OpenVSX
on:
workflow_dispatch:
inputs:
extension:
type: choice
description: 'Select the extension'
required: true
default: 'ballerina'
options:
- 'ballerina'
- 'ballerina-integrator'
- 'choreo'
- 'wso2-platform'
- 'apk'
- 'micro-integrator'
- 'hurl-client'
isPreRelease:
required: true
type: boolean
default: false
vscode:
description: Publish to VSCode marketplace
type: boolean
required: true
default: false
openVSX:
description: Publish to OpenVSX marketplace
type: boolean
required: true
default: false
notify:
description: Notify release on VSCode chat
type: boolean
required: true
default: false
workflowRunId:
required: true
jobs:
publish:
name: Publish vsix to marketplaces
runs-on: codebuild-wso2_vscode-extensions-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.inputs.workflowRunId }}
name: VSIX
- name: Unzip
run: |
unzip VSIX.zip
rm VSIX.zip
- name: Use Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: 20.x
- run: |
npm install -g vsce
npm install -g ovsx
- name: Get version
id: vsix
run: |
file=$(ls ${{ github.event.inputs.extension }}-[0-9]*.[0-9]*.[0-9]*.vsix)
fileName=${file##*-}
version=${fileName%.*}
extension=${{ github.event.inputs.extension }}
extensionName="$(echo "$extension" | sed 's/.*/\u&/')"
echo "vsixName=$file" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
echo "extensionName=$extensionName" >> $GITHUB_OUTPUT
if [ "${{ github.event.inputs.isPreRelease }}" == "true" ]; then
echo "releaseMode=--pre-release" >> $GITHUB_OUTPUT
else
echo "releaseMode= " >> $GITHUB_OUTPUT
fi
- name: Get Repo
id: repo
run: |
if [ "${{ github.event.inputs.extension }}" == "ballerina" ]; then
echo "repo=wso2/ballerina-vscode" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "ballerina-integrator" ]; then
echo "repo=wso2/product-ballerina-integrator" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "choreo" ]; then
echo "repo=wso2/choreo-vscode" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "wso2-platform" ]; then
echo "repo=wso2/vscode-extensions" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "apk" ]; then
echo "repo=wso2/apk-vscode" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "micro-integrator" ]; then
echo "repo=wso2/mi-vscode" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.extension }}" == "hurl-client" ]; then
echo "repo=wso2/vscode-extensions" >> $GITHUB_OUTPUT
fi
- name: Publish to VSCode marketplace
if: ${{ github.event.inputs.vscode == 'true' }}
run: vsce publish -p ${{ secrets.VSCE_TOKEN }} --packagePath ${{ steps.vsix.outputs.vsixName }} ${{ steps.vsix.outputs.releaseMode }}
- name: Publish to OpenVSX marketplace
if: ${{ github.event.inputs.openVSX == 'true' }}
run: ovsx publish -p ${{ secrets.OPENVSX_TOKEN }} --packagePath ${{ steps.vsix.outputs.vsixName }} ${{ steps.vsix.outputs.releaseMode }}
- name: Create a release in ${{ steps.repo.outputs.repo }} repo
id: create_release
if: ${{ steps.repo.outputs.repo != '' && github.event.inputs.isPreRelease == 'false' }}
run: |
id=`curl -X GET -H "Accept: application/vnd.github.v3+json" \
-H "Authorization:token ${{ secrets.CHOREO_BOT_TOKEN }}" \
https://api.github.com/repos/${{ steps.repo.outputs.repo }}/releases/tags/v${{ steps.vsix.outputs.version }} \
| jq -r .id` && \
updateResponse=`curl -X PATCH -H "Accept: application/vnd.github.v3+json" \
-H "Authorization:token ${{ secrets.CHOREO_BOT_TOKEN }}" \
-d '{"draft":false,"prerelease":false}' \
https://api.github.com/repos/wso2/${{ steps.repo.outputs.repo }}/releases/$id`
# Verify the release was created/updated successfully
if [ $? -eq 0 ]; then
echo "release_created=true" >> $GITHUB_OUTPUT
echo "Release successfully created/updated for version v${{ steps.vsix.outputs.version }}"
else
echo "release_created=false" >> $GITHUB_OUTPUT
echo "Failed to create/update release for version v${{ steps.vsix.outputs.version }}"
exit 1
fi
- name: Trigger external repo workflow for ballerina release
if: ${{ github.event.inputs.extension == 'ballerina' && github.event.inputs.isPreRelease == 'false' && steps.create_release.outputs.release_created == 'true' }}
run: |
echo "Triggering external repository workflow for ballerina v${{ steps.vsix.outputs.version }}"
response=$(curl -s -w "%{http_code}" -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.CLOUD_EDITOR_BUILDER_REPO_TOKEN }}" \
https://api.github.com/repos/${{ secrets.CLOUD_EDITOR_BUILDER_REPO }}/dispatches \
-d '{"event_type": "extension_published", "client_payload": {"extension": "${{ github.event.inputs.extension }}", "version": "${{ steps.vsix.outputs.version }}", "release_url": "https://github.com/wso2/${{ steps.repo.outputs.repo }}/releases/tag/v${{ steps.vsix.outputs.version }}"}}')
http_code=$(echo "$response" | tail -c 4)
if [ "$http_code" -eq 204 ]; then
echo "Successfully triggered external repository workflow"
else
echo "Failed to trigger external repository workflow. HTTP code: $http_code"
echo "Response: $response"
exit 1
fi
- name: Set Chat API
id: chat
run: |
if [ "${{ inputs.extension }}" == "micro-integrator" ]; then
echo "chatAPI=${{ secrets.MI_TEAM_CHAT_API }}" >> $GITHUB_OUTPUT
elif [ "${{ inputs.extension }}" == "ballerina" ] || [ "${{ inputs.extension }}" == "ballerina-integrator" ]; then
echo "chatAPI=${{ secrets.BI_TEAM_CHAT_API }}" >> $GITHUB_OUTPUT
else
echo "chatAPI=${{ secrets.TOOLING_TEAM_CHAT_API }}" >> $GITHUB_OUTPUT
fi
- name: "Release Notification"
if: ${{ github.event.inputs.notify == 'true' }}
run: |
body=$(cat << EOF
{
"cards": [
{
"header": {
"title": "Marketplace Release",
"subtitle": "${{ steps.vsix.outputs.extensionName }} Extension"
},
"sections": [
{
"widgets": [
{
"keyValue": {
"topLabel": "VSCode Marketplace",
"content": "v${{ steps.vsix.outputs.version }}",
"iconUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Visual_Studio_Code_1.35_icon.svg/512px-Visual_Studio_Code_1.35_icon.svg.png",
"button": {
"textButton": {
"text": "View",
"onClick": {
"openLink": {
"url": "https://marketplace.visualstudio.com/items?itemName=WSO2.${{ github.event.inputs.extension }}"
}
}
}
}
}
},
{
"keyValue": {
"topLabel": "OpenVSX Marketplace",
"content": "v${{ steps.vsix.outputs.version }}",
"iconUrl": "https://projects.eclipse.org/sites/default/files/open-vsx-logo-withouttext.png",
"button": {
"textButton": {
"text": "View",
"onClick": {
"openLink": {
"url": "https://open-vsx.org/extension/wso2/${{ github.event.inputs.extension }}"
}
}
}
}
}
}
]
}
]
}
]
}
EOF
)
curl \
-X POST \
-H 'Content-Type: application/json' \
"${{ steps.chat.outputs.chatAPI }}" \
-d "$body"