Skip to content

release

release #9

Workflow file for this run

name: release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
next_version:
description: |
Next release version. Possible values: x.y.z, major, minor, patch
required: true
default: 'skip'
# XXX: does not skip for some reason
# skip_tests:
# description: |
# Skip tests iff === 'true'
# required: true
# default: 'false'
workflow_call:
inputs:
next_version:
description: |
Next release version. Possible values: x.y.z, major, minor, patch
required: true
type: string
default: 'skip'
env:
CACHE_DIR: dist
node: ${{ vars.DEFAULT_NODE_VERSION }}
jobs:
lint:
uses: ./.github/workflows/lint.yml
build-and-test:
# XXX: does not skip for some reason
# if: github.events.inputs.skip_tests != 'true'
uses: ./.github/workflows/ubuntu-latest.yml
publish:
needs: [lint, build-and-test]
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Calculate cache keys
# Because the exact same hashFiles invocation produces different
# results down the file
id: build-cache-keys
shell: bash
run: |
if command -v shasum; then sum() { shasum -a 256 "$@"; } ; else sum() { sha256sum "$@"; }; fi
fragment="${{ runner.os }}-${{ env.node }}-${{ hashFiles('*.ts', '**/src/**', '**/.swcrc', '**/.npmrc', '**/tsconfig*.json', '**/pnpm-lock.yaml') }}-$(< package.json sum | command head -c8)"
build_fragment="${{ hashFiles('.github/workflows/build.yml') }}"
echo "build-key=build-${fragment}-${build_fragment}" | tee -a $GITHUB_OUTPUT
- uses: actions/setup-node@v3
id: setup-node
with:
node-version: ${{ env.node }}
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
# See: https://github.com/pnpm/action-setup#use-cache-to-reduce-installation-time
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/.npmrc', '**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile --strict-peer-dependencies
- name: Restore build cache
id: build_cache
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ steps.build-cache-keys.outputs.build-key }}
fail-on-cache-miss: true
- name: Create a new version
if: ${{ github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch' && github.event.inputs.next_version != 'skip' }}
shell: bash
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
# cd to where project package.json is
# pnpm version \
# --new-version ${{ github.event.inputs.next_version }} \
# --message "chore: Release ${{ github.event.inputs.next_version }}"
pnpm bump-version ${{ github.event.inputs.next_version }}
# Push commit along with tag
git push origin --tags :
- name: Publish to npm
shell: bash
run: |
# Ensure these files are here:
missing_files=()
for file in dist/mjs/main.js
do
if ! pnpm publish --no-git-checks --dry-run --json | grep -q 'path.*:.*'"$file"
then
missing_files+=("$file")
fi
done
if [[ ${#missing_files[@]} -gt 0 ]]
then
>&2 echo "error: The following files are missing. Aborting publish process."
for file in "${missing_files[@]}"
do
>&2 echo " $file"
done
exit 1
fi
pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.PANERON_CI_NPM_TOKEN }}