generated from railmapgen/seed-project
-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (117 loc) · 4.68 KB
/
issuebot.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Issue bot
on:
issues:
types: [opened, edited]
jobs:
updateGallery:
runs-on: ubuntu-latest
if: contains(github.event.issue.body, 'Paste or Upload below. They are meant for BOTS ONLY!!!')
outputs:
sanityCheck: ${{ steps.sanity_check.outputs.message }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.RMG_BUILD_AND_RELEASE }}
fetch-depth: 0 # Fetch all to get authors of every template.
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
working-directory: scripts
- name: Configure git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Save issue into a file
run: |
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/railmapgen/rmp-gallery/issues/${{ github.event.issue.number }} > $HOME/issue.json
env:
GH_TOKEN: ${{ github.token }}
- name: Sanity check
id: sanity_check
run: node --loader ts-node/esm ./sanity-check.ts
working-directory: scripts
- name: Setup firefox
uses: browser-actions/setup-firefox@v1
with:
firefox-version: latest
- name: Install Noto CJK fonts
run: sudo apt install -y fonts-noto-cjk
- name: Make metadata and images
run: node --loader ts-node/esm ./issuebot.ts
working-directory: scripts
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
USER_LOGIN: ${{ github.event.issue.user.login }}
USER_ID: ${{ github.event.issue.user.id }}
id: bot
- name: Make logins
run: |
node ./loginbot.js
git add ../public/resources/
git commit --amend --no-edit
working-directory: scripts
- name: Print diff and push
run: |
git --no-pager diff HEAD^ HEAD
git push --set-upstream origin bot-${{ github.event.issue.number }}
- name: pull-request-action
uses: vsoch/pull-request-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_PREFIX: "bot-"
PULL_REQUEST_FROM_BRANCH: bot-${{ github.event.issue.number }}
PULL_REQUEST_BRANCH: "main"
PULL_REQUEST_TOKEN: ${{ secrets.RMT_SVC }}
PULL_REQUEST_TITLE: ${{ github.event.issue.title }}
PULL_REQUEST_BODY: "Hi, I'm the rmp bot updating _${{ github.event.issue.title }}_ on behalf of @${{ github.event.issue.user.login }}.\nThis should fix #${{ github.event.issue.number }}"
- name: Add label
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labelsToAdd = ['resources'];
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labelsToAdd
});
updateIssueIfFailed:
runs-on: ubuntu-latest
needs: updateGallery
if: ${{ failure() && needs.updateGallery.outputs.sanityCheck != 'pass' && needs.updateGallery.outputs.sanityCheck != '' }}
steps:
- name: Comment if failed
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Thank you for your contribution. However, upon review, your work did not pass the sanity check due to the following reason:
- ${{ needs.updateGallery.outputs.sanityCheck }}
This issue will be closed, and no further actions will be taken. Please revise your work accordingly and resubmit it as a new issue.
- name: Add labels
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labelsToAdd = ['resources', 'need fixing'];
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labelsToAdd
});
- name: Close issue
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed',
state_reason: 'not_planned'
});