Skip to content

Commit ef0c990

Browse files
committed
Add prerelease CI derived from the one on vscode-objectscript
1 parent 373627e commit ef0c990

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