Skip to content

Build and publish to NPM #338

Build and publish to NPM

Build and publish to NPM #338

Workflow file for this run

on:
workflow_run:
workflows: [Test JS bindings]
types: [completed]
branches: [master]
name: Build and publish to NPM
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
container: ghcr.io/kanaverse/scran.js-docker/builder:master
defaults:
run:
working-directory: /scran.js
steps:
- name: Get to the right branch
run: |
git fetch --all
git checkout $GITHUB_SHA
# We run the various preparatory steps to ensure that they do, in fact, run.
# This avoids nasty surprises when we actually do want to publish something.
- name: Update node build
run: bash build.sh main
- name: Update browser build
run: bash build.sh browser
- name: Set up Node
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
node-version: 16
- name: Update NPM packages
run: npm i --include=dev
# We only run the remaining (remote-touching) steps if the version has actually changed.
- name: Extract package versions
shell: bash
run: |
current_version=$(npm pkg get version | sed 's/"//g')
echo "NEW_SCRANJS_VERSION=${current_version}" >> $GITHUB_ENV
old_version=$(npm view scran.js version)
update=0 && [[ $old_version != $current_version ]] && update=1
echo "UPDATE_SCRANJS=${update}" >> $GITHUB_ENV
echo "Current version is ${current_version} (published ${old_version})"
- name: Publish to NPM
if: env.UPDATE_SCRANJS == 1
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tagging the release
if: env.UPDATE_SCRANJS == 1
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/' + process.env.NEW_SCRANJS_VERSION,
sha: context.sha
})