Rename workflow file #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-test | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- 'v*' | |
pull_request: | |
branches: | |
- master | |
jobs: | |
checkout: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Restore dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Install dependencies | |
run: npm install | |
- name: Create build workspace | |
run: mkdir -p /tmp/build | |
- name: Copy build | |
run: cp -r . /tmp/build | |
- name: Save dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
build: | |
runs-on: ubuntu-latest | |
needs: checkout | |
steps: | |
- name: Attach workspace | |
run: cp -r /tmp/build . | |
- name: Install Clojure | |
uses: DeLaGuardo/setup-clojure@v1 | |
with: | |
tools-deps: '1.10.3.943' | |
- name: Install CLJS dependencies | |
run: npx shadow-cljs classpath | |
- name: Create artifacts workspace | |
run: mkdir -p /tmp/artifacts | |
- name: Tamper paste-replaced version if not release versioned | |
run: | | |
VERSION=$(node -p 'require("./package.json").version') | |
TAG_VERSION=NO-TAG | |
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then | |
TAG_VERSION=${BASH_REMATCH[1]} | |
echo 'No version tampering because this is a release tag' | |
else | |
COMMIT=${GITHUB_SHA:0:8} | |
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)-(.*) ]]; then | |
TAG_VERSION=${BASH_REMATCH[1]} | |
TAG_TITLE=${BASH_REMATCH[2]} | |
PRERELEASE=${TAG_TITLE}-${COMMIT} | |
else | |
BRANCH=${GITHUB_REF_NAME//[^[:alnum:]]/-} | |
PRERELEASE=${BRANCH}-${COMMIT} | |
fi | |
echo "Append prerelease to version: -${PRERELEASE}" | |
npx json -I -f package.json -e 'this.version=this.version.replace(/$/,"-'${PRERELEASE}'")' | |
fi | |
if [ ${TAG_VERSION} = NO-TAG -o "${TAG_VERSION}" = "${VERSION}" ]; then | |
VERSION=$(node -p 'require("./package.json").version') | |
echo "Using version: ${VERSION}" | |
else | |
echo >&2 "FATAL! Version mismatch between package.json and tag. Aborting." | |
exit 1 | |
fi | |
- name: Package vsix | |
run: | | |
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then | |
echo "Packaging as release" | |
PACKAGE_CMD="vsce package --allow-star-activation --githubBranch master" | |
else | |
echo "Packaging as pre-release" | |
PACKAGE_CMD="vsce package --allow-star-activation --pre-release" | |
fi | |
npx ${PACKAGE_CMD} | |
- name: Copy vsix | |
run: cp *.vsix /tmp/artifacts/ | |
- name: Copy build | |
run: | | |
cp -r out /tmp/build | |
cp package.json /tmp/build | |
- name: Save dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Store artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: artifacts | |
path: /tmp/artifacts | |
github-release: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Attach workspace | |
run: cp -r /tmp/build . | |
- name: Determine if prerelease | |
id: prerelease_check | |
run: | | |
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then | |
echo "::set-output name=prerelease::false" | |
else | |
echo "::set-output name=prerelease::true" | |
fi | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
body: | | |
Changes: | |
$(awk '/^## \['${{ github.ref }}'\]/, started && /^##/ { started=1; if ($0 !~ /(^#|^\s*$)/) { gsub(/["$]/, "\\\\&"); print } }' CHANGELOG.md) | |
draft: false | |
prerelease: ${{ steps.prerelease_check.outputs.prerelease }} | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix | |
asset_name: paste-replaced-$(node -p 'require("./package.json").version').vsix | |
asset_content_type: application/octet-stream | |
marketplace-publish: | |
runs-on: ubuntu-latest | |
needs: github-release | |
steps: | |
- name: Attach workspace | |
run: cp -r /tmp/build . | |
- name: Publish to the marketplace | |
run: | | |
VSCE_CMD="vsce publish --packagePath /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix -p ${PUBLISH_TOKEN}" | |
if [ "${IS_LOCAL}" = YES ]; then | |
echo "Dry npx ${VSCE_CMD}" | |
else | |
npx ${VSCE_CMD} | |
open-vsx-publish: | |
runs-on: ubuntu-latest | |
needs: github-release | |
steps: | |
- name: Attach workspace | |
run: cp -r /tmp/build . | |
- name: Publish to Open VSX | |
run: | | |
OVSX_CMD="ovsx publish /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix --pat ${OVSX_PUBLISH_TOKEN}" | |
if [ "${IS_LOCAL}" = YES ]; then | |
echo "Dry npx ${OVSX_CMD}" | |
else | |
npx ${OVSX_CMD} | |
bump-version: | |
runs-on: ubuntu-latest | |
needs: marketplace-publish | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Bump dev version | |
run: | | |
git config --global user.email $GITHUB_USER_EMAIL | |
git config --global user.name $GITHUB_USER_NAME | |
git checkout master | |
npm set git-tag-version false && npm version patch | |
git add . | |
git commit -m "Bring on version $(node -p 'require('./package').version')!" | |
git push origin HEAD |