Skip to content

Start over

Start over #9

Workflow file for this run

name: CI
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master
jobs:
checkout:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '17'
- name: Install dependencies
run: npm install
- name: Cache Clojure dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-clojure-${{ hashFiles('**/deps.edn') }}
restore-keys: |
${{ runner.os }}-clojure-
- name: Install Clojure
uses: DeLaGuardo/setup-clojure@12.1
with:
tools-deps: '1.10.3.943'
- name: Install CLJS dependencies
run: npx shadow-cljs classpath
- name: Create build workspace
run: mkdir -p /tmp/build
- name: Copy build
run: cp -r . /tmp/build
build:
runs-on: ubuntu-latest
needs: checkout
steps:
- name: Attach workspace
run: cp -r /tmp/build $GITHUB_WORKSPACE
- name: Tamper 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: Store artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: /tmp/artifacts
github-release:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Restore build
run: cp -r /tmp/build $GITHUB_WORKSPACE
- name: Publish Release on GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EXTRA_RELEASE_OPTIONS=""
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]
then
echo "Publishing GitHub Release: ${GITHUB_REF}"
else
echo "Publishing GitHub Prerelease: ${GITHUB_REF}"
EXTRA_RELEASE_OPTIONS=-prerelease
fi
[[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]
TAG_VERSION=${BASH_REMATCH[1]}
BODY=$(awk '/^## \['${TAG_VERSION}'\]/, started && /^##/ { started=1; if ($0 !~ /(^#|^\s*$)/) { gsub(/["$]/, "\\\\&"); print } }' CHANGELOG.md)
echo Changes: "\n" $BODY
gh release create ${GITHUB_REF} /tmp/artifacts/*.vsix --notes "${BODY}" ${EXTRA_RELEASE_OPTIONS}
marketplace-publish:
runs-on: ubuntu-latest
needs: github-release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Restore build
run: cp -r /tmp/build $GITHUB_WORKSPACE
- name: Publish to the marketplace
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: |
VSCE_CMD="vsce publish --packagePath /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix -p ${PUBLISH_TOKEN}"
npx ${VSCE_CMD}
marketplace-preview-publish:
runs-on: ubuntu-latest
needs: github-release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Restore build
run: cp -r /tmp/build $GITHUB_WORKSPACE
- name: Publish to the marketplace
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: |
VSCE_CMD="vsce publish --pre-release --packagePath /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix -p ${PUBLISH_TOKEN}"
npx ${VSCE_CMD}
open-vsx-publish:
runs-on: ubuntu-latest
needs: github-release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Restore build
run: cp -r /tmp/build $GITHUB_WORKSPACE
- name: Publish to Open VSX
env:
OVSX_PUBLISH_TOKEN: ${{ secrets.OVSX_PUBLISH_TOKEN }}
run: |
OVSX_CMD="ovsx publish /tmp/artifacts/paste-replaced-$(node -p 'require("./package.json").version').vsix --pat ${OVSX_PUBLISH_TOKEN}"
npx ${OVSX_CMD}
bump-version:
runs-on: ubuntu-latest
needs: marketplace-publish
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Configure git
run: |
git config --global user.email ${{ secrets.GITHUB_USER_EMAIL }}
git config --global user.name ${{ secrets.GITHUB_USER_NAME }}
- name: Bump dev version
run: |
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