Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to github action CI & CD #239

Merged
merged 12 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
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)

- 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
- 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: |
${{ steps.minichangelog.outputs.minichangelog }}
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
uses: JCofman/vscodeaction@master
if: env.NEED_RELEASE == 'yes'
env:
PUBLISHER_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
with:
args: publish -p $PUBLISHER_TOKEN
46 changes: 46 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI
on:
push:
paths-ignore:
- CHANGELOG.md
- README.md
pull_request:
paths-ignore:
- CHANGELOG.md
- README.md

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
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged
Loading