Skip to content

Release: v5.19.2

Release: v5.19.2 #452

Workflow file for this run

# ⚠️ IMPORTANT: This workflow is a template from diplodoc/lint/scaffolding
# Do not edit this file in other packages - it is automatically copied from here.
# To modify this workflow, edit it in diplodoc/devops/lint/scaffolding/.github/workflows/
# and then run the scaffolding update process.
name: Release Package to npm
# This workflow handles stable releases, prereleases, and deprecation:
# - Stable: triggered by release event or manual dispatch with 'stable' type
# - Prerelease: triggered by manual dispatch with 'prerelease' type (only from non-protected branches)
# - Deprecate: triggered by manual dispatch with 'deprecate' type (marks a version as deprecated)
# GitHub auto-generates a run-name from event data when run-name is not set
# explicitly (e.g. it uses the release tag_name for `release` events, which is
# why runs triggered by the `release` event show "vX.XX.XX" instead of the
# workflow name). workflow_dispatch events carry no such default, so without an
# explicit run-name every manual run (prerelease/deprecate) just shows the
# workflow name. The run-name below makes all trigger types display something
# meaningful in the Actions history.
run-name: >-
${{
github.event_name == 'release' && format('Release: {0}', github.event.release.tag_name)
|| (github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate' && inputs.deprecate_new_latest != '' && format('Deprecate: {0} -> {1}', inputs.deprecate_version, inputs.deprecate_new_latest))
|| (github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate' && format('Deprecate: {0}', inputs.deprecate_version))
|| (github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease' && format('Prerelease: {0}', github.ref_name))
|| github.workflow
}}
on:
release:
types: [published]
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'prerelease'
type: choice
options:
- prerelease
- stable
- deprecate
deprecate_version:
description: 'Version to deprecate (only for deprecate type)'
required: false
type: string
deprecate_message:
description: 'Deprecation message (only for deprecate type)'
required: false
type: string
deprecate_new_latest:
description: 'New latest version (required when deprecating current latest)'
required: false
type: string
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
# For prerelease - only from non-protected branches
# For deprecate - always allowed
if: |
github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'stable') ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease' && github.ref_protected != true) ||
(github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate')
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: diplodoc-platform/setup-node-action@v1
with:
node-version: ${{ vars.NODE_VERSION || '24' }}
registry-url: 'https://registry.npmjs.org'
cache: ''
run-install: 'false'
- uses: codex-team/action-nodejs-package-info@v1
id: package
- name: Install dependencies
if: inputs.release_type != 'deprecate'
run: npm ci
- name: Run tests
if: inputs.release_type != 'deprecate'
run: npm test
- name: Run type check
if: inputs.release_type != 'deprecate'
run: npm run typecheck
- name: Build package
if: inputs.release_type != 'deprecate'
run: npm run build
# === STABLE RELEASE STEPS ===
- name: Check version matches release tag
if: github.event_name == 'release'
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
RELEASE_TAG=${GITHUB_REF#refs/tags/}
RELEASE_VERSION=${RELEASE_TAG#v}
if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then
echo "Error: package.json version ($PACKAGE_VERSION) does not match release tag ($RELEASE_TAG -> $RELEASE_VERSION)"
exit 1
fi
echo "Version check passed: $PACKAGE_VERSION (from tag $RELEASE_TAG)"
- name: Skip if draft release
if: github.event.release.draft == true
run: |
echo "Skipping publish for draft release"
exit 0
- name: Publish stable to npm
if: (github.event_name == 'release' && github.event.release.draft == false) || (github.event_name == 'workflow_dispatch' && inputs.release_type == 'stable')
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# === PRERELEASE STEPS ===
- name: Set prerelease version
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: npm version --no-git-tag-version 0.0.0-rc-$(git branch --show-current)-${{github.run_id}}
- name: Publish prerelease to npm
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'prerelease'
run: npm publish --tag $(git branch --show-current) --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# === DEPRECATE STEPS ===
# workflow_dispatch inputs are user-controlled. Do not interpolate them
# directly into a shell script (${{ inputs.* }} in run:) — pass them
# through env: and reference as "$VAR" so quotes / $(...) / ;-chains in
# input values cannot escape into the shell.
- name: Validate deprecate inputs
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate'
env:
INPUT_DEPRECATE_VERSION: ${{ inputs.deprecate_version }}
INPUT_DEPRECATE_MESSAGE: ${{ inputs.deprecate_message }}
run: |
if [[ -z "$INPUT_DEPRECATE_VERSION" ]]; then
echo "::error::deprecate_version is required for deprecate action"
exit 1
fi
if [[ -z "$INPUT_DEPRECATE_MESSAGE" ]]; then
echo "::error::deprecate_message is required for deprecate action"
exit 1
fi
- name: Deprecate version
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'deprecate'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# See note above the "Validate deprecate inputs" step.
PACKAGE_NAME: ${{ steps.package.outputs.name }}
INPUT_DEPRECATE_VERSION: ${{ inputs.deprecate_version }}
INPUT_DEPRECATE_MESSAGE: ${{ inputs.deprecate_message }}
INPUT_DEPRECATE_NEW_LATEST: ${{ inputs.deprecate_new_latest }}
run: |
set -e
LATEST="$(npm view "$PACKAGE_NAME@latest" version 2>/dev/null || echo '')"
TARGET="$PACKAGE_NAME@$INPUT_DEPRECATE_VERSION"
if [[ "$LATEST" == "$INPUT_DEPRECATE_VERSION" ]]; then
if [[ -z "$INPUT_DEPRECATE_NEW_LATEST" ]]; then
echo "::error::deprecate_new_latest is required when deprecating the current latest version ($LATEST)"
exit 1
fi
echo "::notice::Setting new latest tag to $PACKAGE_NAME@$INPUT_DEPRECATE_NEW_LATEST"
npm dist-tag add "$PACKAGE_NAME@$INPUT_DEPRECATE_NEW_LATEST" latest
fi
echo "::notice::Deprecating $TARGET. Reason: $INPUT_DEPRECATE_MESSAGE"
npm deprecate "$TARGET" "$INPUT_DEPRECATE_MESSAGE"