From e29c7846103599333b9b0793a6054bbe658a248d Mon Sep 17 00:00:00 2001 From: Ika Date: Tue, 7 Jul 2020 21:50:29 +0800 Subject: [PATCH] chore: use github actions --- .github/workflows/lint.yml | 24 +++++++++++++ .github/workflows/test.yml | 24 +++++++++++++ .github/workflows/update.yml | 66 ++++++++++++++++++++++++++++++++++++ .travis.yml | 16 --------- scripts/generate.test.js | 2 +- scripts/markdown.js | 2 +- 6 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/update.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4a759d5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + - push + - pull_request + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2-beta + with: + node-version: "12" + + - name: Install Dependencies + run: yarn + + - name: Lint + run: yarn lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f8e3be1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Test + +on: + - push + - pull_request + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2-beta + with: + node-version: "12" + + - name: Install Dependencies + run: yarn + + - name: Test + run: yarn test --ci diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..34e294f --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,66 @@ +name: Up to Date + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + update: + name: Update + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v2-beta + with: + node-version: "12" + + - name: Install Dependencies + run: yarn + + - name: Generate Cheat Sheet + run: yarn generate + + - name: Push New Cheat Sheet to Updated Branch + run: | + git diff --name-only --exit-code && exit 0 + git add README.md + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -m "docs(readme): update emoji-cheat-sheet" + git push -qf "https://${{ secrets.GITHUB_TOKEN }}@github.com/ikatyang/emoji-cheat-sheet.git" HEAD:github-actions-auto-update + + - name: Create PR from Updated Branch + uses: actions/github-script@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const {owner, repo} = context.repo + const branch = 'github-actions-auto-update' + const {status: branchStatus} = await github.repos.getBranch({ + owner, + repo, + branch, + }) + if (branchStatus !== 200) { + return + } + const {status, data: prs} = await github.pulls.list({ + owner, + repo, + head: branch, + state: 'open', + }) + if (status === 200 && prs.length === 0) { + await github.pulls.create({ + owner, + repo, + head: branch, + title: 'docs(readme): update emoji-cheat-sheet', + base: 'master', + }) + } diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 38acdb6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: node_js - -node_js: -- "12" - -script: -- yarn lint -- yarn test --ci - -cache: - yarn: true - directories: - - node_modules - -matrix: - fast_finish: true diff --git a/scripts/generate.test.js b/scripts/generate.test.js index 714e205..cb959cd 100644 --- a/scripts/generate.test.js +++ b/scripts/generate.test.js @@ -6,7 +6,7 @@ test("emoji-cheat-sheet", async () => { expect(await generate()).toMatchInlineSnapshot(` "# emoji-cheat-sheet - [![build](https://travis-ci.org/ikatyang/emoji-cheat-sheet.svg?branch=master)](https://travis-ci.org/ikatyang/emoji-cheat-sheet) + [![Up to Date](https://github.com/ikatyang/emoji-cheat-sheet/workflows/Up%20to%20Date/badge.svg)](https://github.com/ikatyang/emoji-cheat-sheet/actions?query=workflow%3A%22Up+to+Date%22) This cheat sheet is automatically generated from [GitHub Emoji API](https://api.github.com/emojis) and [Unicode Full Emoji List](https://unicode.org/emoji/charts/full-emoji-list.html). diff --git a/scripts/markdown.js b/scripts/markdown.js index c28e4fb..6692dce 100644 --- a/scripts/markdown.js +++ b/scripts/markdown.js @@ -22,7 +22,7 @@ function generateCheatSheet(categorizedGithubEmojiIds) { lineTexts.push(""); lineTexts.push( - `[![build](https://travis-ci.org/${repository}.svg?branch=master)](https://travis-ci.org/${repository})` + `[![Up to Date](https://github.com/${repository}/workflows/Up%20to%20Date/badge.svg)](https://github.com/${repository}/actions?query=workflow%3A%22Up+to+Date%22)` ); lineTexts.push("");