-
Notifications
You must be signed in to change notification settings - Fork 70
179 lines (148 loc) · 6.61 KB
/
upload-compilation-result.yaml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Generates an artifact containing the result of the `yarn compile` command.
name: Generate compilation result
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- '!master'
jobs:
compile:
runs-on: ubuntu-22.04
outputs:
check-translation-result: ${{ steps.check-translation.outputs.result }}
check-personas-result: ${{ steps.check-personas.outputs.result }}
test-personas-nightly-result: ${{ steps.test-personas-nightly.outputs.result }}
test-personas-latest-result: ${{ steps.test-personas-latest.outputs.result }}
test-url: ${{ steps.set-test-url.outputs.fr }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- run: yarn install --immutable
- run: git log | head && git status
- id: compilation
name: Compile
run: yarn compile
- id: check-translation
name: Checks the rules translation
run: |
yarn check:rules --markdown > check-rules.res
body="$(cat check-rules.res | tail --lines=+3 | head --lines=-1)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=result::${body}"
- id: check-personas
name: Checks the personas translation
run: |
yarn check:personas --markdown > check-personas.res
body="$(cat check-personas.res | tail --lines=+3 | head --lines=-1)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=result::${body}"
- id: test-optim
name: Test the optimized rules against base rules
run: yarn test:optim
- id: test-translation
name: Test the translated rules against production
run: yarn test:translation
- id: test-personas-latest
name: Test the personas bilans against production
run: |
yarn test:personas --markdown -v latest > test-personas-latest.res
body="$(cat test-personas-latest.res | tail --lines=+3 | head --lines=-1)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=result::${body}"
- id: test-personas-nightly
name: Test the personas bilans against develop
run: |
yarn test:personas --markdown -v nightly > test-personas-nightly.res
body="$(cat test-personas-nightly.res | tail --lines=+3 | head --lines=-1)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=result::${body}"
- id: set-test-url
# Setups the NGC url with the corresponding PR number: https://nosgestesclimat.fr?PR=<pr_number>
run: echo "::set-output name=fr::${{ steps.deploy-env.outputs.name == 'master' && 'https://preprod.nosgestesclimat.fr' || format('https://preprod.nosgestesclimat.fr?PR={0}', github.event.pull_request.number) }}"
generate-comment:
runs-on: ubuntu-22.04
needs: compile
steps:
- name: Create artifact
run: |
echo "
<h1 align="center">Report for the pull request #${{ github.event.pull_request.number }}</h2>
<p align="center">:rocket: Test the model from the website: <a href=\"${{ needs.compile.outputs.test-url }}\">${{ needs.compile.outputs.test-url }}</a></p>
## :globe_with_meridians: Translation status
> _You will find more information about the translation in our [wiki](https://accelerateur-transition-ecologique-ademe.notion.site/Traduction-mod-le-5634c26ccf9b4d1e90840626227ca077?pvs=4)._
### Rules
${{ needs.compile.outputs.check-translation-result }}
### Personas
${{ needs.compile.outputs.check-personas-result }}
## :couple: Personas changes
### Test personas bilans against [preprod](https://nosgestesclimat-api.osc-fr1.scalingo.io/nightly/fr/FR/rules)
<details open=true>
<summary>In details</summary>
${{ needs.compile.outputs.test-personas-nightly-result }}
</details>
### Test personas bilans against [production](https://nosgestesclimat-api.osc-fr1.scalingo.io/latest/fr/FR/rules)
<details>
<summary>Show</summary>
${{ needs.compile.outputs.test-personas-latest-result }}
</details>
" > result.md
- name: Updating the PR
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const {owner, repo} = context.repo;
const pull_requests = await github.rest.pulls.list(context.repo);
if (!pull_requests.data.length) {
return core.error("Currently, there is no open PR.");
}
core.info('Found ' + pull_requests.data.length + ' PR');
const triggered_pr = context.payload.pull_request;
if (!triggered_pr) {
return core.error('The corresponding PR could not be found.');
}
core.info('Found the corresponding PR: #' + triggered_pr.number);
const marker = 'yarn-compile-result';
if (!fs.existsSync('result.md')) {
return core.info("Cannot find 'result.md', skipping")
}
var body = '<!-- bot: ' + marker + ' -->\n' + fs.readFileSync('result.md', 'utf8');
const issue_number = triggered_pr.number;
const comments = await github.rest.issues.listComments({owner, repo, issue_number});
const existing = comments.data.filter((c) => c.body.includes(marker));
try {
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info('Updating the comment ' + last.id);
await github.rest.issues.updateComment({
owner,
repo,
body,
comment_id: last.id,
});
} else {
core.info('Creating a comment in the PR #' + issue_number);
await github.rest.issues.createComment({
issue_number,
body,
owner,
repo
});
}
core.info('PR comment updated/created successfully');
} catch (error) {
core.setFailed(`Error updating PR comment: ${error.message}`);
}