-
Notifications
You must be signed in to change notification settings - Fork 126
116 lines (114 loc) · 4.71 KB
/
make_card_db_pr.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
name: Make Card DB PR
on:
workflow_run:
workflows:
- Compile Card DB
types:
- completed
jobs:
make_pr:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v3
- uses: actions/github-script@v6
id: get-artifact
with:
result-encoding: string
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "card_db"
});
if (matchArtifacts.length > 0) {
var matchArtifact = matchArtifacts[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/card_db.zip', Buffer.from(download.data));
return 'found_artifact';
} else {
return 'no_artifact'
}
- run: unzip -o -d src/domdiv/card_db card_db.zip
if: steps.get-artifact.outputs.result == 'found_artifact'
- run: rm -f card_db.zip
if: steps.get-artifact.outputs.result == 'found_artifact'
- name: 'Download PR number artifact'
if: steps.get-artifact.outputs.result == 'found_artifact'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: 'Unzip PR Number artifact'
if: steps.get-artifact.outputs.result == 'found_artifact'
run: unzip pr_number.zip
- name: 'Read PR number'
id: read-pr-number
if: steps.get-artifact.outputs.result == 'found_artifact'
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let fs = require('fs');
let pr_number = Number(fs.readFileSync('./pr_number'));
console.log(`original pr number: ${pr_number}`)
return pr_number
- name: Make PR
id: make-pr
if: steps.get-artifact.outputs.result == 'found_artifact'
uses: peter-evans/create-pull-request@v5
with:
title: 'Auto Card DB compile for #${{ steps.read-pr-number.outputs.result }}'
body: |
Auto-generate package card DB to from source card DB for PR #${{ steps.read-pr-number.outputs.result }}
delete-branch: true
reviewers: sumpfork
assignees: sumpfork
add-paths: |
src/domdiv/card_db/
- name: 'Comment on PR'
if: steps.get-artifact.outputs.result == 'found_artifact'
uses: actions/github-script@v6
env:
THIS_PR_NUMBER: ${{ steps.make-pr.outputs.pull-request-number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log(`new PR number: ${{ steps.make-pr.outputs.pull-request-number }}`)
console.log(process.env)
const { THIS_PR_NUMBER } = process.env
console.log(`new PR number: ${THIS_PR_NUMBER}`)
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./pr_number'));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: `It seems compiling the card DB on this PR produced changes.\n` +
`Ideally, please run "doit update-language" yourself on this PR and check in the results.\n` +
`Otherwise, PR #${THIS_PR_NUMBER} has the necessary (but unreviewed) changes.\n`
});