Add diff action

This commit is contained in:
simurai 2021-09-28 16:51:39 +09:00
parent 916b00c28b
commit 31c47d818f
2 changed files with 105 additions and 0 deletions

5
.github/diff_comment_template.md vendored Normal file
View File

@ -0,0 +1,5 @@
<details>
<summary><strong>Colors changed</strong></summary>
<!-- diff --><!-- /diff -->
</details>

100
.github/workflows/diff.yml vendored Normal file
View File

@ -0,0 +1,100 @@
# Posts a comment listing all the colors that changed in a PR
name: Diff
on:
pull_request:
branches-ignore:
- 'test/**'
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Create comment (if necessary)
uses: actions/github-script@v5
with:
script: |
const fs = require('fs')
const body = fs.readFileSync('.github/diff_comment_template.md', 'utf8')
const result = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(result.data)
const botComments = result.data.filter(c => c.user.login === 'github-actions[bot]')
if (!botComments.length) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
diff:
needs: comment
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout base branch
uses: actions/checkout@v2
with:
ref: ${{ github.base_ref }}
path: base
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Install dependencies (base)
run: pushd base; yarn; popd
- name: Build (base)
run: pushd base; yarn build; popd
- name: Diff
uses: primer/comment-token-update@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: github-actions[bot]
with:
# This action will find the first comment by `github-actions[bot]` and
# insert the diff data if `<!-- diff --><!-- /diff -->` is present in that comment.
# If there are multiple comments by `github-actions[bot]`
# or if `<!-- diff --><!-- /diff -->` is missing,
# this action may not work as expected.
comment-token: 'diff'
script: |
diff=$(for file in themes/**/*.json
do
# using `2> /dev/null || true` here to suppress errors because,
# in this case, differences are not errors
diff -U 1 base/$file $file 2> /dev/null || true
done)
echo "\`\`\`diff"
if [[ $diff ]]
then
echo "$diff"
else
echo "No colors changed"
fi
echo "\`\`\`"