-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (76 loc) · 2.74 KB
/
merge-words.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
name: Validate and Merge Pull Request
on:
pull_request:
types: [opened, synchronize]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BOT_ACCESS_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
permissions:
contents: write
pull-requests: write
jobs:
merge:
runs-on: ubuntu-22.04
if: contains(github.event.pull_request.labels.*.name, 'mb-cli')
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Run Validation Script
id: validation
run: |
node ./.github/scripts/validation.js ./Sources/PhraseKit/Resources pending
- name: Commit Changes
if: success()
run: |
git config --global user.name "mb-actions[bot]"
git config --global user.email "[email protected]"
git add .
git commit -m "Auto-update JSON files after validation"
git pull origin ${{ github.event.pull_request.head.ref }} --rebase
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge Pull Request
if: success()
run: |
gh pr merge ${{ github.event.pull_request.number }} --admin --delete-branch --merge
env:
GITHUB_TOKEN: ${{ env.BOT_ACCESS_TOKEN }}
- name: Update PR (Success)
if: success()
uses: actions/github-script@v4
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const outputPath = 'validation_output.txt';
let output = '';
if (fs.existsSync(outputPath)) {
output = fs.readFileSync(outputPath, 'utf8');
} else {
output = 'No output generated from validation.';
}
github.pulls.createReview({
pull_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Word validation was successful with the following details:\n\`\`\`\n${output}\n\`\`\`\n`,
event: "COMMENT"
});
- name: Update PR (Failure)
if: failure()
uses: actions/github-script@v4
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
github.pulls.createReview({
pull_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Validation failed. Please check the details and make necessary changes.`,
event: "REQUEST_CHANGES"
});