build_release #61
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: build_release | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '20 19 * * *' # 北京时间凌晨3:20运行(UTC时间为前一天的19:20) | |
jobs: | |
check_changes: | |
runs-on: ubuntu-latest | |
outputs: | |
has_changes: ${{ steps.check_changes.outputs.has_changes }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get Latest Tag | |
id: get_latest_tag | |
run: | | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
echo "Latest tag: $latest_tag" | |
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT | |
- name: Check for Changes | |
id: check_changes | |
run: | | |
latest_tag=${{ steps.get_latest_tag.outputs.latest_tag }} | |
if [ -z "$latest_tag" ]; then | |
echo "No tags found." | |
echo "has_changes=true" >> $GITHUB_OUTPUT | |
else | |
changes=$(git diff --name-only $latest_tag HEAD -- ./src) | |
if [ -z "$changes" ]; then | |
echo "No changes detected in ./src" | |
echo "has_changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "Changes detected in ./src:" | |
echo "$changes" | |
echo "has_changes=true" >> $GITHUB_OUTPUT | |
fi | |
fi | |
build_release: | |
needs: check_changes | |
runs-on: ubuntu-latest | |
if: needs.check_changes.outputs.has_changes == 'true' | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- uses: pnpm/action-setup@v4 | |
- run: pnpm install | |
- run: pnpm run build | |
- id: version | |
run: | | |
version=$(node -e "import('@gkd-kit/tools').then((m) => m.stdoutGkdVersion());") | |
echo "version=${version}" >> "$GITHUB_OUTPUT" | |
- name: Git commit | |
id: commit | |
run: | | |
git config --local user.email github-actions[bot]@users.noreply.github.com | |
git config --local user.name github-actions[bot] | |
git status | |
git add . | |
git commit -a -m "chore: v${{steps.version.outputs.version}}" | |
continue-on-error: true | |
- name: Git push | |
if: ${{ steps.commit.outcome == 'success' }} | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
tags: true | |
- name: Create Release | |
if: ${{ steps.commit.outcome == 'success' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.version.outputs.version }} | |
release_name: Release ${{ steps.version.outputs.version }} | |
body_path: ./dist/CHANGELOG.md | |
- name: Publish package | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
if: ${{ steps.commit.outcome == 'success' && env.NPM_TOKEN != '' }} | |
run: | | |
pnpm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} | |
node -e "import('@gkd-kit/tools').then((m) => m.updatePkgVersion());" | |
pnpm publish --no-git-checks | |
node -e "import('@gkd-kit/tools').then((m) => m.syncNpmmirror());" |