Skip to content

Commit c48db4d

Browse files
committed
a bit clever github actions
1 parent e05bcac commit c48db4d

File tree

1 file changed

+82
-10
lines changed

1 file changed

+82
-10
lines changed

.github/workflows/main.yml

+82-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
name: CI
22

3-
on: [push,release]
4-
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '*.md'
9+
- '**/*.md'
10+
pull_request:
11+
branches:
12+
- master
13+
release:
14+
types:
15+
- created
516
jobs:
617
build:
718
runs-on: ${{ matrix.os }}
@@ -17,16 +28,21 @@ jobs:
1728
run: |
1829
set -x
1930
VERSION=$(jq -r '.version' package.json | cut -d- -f1)
31+
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
2032
CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d')
2133
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
2234
echo ::set-output name=changelog::$CHANGELOG
23-
VERSION+=-beta
2435
git tag -l | cat
25-
VERSION+=.$(($(git tag -l "v$VERSION.*" 2>/dev/null | tail -1 | cut -d. -f4)+1))
36+
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" 2>/dev/null | tail -1 | cut -d. -f4)+1))
37+
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev
2638
echo ::set-output name=version::$VERSION
27-
echo ::set-output name=name::$(jq -r '.name' package.json)-$VERSION
39+
NAME=$(jq -r '.name' package.json)-$VERSION
40+
echo ::set-output name=name::$NAME
2841
tmp=$(mktemp)
2942
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
43+
mkdir dist
44+
echo $VERSION > ./dist/.version
45+
echo $NAME > ./dist/.name
3046
- name: Use Node.js
3147
uses: actions/setup-node@master
3248
with:
@@ -40,8 +56,28 @@ jobs:
4056
- name: Build package
4157
if: runner.os == 'Linux'
4258
run: |
43-
mkdir dist
44-
./node_modules/.bin/vsce package -o ./dist/vscode-objectscript.vsix
59+
./node_modules/.bin/vsce package -o ./dist/package.vsix
60+
- uses: actions/upload-artifact@master
61+
if: runner.os == 'Linux'
62+
with:
63+
name: vsix
64+
path: ./dist/
65+
beta:
66+
if: (github.event_name == 'push')
67+
runs-on: ubuntu-latest
68+
needs: build
69+
steps:
70+
- uses: actions/download-artifact@master
71+
with:
72+
name: vsix
73+
path: ./dist/
74+
- name: Set an output
75+
id: set-version
76+
if: runner.os == 'Linux'
77+
run: |
78+
set -x
79+
echo ::set-output name=version::`cat ./dist/.version`
80+
echo ::set-output name=name::`cat ./dist/.name`
4581
- name: Create Release
4682
id: create_release
4783
uses: actions/create-release@master
@@ -51,8 +87,7 @@ jobs:
5187
with:
5288
tag_name: v${{ steps.set-version.outputs.version }}
5389
release_name: v${{ steps.set-version.outputs.version }}
54-
draft: false
55-
prerelease: true
90+
prerelease: ${{ github.event_name != 'release' }}
5691
body: |
5792
Changes in this release
5893
${{ steps.set-version.outputs.changelog }}
@@ -64,6 +99,43 @@ jobs:
6499
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65100
with:
66101
upload_url: ${{ steps.create_release.outputs.upload_url }}
67-
asset_path: ./dist/vscode-objectscript.vsix
102+
asset_path: ./dist/package.vsix
103+
asset_name: ${{ steps.set-version.outputs.name }}.vsix
104+
asset_content_type: application/zip
105+
publish:
106+
if: github.event_name == 'release'
107+
runs-on: ubuntu-latest
108+
needs: build
109+
steps:
110+
- uses: actions/checkout@master
111+
- uses: actions/download-artifact@master
112+
with:
113+
name: vsix
114+
path: ./dist/
115+
- name: Use Node.js
116+
uses: actions/setup-node@master
117+
with:
118+
node-version: 12.x
119+
- name: Prepare build
120+
id: set-version
121+
run: |
122+
VERSION=`cat ./dist/.version`
123+
echo ::set-output name=name::`cat ./dist/.name`
124+
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
125+
jq '.enableProposedApi = false' package.json > "$tmp" && mv "$tmp" package.json
126+
npm install
127+
npm i -g vsce
128+
- name: Upload Release Asset
129+
id: upload-release-asset
130+
uses: actions/upload-release-asset@master
131+
if: runner.os == 'Linux'
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
with:
135+
upload_url: ${{ github.event.release.upload_url }}
136+
asset_path: ./dist/package.vsix
68137
asset_name: ${{ steps.set-version.outputs.name }}.vsix
69138
asset_content_type: application/zip
139+
- name: Publish to Marketplace
140+
run: vsce publish -p ${{ secrets.VSCE_TOKEN }}
141+

0 commit comments

Comments
 (0)