Skip to content

Commit

Permalink
💚 Fix workflow (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlaa authored Sep 18, 2024
1 parent d6fdfaf commit a251437
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 82 deletions.
74 changes: 0 additions & 74 deletions .github/workflows/pr-updater.yaml

This file was deleted.

66 changes: 58 additions & 8 deletions .github/workflows/upload-compilation-result.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generates an artifact containing the result of the `yarn compile` command.

name: Generate PR artifact
name: Generate compilation result

on:
pull_request:
Expand Down Expand Up @@ -77,13 +77,12 @@ jobs:
# 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) }}"

upload-artifact:
generate-comment:
runs-on: ubuntu-22.04
needs: compile
steps:
- name: Create artifact
run: |
mkdir -p artifacts
echo "
<h1 align="center">Report for the pull request #${{ github.event.pull_request.number }}</h2>
Expand Down Expand Up @@ -121,9 +120,60 @@ jobs:
</details>
" > artifacts/result.md
- name: Upload artifact
uses: actions/upload-artifact@v4
" > result.md
- name: Updating the PR
uses: actions/github-script@v6
with:
name: pr_message
path: artifacts
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}`);
}

0 comments on commit a251437

Please sign in to comment.