自动发布 #9
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: 自动发布 | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- master | |
workflow_dispatch: | |
jobs: | |
publish-and-pr: | |
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run publish script | |
run: npm run publish | |
# 生成分支名称并存储为变量 | |
- name: Generate branch name | |
id: branch_name | |
run: | | |
echo "branch_name=auto-publish-changes-$(date +%s)" >> $GITHUB_OUTPUT | |
# Configure Git for committing changes | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# Commit and push changes to a new branch | |
- name: Commit and create branch | |
run: | | |
git checkout -b ${{ steps.branch_name.outputs.branch_name }} | |
git add . | |
git commit -m "Automated changes after publish" | |
git push origin ${{ steps.branch_name.outputs.branch_name }} | |
# Push changes and create a PR | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
branch: ${{ steps.branch_name.outputs.branch_name }} | |
title: "Automated Changes After Publish" | |
body: | | |
This PR was created automatically after running the publish script on the master branch. | |
commit-message: "Automated changes after publish" | |
base: "master" |