update #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pre Publish | |
on: | |
push: | |
branches: | |
- main # master 分支有 push 行为时就触发这个 action | |
jobs: | |
pre-publish: | |
# needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Set timezone to Asia/Shanghai | |
uses: szenius/[email protected] | |
with: | |
# 设置执行环境的时区为 Linux 上海时区 | |
timezoneLinux: "Asia/Shanghai" | |
- name: Echo current time | |
run: timedatectl | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.11.1 | |
- name: Set Git user and email | |
run: | | |
git config --local user.name ${{vars.NAME}} | |
git config --local user.email ${{vars.EMAIL}} | |
- name: Update Version | |
run: | | |
# 更新版本号并获取新版本号 | |
VERSION=$(npm version patch --no-git-tag-version --silent) | |
echo "VERSION=$VERSION" | |
# 将新版本号输出到环境变量 | |
echo "NEW_VERSION=$VERSION" >> $GITHUB_ENV | |
SHORT_GITHUB_SHA=$(echo ${GITHUB_SHA:0:8}) | |
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA" | |
# 将八位hash输出到环境变量 | |
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA" >> $GITHUB_ENV | |
TAG_NAME="${VERSION}-${SHORT_GITHUB_SHA}" | |
echo "TAG_NAME=$TAG_NAME" | |
# 将组合的TAG_NAME输出到环境变量 | |
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
- name: Install pnpm | |
run: | | |
npm install -g pnpm | |
# pnpm config set store-dir $(pwd)/.pnpm-store | |
# pnpm config set recursive-optional true | |
- name: Install Dependence | |
run: pnpm i | |
- name: Build dist | |
run: | | |
git pull -p | |
pnpm run build | |
- name: Pre publish | |
run: npm publish --dry-run # 如果发布之前需要构建,可添加prepublishOnly的生命周期脚本 | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} # 上面在Github Secrets中设置的密钥 | |
- uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
update: | |
- 'main/**' | |
- 'types/**' | |
- 'utils/**' | |
- README.md | |
- package.json | |
- rollup.config.js | |
- tsconfig.json | |
- .babelrc | |
- name: Create GitHub Release | |
if: steps.changes.outputs.update == 'true' | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
token: ${{ secrets.TOKEN }} | |
name: "Release ${{ env.NEW_VERSION }}" | |
tag_name: "${{ env.TAG_NAME }}" | |
body: "Check the changelog for details." | |
draft: false | |
prerelease: false | |
files: | | |
- package.json | |
- dist | |
- LICENSE | |
- name: Commit and push Version | |
run: | | |
git add package.json | |
git commit -m "Bump version to ${{ env.TAG_NAME }}" | |
git tag -a "${{ env.TAG_NAME }}" -m "Release ${{ env.TAG_NAME }}" | |
git push origin main | |
- name: Publish | |
run: npm publish # 如果发布之前需要构建,可添加prepublishOnly的生命周期脚本 | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} # 上面在Github Secrets中设置的密钥 | |
# - name: Repository Dispatch | |
# uses: peter-evans/repository-dispatch@v3 | |
# with: | |
# token: ${{ secrets.GITHUB_TOKEN }} | |
# # 也可以直接写成R: GITHUB_REPOSITORY | |
# # https://docs.github.com/zh/actions/learn-github-actions/variables | |
# repository: ${{ github.repository }} | |
# event-type: to-publish-npm |