From 6552853fefe0ee570c01c8f9b88b180186817da3 Mon Sep 17 00:00:00 2001 From: Koy Zhuang Date: Sat, 25 May 2024 12:45:11 +0800 Subject: [PATCH] update(ci): add update emoji schedule workflow (#2436) --------- Co-authored-by: Luffy <52o@qq52o.cn> --- .github/workflows/update-emoji.yml | 53 ++++++++++++++++++++++++++++++ build/emoji.js | 14 +++----- package.json | 2 +- 3 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/update-emoji.yml diff --git a/.github/workflows/update-emoji.yml b/.github/workflows/update-emoji.yml new file mode 100644 index 000000000..53b9857b2 --- /dev/null +++ b/.github/workflows/update-emoji.yml @@ -0,0 +1,53 @@ +name: Update Emoji + +on: + schedule: + - cron: '0 2 * * *' + workflow_dispatch: + +concurrency: + group: update-emoji-group + +jobs: + sync-emojis-from-github: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js v20 + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm ci --ignore-scripts + + - name: Fetch emojiData + run: npm run build:emoji + + - name: Check for changes + run: | + if git diff --quiet -- "src/core/render/emoji-data.js"; then + echo "No changes Found. Skipping PR creation." + else + echo "Changes detected in emoji-data.js. Creating PR." + + current_date=$(date +'%Y-%m-%d') + + branch_name="update-emoji-data-$current_date" + pr_title="update(emoji): Sync emoji data with GitHub emoji API [$current_date]" + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + + git checkout -b $branch_name + git add src/core/render/emoji-data.js + git add docs/emoji.md + git commit -m "update(emoji): Sync emoji data with GitHub emoji API [$current_date]" + unique_branch_name=$branch_name-$(git log -1 --pretty=%h) + git checkout -b $unique_branch_name + git push origin $unique_branch_name + gh pr create --title "$pr_title" --body "Found updated github emojis need to sync, PTAL @docsifyjs/reviewers :robot:." --base develop + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build/emoji.js b/build/emoji.js index f1ad8930b..affc5c1e5 100644 --- a/build/emoji.js +++ b/build/emoji.js @@ -95,13 +95,9 @@ function writeEmojiJS(emojiData) { console.info('Build emoji'); -try { - const emojiData = await getEmojiData(); +const emojiData = await getEmojiData(); - if (emojiData) { - writeEmojiPage(emojiData); - writeEmojiJS(emojiData); - } -} catch (err) { - console.warn(`- Error: ${err.message}`); -} +writeEmojiPage(emojiData); +writeEmojiJS(emojiData); + +console.info('Finish update'); diff --git a/package.json b/package.json index 71d5c33d6..ef85b3de4 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "build:css": "stylus src/themes --out dist/themes --sourcemap", "build:emoji": "node ./build/emoji.js", "build:js": "rollup -c", - "build": "run-s clean build:js build:css build:css:min build:cover build:emoji", + "build": "run-s clean build:js build:css build:css:min build:cover", "clean": "rimraf --glob dist/** themes/** _playwright*/**", "dev": "run-p serve:dev watch:*", "docker:build:test": "npm run docker:cli -- build:test",