Skip to content

Commit

Permalink
a bit clever github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Apr 20, 2020
1 parent e05bcac commit c48db4d
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: CI

on: [push,release]

on:
push:
branches:
- master
paths-ignore:
- '*.md'
- '**/*.md'
pull_request:
branches:
- master
release:
types:
- created
jobs:
build:
runs-on: ${{ matrix.os }}
Expand All @@ -17,16 +28,21 @@ jobs:
run: |
set -x
VERSION=$(jq -r '.version' package.json | cut -d- -f1)
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d')
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
echo ::set-output name=changelog::$CHANGELOG
VERSION+=-beta
git tag -l | cat
VERSION+=.$(($(git tag -l "v$VERSION.*" 2>/dev/null | tail -1 | cut -d. -f4)+1))
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" 2>/dev/null | tail -1 | cut -d. -f4)+1))
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev
echo ::set-output name=version::$VERSION
echo ::set-output name=name::$(jq -r '.name' package.json)-$VERSION
NAME=$(jq -r '.name' package.json)-$VERSION
echo ::set-output name=name::$NAME
tmp=$(mktemp)
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
mkdir dist
echo $VERSION > ./dist/.version
echo $NAME > ./dist/.name
- name: Use Node.js
uses: actions/setup-node@master
with:
Expand All @@ -40,8 +56,28 @@ jobs:
- name: Build package
if: runner.os == 'Linux'
run: |
mkdir dist
./node_modules/.bin/vsce package -o ./dist/vscode-objectscript.vsix
./node_modules/.bin/vsce package -o ./dist/package.vsix
- uses: actions/upload-artifact@master
if: runner.os == 'Linux'
with:
name: vsix
path: ./dist/
beta:
if: (github.event_name == 'push')
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@master
with:
name: vsix
path: ./dist/
- name: Set an output
id: set-version
if: runner.os == 'Linux'
run: |
set -x
echo ::set-output name=version::`cat ./dist/.version`
echo ::set-output name=name::`cat ./dist/.name`
- name: Create Release
id: create_release
uses: actions/create-release@master
Expand All @@ -51,8 +87,7 @@ jobs:
with:
tag_name: v${{ steps.set-version.outputs.version }}
release_name: v${{ steps.set-version.outputs.version }}
draft: false
prerelease: true
prerelease: ${{ github.event_name != 'release' }}
body: |
Changes in this release
${{ steps.set-version.outputs.changelog }}
Expand All @@ -64,6 +99,43 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/vscode-objectscript.vsix
asset_path: ./dist/package.vsix
asset_name: ${{ steps.set-version.outputs.name }}.vsix
asset_content_type: application/zip
publish:
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
with:
name: vsix
path: ./dist/
- name: Use Node.js
uses: actions/setup-node@master
with:
node-version: 12.x
- name: Prepare build
id: set-version
run: |
VERSION=`cat ./dist/.version`
echo ::set-output name=name::`cat ./dist/.name`
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
jq '.enableProposedApi = false' package.json > "$tmp" && mv "$tmp" package.json
npm install
npm i -g vsce
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@master
if: runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/package.vsix
asset_name: ${{ steps.set-version.outputs.name }}.vsix
asset_content_type: application/zip
- name: Publish to Marketplace
run: vsce publish -p ${{ secrets.VSCE_TOKEN }}

0 comments on commit c48db4d

Please sign in to comment.