|
| 1 | +name: CI-prerelease |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - prerelease |
| 7 | + paths-ignore: |
| 8 | + - "docs/**" |
| 9 | + - ".vscode/**" |
| 10 | + - ".github/**" |
| 11 | + - "*.md" |
| 12 | + - "**/*.md" |
| 13 | + pull_request: |
| 14 | + branches: |
| 15 | + - prerelease |
| 16 | + release: |
| 17 | + types: |
| 18 | + - released |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + timeout-minutes: 10 |
| 22 | + runs-on: ${{ matrix.os }} |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + os: [ubuntu-latest, windows-latest, macOS-latest] |
| 26 | + outputs: |
| 27 | + taggedbranch: ${{ steps.find-branch.outputs.taggedbranch }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 31 | + - name: Find which branch the release tag points at |
| 32 | + id: find-branch |
| 33 | + if: github.event_name == 'release' && runner.os == 'Linux' |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + git fetch --depth=1 origin +refs/heads/*:refs/heads/* |
| 37 | + set -x |
| 38 | + TAGGEDBRANCH=$(git for-each-ref --points-at=${{github.sha}} --format='%(refname:lstrip=2)' refs/heads/) |
| 39 | + echo ::set-output name=taggedbranch::$TAGGEDBRANCH |
| 40 | + - name: Set an output |
| 41 | + id: set-version |
| 42 | + if: runner.os == 'Linux' |
| 43 | + run: | |
| 44 | + set -x |
| 45 | + VERSION=$(jq -r '.version' package.json | cut -d- -f1) |
| 46 | + [ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/} |
| 47 | + CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d') |
| 48 | + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" |
| 49 | + echo ::set-output name=changelog::$CHANGELOG |
| 50 | + git tag -l | cat |
| 51 | + [ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1)) |
| 52 | + [ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev.${{ github.event.pull_request.number }} |
| 53 | + echo ::set-output name=version::$VERSION |
| 54 | + NAME=$(jq -r '.name' package.json)-$VERSION |
| 55 | + echo ::set-output name=name::$NAME |
| 56 | + tmp=$(mktemp) |
| 57 | + jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 58 | + mkdir dist |
| 59 | + echo $VERSION > .version |
| 60 | + echo $NAME > .name |
| 61 | + - name: Use Node.js |
| 62 | + uses: actions/setup-node@v1 |
| 63 | + with: |
| 64 | + node-version: 14.x |
| 65 | + - run: npm install |
| 66 | + - name: lint |
| 67 | + if: runner.os == 'Linux' |
| 68 | + run: npm run lint |
| 69 | + - run: npm run compile |
| 70 | + - name: npm test |
| 71 | + |
| 72 | + with: |
| 73 | + run: npm run test |
| 74 | + - name: Build pre-release package |
| 75 | + if: runner.os == 'Linux' |
| 76 | + run: | |
| 77 | + npx vsce package --pre-release -o ${{ steps.set-version.outputs.name }}.vsix |
| 78 | + - uses: actions/upload-artifact@v2 |
| 79 | + if: (runner.os == 'Linux') && (github.event_name != 'release') |
| 80 | + with: |
| 81 | + name: ${{ steps.set-version.outputs.name }}.vsix |
| 82 | + path: ${{ steps.set-version.outputs.name }}.vsix |
| 83 | + - uses: actions/upload-artifact@v2 |
| 84 | + if: runner.os == 'Linux' |
| 85 | + with: |
| 86 | + name: meta |
| 87 | + path: | |
| 88 | + .name |
| 89 | + .version |
| 90 | + beta: |
| 91 | + if: (github.event_name == 'push') |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: build |
| 94 | + steps: |
| 95 | + - uses: actions/download-artifact@v2 |
| 96 | + with: |
| 97 | + name: meta |
| 98 | + path: . |
| 99 | + - name: Set an output |
| 100 | + id: set-version |
| 101 | + if: runner.os == 'Linux' |
| 102 | + run: | |
| 103 | + set -x |
| 104 | + echo ::set-output name=version::`cat .version` |
| 105 | + echo ::set-output name=name::`cat .name` |
| 106 | + - uses: actions/download-artifact@v2 |
| 107 | + with: |
| 108 | + name: ${{ steps.set-version.outputs.name }}.vsix |
| 109 | + - name: Create Pre-Release |
| 110 | + id: create_release |
| 111 | + uses: actions/create-release@v1 |
| 112 | + if: runner.os == 'Linux' |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + with: |
| 116 | + tag_name: v${{ steps.set-version.outputs.version }} |
| 117 | + release_name: v${{ steps.set-version.outputs.version }} |
| 118 | + prerelease: ${{ github.event_name != 'release' }} |
| 119 | + body: | |
| 120 | + Changes in this pre-release |
| 121 | + ${{ steps.set-version.outputs.changelog }} |
| 122 | + - name: Upload Pre-Release Asset |
| 123 | + id: upload-release-asset |
| 124 | + uses: actions/upload-release-asset@v1 |
| 125 | + if: runner.os == 'Linux' |
| 126 | + env: |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + with: |
| 129 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 130 | + asset_path: ${{ steps.set-version.outputs.name }}.vsix |
| 131 | + asset_name: ${{ steps.set-version.outputs.name }}.vsix |
| 132 | + asset_content_type: application/zip |
| 133 | + publish: |
| 134 | + needs: build |
| 135 | + if: github.event_name == 'release' && needs.build.outputs.taggedbranch == 'prerelease' |
| 136 | + runs-on: ubuntu-latest |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v2 |
| 139 | + with: |
| 140 | + ref: prerelease |
| 141 | + token: ${{ secrets.TOKEN }} |
| 142 | + - uses: actions/download-artifact@v2 |
| 143 | + with: |
| 144 | + name: meta |
| 145 | + path: . |
| 146 | + - name: Use Node.js |
| 147 | + uses: actions/setup-node@v1 |
| 148 | + with: |
| 149 | + node-version: 14.x |
| 150 | + - name: Prepare pre-release build |
| 151 | + id: set-version |
| 152 | + run: | |
| 153 | + VERSION=`cat .version` |
| 154 | + NEXT_VERSION=`cat .version | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.` |
| 155 | + echo ::set-output name=name::`cat .name` |
| 156 | + tmp=$(mktemp) |
| 157 | + git config --global user.name 'ProjectBot' |
| 158 | + git config --global user.email '[email protected]' |
| 159 | + jq --arg version "${NEXT_VERSION}-SNAPSHOT" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 160 | + git add package.json |
| 161 | + git commit -m 'auto bump version after pre-release' |
| 162 | + jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json |
| 163 | + npm install |
| 164 | + jq 'del(.enableProposedApi,.enabledApiProposals)' package.json > "$tmp" && mv "$tmp" package.json |
| 165 | + git push |
| 166 | + - name: Build pre-release package |
| 167 | + run: | |
| 168 | + npx vsce package --pre-release -o ${{ steps.set-version.outputs.name }}.vsix |
| 169 | + - name: Upload Release Asset |
| 170 | + id: upload-release-asset |
| 171 | + uses: actions/upload-release-asset@v1 |
| 172 | + if: runner.os == 'Linux' |
| 173 | + env: |
| 174 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 175 | + with: |
| 176 | + upload_url: ${{ github.event.release.upload_url }} |
| 177 | + asset_path: ${{ steps.set-version.outputs.name }}.vsix |
| 178 | + asset_name: ${{ steps.set-version.outputs.name }}.vsix |
| 179 | + asset_content_type: application/zip |
| 180 | + - name: Publish to VSCode Marketplace |
| 181 | + run: | |
| 182 | + [ -n "${{ secrets.VSCE_TOKEN }}" ] && \ |
| 183 | + npx vsce publish --pre-release --packagePath ${{ steps.set-version.outputs.name }}.vsix -p ${{ secrets.VSCE_TOKEN }} || true |
0 commit comments