-
-
Notifications
You must be signed in to change notification settings - Fork 52
139 lines (135 loc) · 5.7 KB
/
CD.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
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
131
132
133
134
135
136
137
138
139
name: CD
on:
push:
branches:
- master
jobs:
unit-test:
name: Test
runs-on: ${{ matrix.config.os }} # we run many different builds
strategy:
matrix:
config:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
steps:
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- run: yarn
- run: yarn format-check
- run: yarn test-compile
- run: yarn compile
# https://github.com/GabrielBB/xvfb-action
- name: Run headless test
uses: GabrielBB/xvfb-action@v1
with:
run: yarn test
release:
name: release
runs-on: ubuntu-latest
needs: unit-test
steps:
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: read version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$PACKAGE_VERSION"
PUBLISHED_VERSION=$(curl 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \
-H 'origin: https://marketplace.visualstudio.com' \
-H 'pragma: no-cache' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36' \
-H 'content-type: application/json' \
-H 'accept: application/json;api-version=5.1-preview.1;excludeUrls=true' \
-H 'cache-control: no-cache' \-H 'authority: marketplace.visualstudio.com' \
-H 'referer: https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format' \
--data-binary '{"assetTypes":null,"filters":[{"criteria":[{"filterType":7,"value":"foxundermoon.shell-format"}],"direction":2,"pageSize":1,"pageNumber":1,"sortBy":0,"sortOrder":0,"pagingToken":null}],"flags":71}' |
jq '.results[0].extensions[0].versions[0].version')
echo "PUBLISHED_VERSION=$PUBLISHED_VERSION"
if [ "$PACKAGE_VERSION" = "$PUBLISHED_VERSION" ]; then
echo 'niddend published'
echo "NEED_RELEASE=no" >> $GITHUB_ENV
else
echo "need publish"
echo "NEED_RELEASE=yes" >> $GITHUB_ENV
fi
- run: yarn
if: env.NEED_RELEASE == 'yes'
- name: mini changelog
if: env.NEED_RELEASE == 'yes'
id: minichangelog
run: |
VERSION_REGEX="## $(echo ${{ env.PACKAGE_VERSION }} | sed 's/\./\\./g')"
sed -n "/$VERSION_REGEX/,/## /p" CHANGELOG.md | sed '$d' > minichangelog.txt
cat minichangelog.txt
# echo "::set-output name=minichangelog::$(cat minichangelog.txt)
echo "MINI_CHANGELOG<<EOF" >> $GITHUB_ENV
cat minichangelog.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: check changelog
if: env.NEED_RELEASE == 'yes'
run: |
LINE_COUNT=$(cat minichangelog.txt | wc -l)
if [ "$LINE_COUNT" -lt 3 ]; then
echo Mini changelog is too short. Did you use the wrong version number in CHANGELOG.txt?
exit 1
fi
- name: package
if: env.NEED_RELEASE == 'yes'
run: |
yarn package
echo FILE_NAME=$(node -p "require('./package.json').name")-${{ env.PACKAGE_VERSION }}.vsix >> $GITHUB_ENV
- name: create github release
if: env.NEED_RELEASE == 'yes'
id: create_release
uses: actions/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ env.PACKAGE_VERSION }}
release_name: Release ${{ env.PACKAGE_VERSION }}
body: |
${{ env.MINI_CHANGELOG }}
draft: false
prerelease: false
- name: Upload Release Asset
if: env.NEED_RELEASE == 'yes'
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ env.FILE_NAME }}
asset_name: ${{ env.FILE_NAME }}
asset_content_type: application/gzip
- name: Vscode release plugin
if: env.NEED_RELEASE == 'yes'
run: |
yarn vsce publish -p ${{ secrets.PUBLISHER_TOKEN }}