Skip to content

Auto Publish

Auto Publish #10

Workflow file for this run

name: Auto Publish
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: 输入您将要发布的版本号(默认使用 packages/fluent-editor/package.json 中的版本号),例如:`0.1.0`。
required: false
type: string
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.value }}
steps:
- name: CheckOut Code
uses: actions/checkout@master
with:
ref: ${{ github.ref_name }}
- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.10.0
registry-url: "https://registry.npmjs.org"
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --no-frozen-lockfile
- name: Get version
id: ver
run: |
# 优先用手动输入的版本号
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="$(node -p "require('./packages/fluent-editor/package.json').version")"
fi
echo "version: $VERSION"
echo "value=$VERSION" >> $GITHUB_OUTPUT
- name: Build lib
run: |
pnpm build:lib
cd packages/fluent-editor
echo "version: ${{ steps.ver.outputs.value }}"
pnpm pre-release -v ${{ steps.ver.outputs.value }}
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: dist-artifact
path: packages/fluent-editor/dist/
# Publish job
publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: dist-artifact
path: packages/fluent-editor/dist/
- name: Parse Publish version
id: parse_version
run: |
version_name="${{ needs.build.outputs.version }}"
if [[ "$version_name" == *alpha* ]]; then
echo "dist_tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$version_name" == *beta* ]]; then
echo "dist_tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$version_name" == *rc* ]]; then
echo "dist_tag=rc" >> "$GITHUB_OUTPUT"
else
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Show tag
run: |
echo "publish tag: ${{ steps.parse_version.outputs.dist_tag }}"
- name: Publish @opentiny/fluent-editor
run: |
echo "ls"
ls
cd packages/fluent-editor/dist
ls
if [ ${{ steps.parse_version.outputs.dist_tag }} == 'latest' ]; then
npm publish
else
npm publish --tag ${{ steps.parse_version.outputs.dist_tag }}
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release
if: ${{ steps.parse_version.outputs.dist_tag == 'latest' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}