使用 GitHub 作为博客之后,可以利用 GitHub Actions 做哪些事情? #11
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: Update README | |
on: | |
issues: | |
types: [opened, deleted] | |
push: | |
paths: | |
- 'docs/templates/readme.md' | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Pull latest changes | |
run: git pull origin main | |
- name: Install dependencies | |
run: npm install | |
- name: Run update-readme script | |
env: | |
GITHUB_TOKEN: ${{ secrets.WORKFLOW_GITHUB_TOKEN }} | |
run: node scripts/update-readme.js | |
- name: Check if README.md has changed | |
id: check_changes | |
run: | | |
if git diff --exit-code README.md; then | |
echo "file_changed=false" >> $GITHUB_ENV | |
else | |
echo "file_changed=true" >> $GITHUB_ENV | |
fi | |
- name: Commit changes | |
if: env.file_changed == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.WORKFLOW_GITHUB_TOKEN }} | |
GITHUB_USER: toFrankie | |
GITHUB_REPO: blog | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
git add README.md | |
git commit -m "docs: update readme" | |
git push origin main |