This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
97 lines (81 loc) · 3.13 KB
/
release.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
# https://github.com/golang/vscode-go/blob/master/.github/workflows/release.yml
# Create Release in Github release page:
# create Pre-Release when tag pushed in format: 'vX.X.X-rc.X'
# create Official-Release when tag pushed in format: 'vX.X.X'
# Upload .vsix file as asset of the release
# Publish Official-Release to Visual Studio Code Marketplace
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
name: Create release
runs-on: ubuntu-latest
if: github.repository == 'useblocks/sphinx-needs-vscode'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 16
- name: Check and get release version
run: |
TAGGED_VERSION="${GITHUB_REF/refs\/tags\/v/}"
if [[ ! "${TAGGED_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "Invalid version tag '${TAGGED_VERSION}'"
exit 1
fi
echo "EXT_VERSION=${TAGGED_VERSION}" >> $GITHUB_ENV
WRITTEN_VERSION="$(cat package.json | jq '.version' -r)"
if [[ "${TAGGED_VERSION}" == *"-"* ]]; then
if [[ ! "${TAGGED_VERSION}" == "${WRITTEN_VERSION}"-rc.* ]]; then
echo "Prerelease Tag and Version in package.json are not compatible: '${TAGGED_VERSION}' vs '${WRITTEN_VERSION}'"
exit 1
fi
echo "EXT_ISPRERELEASE=1" >> $GITHUB_ENV
else
if [[ "${TAGGED_VERSION}" != "${WRITTEN_VERSION}" ]]; then
echo "Release Tag and Version written in package.json do not match: '${TAGGED_VERSION}' vs '${WRITTEN_VERSION}'"
exit 1
fi
echo "EXT_ISPRERELEASE=0" >> $GITHUB_ENV
fi
- name: Stamp version
run: |
cat package.json | jq --arg VER "${{ env.EXT_VERSION }}" '.version=$VER' > /tmp/package.json
cp /tmp/package.json ./package.json
npm ci
npm run vscode:prepublish
- name: Package
uses: lannonbr/[email protected]
with:
args: "package"
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ env.EXT_VERSION }}
draft: false
prerelease: ${{env.EXT_ISPRERELEASE == 1}}
- name: Upload release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sphinx-needs-vscode-${{ env.EXT_VERSION }}.vsix
asset_name: sphinx-needs-vscode-${{ env.EXT_VERSION }}.vsix
asset_content_type: application/zip
- name: Publish to VSCode Marketplace
if: env.EXT_ISPRERELEASE != 1 && github.repository == 'useblocks/sphinx-needs-vscode'
uses: lannonbr/[email protected]
with:
args: "publish -p $VSCE_TOKEN"
env:
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}