-
Notifications
You must be signed in to change notification settings - Fork 24
155 lines (132 loc) · 5.21 KB
/
gen-killed-in-gaza.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
on:
workflow_dispatch:
push:
branches:
- "**"
- "!main"
paths:
- "scripts/data/common/killed-in-gaza/**"
- "scripts/data/v2/killed-in-gaza.ts"
- ".github/workflows/gen-killed-in-gaza.yml"
jobs:
datasets_gen_killed:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: checkout main for diff
run: |
git fetch origin main --depth 1
- uses: oven-sh/setup-bun@v1
name: setup bun
with:
bun-version: 1.0.22
- name: install dependencies
run: bun install
- name: sort dict csvs
run: |
bun run sort-list-csvs scripts/data/common/killed-in-gaza/data/dict_ar_en.csv
bun run sort-list-csvs scripts/data/common/killed-in-gaza/data/dict_ar_ar.csv
- name: run scripts & diff
run: |
bun run scripts/data/common/killed-in-gaza/generate_killed_list.ts
mkdir -p ci-tmp
bun run gen-killed
git diff origin/main:killed-in-gaza.json killed-in-gaza.json > ci-tmp/killed-in-gaza-json.diff
- name: upload debug artifacts
uses: actions/upload-artifact@v4
with:
name: GAZA-LIST-REVIEW-ITEMS
path: ci-tmp/*
- uses: EndBug/add-and-commit@v9 # You can change this to use a specific version.
name: commit changes
id: commit
with:
message: "killed-in-gaza: json update"
add: '["killed-in-gaza.json", "killed-in-gaza.min.json", "scripts/data/common/killed-in-gaza/data/**"]'
push: true
- name: create & upload derived API resources artifact
run: bun run gen-derived
env:
TFP_SHEET_KEY: ${{ secrets.TFP_SHEET_KEY }}
- uses: 8BitJonny/gh-get-current-pr@3.0.0
id: PR
with:
github-token: ${{ github.token }}
sha: ${{ github.event.pull_request.head.sha }}
filterOutClosed: true
filterOutDraft: false
- name: build report
id: report
run: |
# if our log output has lines there's issues worth noting
if [[ $(wc -l <ci-tmp/killed-in-gaza-log.txt) -ge 2 ]]; then
echo "logs=1" >> "$GITHUB_OUTPUT"
fi
if [[ $(wc -l <ci-tmp/killed-in-gaza-json.diff) -ge 1 ]]; then
echo "diff=1" >> "$GITHUB_OUTPUT"
fi
- uses: actions/github-script@v7
if: steps.PR.outputs.pr_found == 'true'
name: add pr comment
env:
COMMITTED: ${{ steps.commit.outputs.committed }}
HASLOGS: ${{ steps.report.outputs.logs }}
HASDIFF: ${{ steps.report.outputs.diff }}
PRNUM: ${{ steps.PR.outputs.number }}
with:
script: |
let body = ''
const changesStart = '✅'
const missStart = '💨'
if (process.env.COMMITTED === 'true') {
body += `${changesStart} The JSON build scripts ran and produced JSON changes, please review them.\n\n`
} else {
body += `${missStart} The JSON build scripts ran and did not produce any changes to commit.\n\n`
}
if (process.env.HASLOGS || process.env.HASDIFF) {
body += `The CI workflow artifacts have items you can [download and review](https://github.com/TechForPalestine/palestine-datasets/actions/runs/${context.runId}):\n`
}
if (process.env.HASLOGS) {
body += '- [ ] logs detailing potential issues to resolve\n'
}
if (process.env.HASDIFF) {
body += '- [ ] a diff of the JSON file changes for review\n'
}
const commonInputs = {
issue_number: process.env.PRNUM,
owner: context.repo.owner,
repo: context.repo.repo
}
// delete prior comments
const comments = await github.rest.issues.listComments(commonInputs)
const idsToDelete = comments.data
.filter(comment => comment.user.login.includes('github-action'))
.map(comment => comment.id)
// check if a recent commit had changes to review
let recentChanges = false
const lastCommentBody = comments.data
.sort((a, b) => b.created_at.localeCompare(a.created_at))[0]?.body ?? ''
if (lastCommentBody.startsWith(changesStart)) {
recentChanges = true
}
if (recentChanges && body.startsWith(missStart)) {
console.log('skipping comment, recent changes')
return; // keep last comment if commit leads to no change
}
console.log(`found ${idsToDelete.length} comments to delete: ${idsToDelete.join(',')}`)
if (idsToDelete.length) {
await idsToDelete.reduce(async (chain, comment_id) => {
await chain;
await github.rest.issues.deleteComment({
...commonInputs,
comment_id
})
}, Promise.resolve())
}
await github.rest.issues.createComment({
...commonInputs,
body
})