Skip to content
name: Release package
on:
workflow_call:
inputs:
release-type:
description: "Release type"
required: true
type: string
# type: choice
# options:
# - major
# - minor
# - patch
# - premajor
# - preminor
# - prepatch
# - prerelease
release-notes:
description: "Release notes"
type: string
dist-script:
description: "Distribution script to execute"
type: string
default: "dist"
permissions:
id-token: write
contents: write
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
jobs:
Release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# Setup Node.js environment
- name: Set up Node.js 20.9.0
uses: actions/setup-node@v4
with:
node-version: 20.9.0
# Important!
registry-url: 'https://registry.npmjs.org'
always-auth: true
- name: Set up environment
uses: michijs/.github/.github/workflows/runtime/setup.yml@main
- name: Install dependencies
uses: michijs/.github/.github/workflows/runtime/install.yml@main
# Configure Git
- name: Git configuration
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
# Bump package version
# Use tag latest
- name: Bump release version
if: startsWith(github.event.inputs.release-type, 'pre') != true
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
# Bump package pre-release version
# Use tag beta for pre-release versions
- name: Bump pre-release version
if: startsWith(github.event.inputs.release-type, 'pre')
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
- name: Build
uses: michijs/.github/.github/workflows/runtime/run.yml@main
with:
script-name: ${{ inputs.dist-script }}
# Commit changes
- name: Commit package.json changes and create tag
run: |
git add "package.json"
git commit -m "chore: release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
# Push repository changes
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
# Update GitHub release with changelog
- name: Update GitHub release documentation
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
body: ${{ github.event.inputs.release-notes }}
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
# Publish version to public repository
- name: Publish
run: npm publish --provenance --access public --tag ${{ env.RELEASE_TAG }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}