|
| 1 | +name: CI |
| 2 | + |
| 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 |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + timeout-minutes: 10 |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + os: [ubuntu-latest, windows-latest, macOS-latest] |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@master |
| 25 | + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 26 | + - name: Set an output |
| 27 | + id: set-version |
| 28 | + if: runner.os == 'Linux' |
| 29 | + run: | |
| 30 | + set -x |
| 31 | + VERSION=$(jq -r '.version' package.json | cut -d- -f1) |
| 32 | + [ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/} |
| 33 | + CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d') |
| 34 | + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" |
| 35 | + echo ::set-output name=changelog::$CHANGELOG |
| 36 | + git tag -l | cat |
| 37 | + [ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1)) |
| 38 | + [ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev |
| 39 | + echo ::set-output name=version::$VERSION |
| 40 | + NAME=$(jq -r '.name' package.json)-$VERSION |
| 41 | + echo ::set-output name=name::$NAME |
| 42 | + tmp=$(mktemp) |
| 43 | + jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 44 | + mkdir dist |
| 45 | + echo $VERSION > ./dist/.version |
| 46 | + echo $NAME > ./dist/.name |
| 47 | + - name: Use Node.js |
| 48 | + uses: actions/setup-node@master |
| 49 | + with: |
| 50 | + node-version: 12.x |
| 51 | + - run: npm install |
| 52 | + - name: lint |
| 53 | + if: runner.os == 'Linux' |
| 54 | + run: npm run lint |
| 55 | + - run: npm run compile |
| 56 | + - name: npm test |
| 57 | + |
| 58 | + with: |
| 59 | + run: npm run test |
| 60 | + - name: Build package |
| 61 | + if: runner.os == 'Linux' |
| 62 | + run: | |
| 63 | + ./node_modules/.bin/vsce package -o ./dist/package.vsix |
| 64 | + - uses: actions/upload-artifact@master |
| 65 | + if: runner.os == 'Linux' |
| 66 | + with: |
| 67 | + name: vsix |
| 68 | + path: ./dist/ |
| 69 | + beta: |
| 70 | + if: (github.event_name == 'push') |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: build |
| 73 | + steps: |
| 74 | + - uses: actions/download-artifact@master |
| 75 | + with: |
| 76 | + name: vsix |
| 77 | + path: ./dist/ |
| 78 | + - name: Set an output |
| 79 | + id: set-version |
| 80 | + if: runner.os == 'Linux' |
| 81 | + run: | |
| 82 | + set -x |
| 83 | + echo ::set-output name=version::`cat ./dist/.version` |
| 84 | + echo ::set-output name=name::`cat ./dist/.name` |
| 85 | + - name: Create Release |
| 86 | + id: create_release |
| 87 | + uses: actions/create-release@master |
| 88 | + if: runner.os == 'Linux' |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + with: |
| 92 | + tag_name: v${{ steps.set-version.outputs.version }} |
| 93 | + release_name: v${{ steps.set-version.outputs.version }} |
| 94 | + prerelease: ${{ github.event_name != 'release' }} |
| 95 | + body: | |
| 96 | + Changes in this release |
| 97 | + ${{ steps.set-version.outputs.changelog }} |
| 98 | + - name: Upload Release Asset |
| 99 | + id: upload-release-asset |
| 100 | + uses: actions/upload-release-asset@master |
| 101 | + if: runner.os == 'Linux' |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + with: |
| 105 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 106 | + asset_path: ./dist/package.vsix |
| 107 | + asset_name: ${{ steps.set-version.outputs.name }}.vsix |
| 108 | + asset_content_type: application/zip |
| 109 | + publish: |
| 110 | + if: github.event_name == 'release' |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: build |
| 113 | + steps: |
| 114 | + - uses: actions/checkout@v2 |
| 115 | + with: |
| 116 | + ref: master |
| 117 | + - uses: actions/download-artifact@master |
| 118 | + with: |
| 119 | + name: vsix |
| 120 | + path: ./dist/ |
| 121 | + - name: Use Node.js |
| 122 | + uses: actions/setup-node@master |
| 123 | + with: |
| 124 | + node-version: 12.x |
| 125 | + - name: Prepare build |
| 126 | + id: set-version |
| 127 | + run: | |
| 128 | + VERSION=`cat ./dist/.version` |
| 129 | + NEXT_VERSION=`cat ./dist/.version | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.` |
| 130 | + echo ::set-output name=name::`cat ./dist/.name` |
| 131 | + tmp=$(mktemp) |
| 132 | + git config --global user.name 'ProjectBot' |
| 133 | + git config --global user.email '[email protected]' |
| 134 | + jq --arg version "${NEXT_VERSION}-SNAPSHOT" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 135 | + git add package.json |
| 136 | + git commit -m 'auto bump version with release' |
| 137 | + jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 138 | + jq '.enableProposedApi = false' package.json > "$tmp" && mv "$tmp" package.json |
| 139 | + npm install |
| 140 | + npm i -g vsce ovsx |
| 141 | + git push |
| 142 | + - name: Upload Release Asset |
| 143 | + id: upload-release-asset |
| 144 | + uses: actions/upload-release-asset@master |
| 145 | + if: runner.os == 'Linux' |
| 146 | + env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 148 | + with: |
| 149 | + upload_url: ${{ github.event.release.upload_url }} |
| 150 | + asset_path: ./dist/package.vsix |
| 151 | + asset_name: ${{ steps.set-version.outputs.name }}.vsix |
| 152 | + asset_content_type: application/zip |
| 153 | + - name: Publish to Marketplaces |
| 154 | + run: | |
| 155 | + vsce publish -p ${{ secrets.VSCE_TOKEN }} |
| 156 | + ovsx publish --pat ${{ secrets.OVSX_TOKEN }} |
| 157 | +
|
0 commit comments