-
Notifications
You must be signed in to change notification settings - Fork 19
65 lines (61 loc) · 2.24 KB
/
prune_previews.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
name: Prune Previews
on:
push:
paths:
- '.github/workflows/prune_previews.yml'
schedule:
- cron: '05 2 * * *'
jobs:
remove:
name: Remove Stale Previews
runs-on: ubuntu-latest
steps:
- name: Find PRs
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CROSSBOW_DOCS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CROSSBOW_DOCS_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET_REGION }}
BUCKET: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET }}
run: |
echo "PRs=$(aws s3 ls $BUCKET/pr_docs/ | sed 's/PRE//g' | tr -d '/' | tr '\n' ' ')" >> $GITHUB_ENV
- name: Find open PRs
uses: actions/github-script@v5
id: find
with:
script: |
let prs = "${{ env.PRs }}".split(" ").filter(x => x)
async function not_open(id) {
let pr;
try {
pr = await github.rest.pulls.get({
"owner": "apache",
"repo": "arrow",
"pull_number": id
})
}
catch(err) {
//In case of error retrieving PR try to clean it.
//Example manually triggered job with different naming.
return(id)
}
if(pr.data.state !== "open") {
return(id)
}
return("")
}
let del_prs = await Promise.all(prs.map(not_open))
del_prs = del_prs.filter(x => x).join(" ")
console.log(`::set-output name=del_prs::${del_prs}`)
- name: Delete Dirs and Commit
if: steps.find.outputs.del_prs != ''
env:
pr_ids: ${{ steps.find.outputs.del_prs }}
AWS_ACCESS_KEY_ID: ${{ secrets.CROSSBOW_DOCS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CROSSBOW_DOCS_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET_REGION }}
BUCKET: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET }}
run: |
for id in ${pr_ids[@]}
do
aws s3 rm $BUCKET/pr_docs/$id --recursive
done