-
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (122 loc) · 5.91 KB
/
release.yml
File metadata and controls
130 lines (122 loc) · 5.91 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
name: Build & Publish Extension
on:
push:
branches: ["main", "master"]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
name: Build and package
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: |
npm install -g @vscode/vsce
yarn install --frozen-lockfile
- name: Get NPM Version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1
- name: Run Tests
run: xvfb-run -a yarn test
- name: Check if version exists
id: check-version
env:
VERSION: ${{ steps.package-version.outputs.current-version }}
run: |
echo "Checking version $VERSION..."
# Check VS Marketplace
VS_Response=$(curl -s --location 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \
--header 'Accept: application/json; api-version=7.2-preview.1' \
--header 'Content-Type: application/json' \
--data '{
"filters": [
{
"criteria": [
{
"filterType": 7,
"value": "ahnafnafee.postscript-preview"
}
]
}
],
"flags": 915
}')
# Check if version exists (robust jq boolean)
if echo "$VS_Response" | jq -e --arg v "$VERSION" '.results[0].extensions[0].versions | map(select(.version == $v)) | length > 0' > /dev/null; then
echo "Version $VERSION already exists in VS Marketplace."
echo "VS_EXISTS=true" >> $GITHUB_ENV
else
echo "Version $VERSION not found in VS Marketplace."
echo "VS_EXISTS=false" >> $GITHUB_ENV
fi
# Check Open VSX
OVSX_Status=$(curl -o /dev/null -s -w "%{http_code}" https://open-vsx.org/api/ahnafnafee/postscript-preview/$VERSION)
if [ "$OVSX_Status" = "200" ]; then
echo "Version $VERSION already exists in Open VSX."
echo "OVSX_EXISTS=true" >> $GITHUB_ENV
else
echo "Version $VERSION not found in Open VSX."
echo "OVSX_EXISTS=false" >> $GITHUB_ENV
fi
- name: Validate Version Status
run: |
if [ "$VS_EXISTS" = "true" ] && [ "$OVSX_EXISTS" = "true" ]; then
echo "::warning::Version $VERSION is already published to both VS Marketplace and Open VSX. Skipping publish."
echo "Please bump the version in package.json to release a new version."
fi
- name: Build extension
if: env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false'
run: vsce package -o postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix
- name: Upload a Build Artifact
if: env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false'
uses: actions/upload-artifact@v4
with:
name: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix
path: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix
if-no-files-found: error
- name: Extract Changelog
if: (env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false') && success()
run: |
awk -v v="[${{ steps.package-version.outputs.current-version }}]" '
/^## / {
if (index($0, v)) {
p=1
next
} else {
p=0
}
}
p { print }
' CHANGELOG.md > RELEASE_BODY.md
- name: Create release with artifact
if: (env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false') && success()
uses: softprops/action-gh-release@v2.0.8
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
with:
name: Release v${{ steps.package-version.outputs.current-version }}
tag_name: v${{ steps.package-version.outputs.current-version }}
draft: false
body_path: RELEASE_BODY.md
files: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix
- name: Publish to Open VSX Registry
if: env.OVSX_EXISTS == 'false'
uses: HaaLeo/publish-vscode-extension@v1
with:
pat: ${{ secrets.OPEN_VSX_TOKEN }}
extensionFile: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix
- name: Publish to Visual Studio Marketplace
if: env.VS_EXISTS == 'false'
uses: HaaLeo/publish-vscode-extension@v1
with:
pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
registryUrl: https://marketplace.visualstudio.com
extensionFile: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix