Skip to content

Commit 241ffdb

Browse files
Merge pull request #839 from gjsjohnmurray/pre-CI-for-prerelease-branch
Add CI for prerelease branch
2 parents eee6456 + 5231d3d commit 241ffdb

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

.github/workflows/prerelease.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: CI-prerelease
2+
3+
on:
4+
push:
5+
branches:
6+
- prerelease
7+
paths-ignore:
8+
- "docs/**"
9+
- ".vscode/**"
10+
- ".github/**"
11+
- "*.md"
12+
- "**/*.md"
13+
pull_request:
14+
branches:
15+
- prerelease
16+
release:
17+
branches:
18+
- prerelease
19+
types:
20+
- released
21+
jobs:
22+
build:
23+
timeout-minutes: 10
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
matrix:
27+
os: [ubuntu-latest, windows-latest, macOS-latest]
28+
steps:
29+
- uses: actions/checkout@v2
30+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
31+
- name: Set an output
32+
id: set-version
33+
if: runner.os == 'Linux'
34+
run: |
35+
set -x
36+
VERSION=$(jq -r '.version' package.json | cut -d- -f1)
37+
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
38+
CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d')
39+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
40+
echo ::set-output name=changelog::$CHANGELOG
41+
git tag -l | cat
42+
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1))
43+
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev.${{ github.event.pull_request.number }}
44+
echo ::set-output name=version::$VERSION
45+
NAME=$(jq -r '.name' package.json)-$VERSION
46+
echo ::set-output name=name::$NAME
47+
tmp=$(mktemp)
48+
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
49+
mkdir dist
50+
echo $VERSION > .version
51+
echo $NAME > .name
52+
- name: Use Node.js
53+
uses: actions/setup-node@v1
54+
with:
55+
node-version: 14.x
56+
- run: npm install
57+
- name: lint
58+
if: runner.os == 'Linux'
59+
run: npm run lint
60+
- run: npm run compile
61+
- name: npm test
62+
uses: GabrielBB/[email protected]
63+
with:
64+
run: npm run test
65+
- name: Build pre-release package
66+
if: runner.os == 'Linux'
67+
run: |
68+
npx vsce package --pre-release -o ${{ steps.set-version.outputs.name }}.vsix
69+
- uses: actions/upload-artifact@v2
70+
if: runner.os == 'Linux'
71+
with:
72+
name: ${{ steps.set-version.outputs.name }}.vsix
73+
path: ${{ steps.set-version.outputs.name }}.vsix
74+
- uses: actions/upload-artifact@v2
75+
if: runner.os == 'Linux'
76+
with:
77+
name: meta
78+
path: |
79+
.name
80+
.version
81+
beta:
82+
if: (github.event_name == 'push')
83+
runs-on: ubuntu-latest
84+
needs: build
85+
steps:
86+
- uses: actions/download-artifact@v2
87+
with:
88+
name: meta
89+
path: .
90+
- name: Set an output
91+
id: set-version
92+
if: runner.os == 'Linux'
93+
run: |
94+
set -x
95+
echo ::set-output name=version::`cat .version`
96+
echo ::set-output name=name::`cat .name`
97+
- uses: actions/download-artifact@v2
98+
with:
99+
name: ${{ steps.set-version.outputs.name }}.vsix
100+
- name: Create Pre-Release
101+
id: create_release
102+
uses: actions/create-release@v1
103+
if: runner.os == 'Linux'
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
with:
107+
tag_name: v${{ steps.set-version.outputs.version }}
108+
release_name: v${{ steps.set-version.outputs.version }}
109+
prerelease: ${{ github.event_name != 'release' }}
110+
body: |
111+
Changes in this pre-release
112+
${{ steps.set-version.outputs.changelog }}
113+
- name: Upload Pre-Release Asset
114+
id: upload-release-asset
115+
uses: actions/upload-release-asset@v1
116+
if: runner.os == 'Linux'
117+
env:
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
with:
120+
upload_url: ${{ steps.create_release.outputs.upload_url }}
121+
asset_path: ${{ steps.set-version.outputs.name }}.vsix
122+
asset_name: ${{ steps.set-version.outputs.name }}.vsix
123+
asset_content_type: application/zip
124+
publish:
125+
if: github.event_name == 'release'
126+
runs-on: ubuntu-latest
127+
needs: build
128+
steps:
129+
- uses: actions/checkout@v2
130+
with:
131+
ref: prerelease
132+
token: ${{ secrets.TOKEN }}
133+
- uses: actions/download-artifact@v2
134+
with:
135+
name: meta
136+
path: .
137+
- name: Use Node.js
138+
uses: actions/setup-node@v1
139+
with:
140+
node-version: 14.x
141+
- name: Prepare pre-release build
142+
id: set-version
143+
run: |
144+
VERSION=`cat .version`
145+
NEXT_VERSION=`cat .version | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
146+
echo ::set-output name=name::`cat .name`
147+
tmp=$(mktemp)
148+
git config --global user.name 'ProjectBot'
149+
git config --global user.email '[email protected]'
150+
jq --arg version "${NEXT_VERSION}-SNAPSHOT" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
151+
git add package.json
152+
git commit -m 'auto bump version after pre-release'
153+
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
154+
npm install
155+
jq 'del(.enableProposedApi,.enabledApiProposals)' package.json > "$tmp" && mv "$tmp" package.json
156+
git push
157+
- name: Build pre-release package
158+
run: |
159+
npx vsce package --pre-release -o ${{ steps.set-version.outputs.name }}.vsix
160+
- name: Upload Release Asset
161+
id: upload-release-asset
162+
uses: actions/upload-release-asset@v1
163+
if: runner.os == 'Linux'
164+
env:
165+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
166+
with:
167+
upload_url: ${{ github.event.release.upload_url }}
168+
asset_path: ${{ steps.set-version.outputs.name }}.vsix
169+
asset_name: ${{ steps.set-version.outputs.name }}.vsix
170+
asset_content_type: application/zip
171+
- name: Publish to VSCode Marketplace
172+
run: |
173+
[ -n "${{ secrets.VSCE_TOKEN }}" ] && \
174+
npx vsce publish --pre-release --packagePath ${{ steps.set-version.outputs.name }}.vsix -p ${{ secrets.VSCE_TOKEN }} || true

0 commit comments

Comments
 (0)