-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed printing of simulation results #397
Changes from 1 commit
cc897df
3901421
6169fef
f6f84f2
a347cb6
b7dcb8f
50e7551
a202d2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,8 +20,7 @@ jobs: | |||||||||||
run: | | ||||||||||||
echo "AGENT_VERSION=${AGENT_VERSION}" | ||||||||||||
echo "COMPOSE_FILE=${COMPOSE_FILE}" | ||||||||||||
- name: 'Download artifact (PR ID)' | ||||||||||||
if: github.event_name == 'pull_request' | ||||||||||||
- name: Download artifact | ||||||||||||
uses: actions/github-script@v6 | ||||||||||||
with: | ||||||||||||
script: | | ||||||||||||
|
@@ -31,10 +30,10 @@ jobs: | |||||||||||
run_id: context.payload.workflow_run.id, | ||||||||||||
}); | ||||||||||||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | ||||||||||||
return artifact.name == "pr_id" | ||||||||||||
return artifact.name == "artifact.json" | ||||||||||||
})[0]; | ||||||||||||
if (!matchArtifact) { | ||||||||||||
core.setFailed('No pr_id artifact found from the build workflow'); | ||||||||||||
core.setFailed('No artifact found from the build workflow'); | ||||||||||||
return; | ||||||||||||
} | ||||||||||||
let download = await github.rest.actions.downloadArtifact({ | ||||||||||||
|
@@ -44,23 +43,20 @@ jobs: | |||||||||||
archive_format: 'zip', | ||||||||||||
}); | ||||||||||||
let fs = require('fs'); | ||||||||||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_id.zip`, Buffer.from(download.data)); | ||||||||||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data)); | ||||||||||||
|
||||||||||||
- name: 'Unzip artifact (PR ID)' | ||||||||||||
if: github.event_name == 'pull_request' | ||||||||||||
- name: Unzip artifact | ||||||||||||
run: | | ||||||||||||
unzip pr_id.zip | ||||||||||||
unzip artifact.zip | ||||||||||||
|
||||||||||||
- name: Check PR ID | ||||||||||||
if: github.event_name == 'pull_request' | ||||||||||||
- name: Return artifact JSON | ||||||||||||
id: return-artifact-json | ||||||||||||
uses: actions/github-script@v6 | ||||||||||||
with: | ||||||||||||
script: | | ||||||||||||
let issue_number = fs.readFileSync('./pr_id'); | ||||||||||||
if (!issue_number || isNaN(Number(issue_number))) { | ||||||||||||
core.setFailed(`Invalid PR ID: ${prIdContent}`); | ||||||||||||
return; | ||||||||||||
} | ||||||||||||
let fs = require('fs'); | ||||||||||||
let data = JSON.parse(fs.readFileSync('./artifacts/artifacts.json')); | ||||||||||||
return data; | ||||||||||||
|
||||||||||||
- name: Run docker-compose | ||||||||||||
run: | | ||||||||||||
|
@@ -73,12 +69,10 @@ jobs: | |||||||||||
if: always() | ||||||||||||
run: docker compose down -v | ||||||||||||
# add rendered JSON as comment to the pull request | ||||||||||||
- name: Add simulation results as comment | ||||||||||||
if: github.event_name == 'pull_request' | ||||||||||||
- name: Create simulation results table | ||||||||||||
id: simulation-results | ||||||||||||
uses: actions/github-script@v6 | ||||||||||||
with: | ||||||||||||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||
# this script reads the simulation_results.json and creates a comment on the pull request with the results. | ||||||||||||
script: | | ||||||||||||
const fs = require('fs'); | ||||||||||||
// read the simulation results | ||||||||||||
|
@@ -94,13 +88,26 @@ jobs: | |||||||||||
let resultsTableDivider = `| --- | --- |`; | ||||||||||||
// add everything to the resultsTable | ||||||||||||
resultsTable = resultsTableHeader + '\n' + resultsTableDivider + '\n' + resultsTable.join('\n'); | ||||||||||||
return resultsTable; | ||||||||||||
result-encoding: string | ||||||||||||
- name: Print simulation results | ||||||||||||
run: | | ||||||||||||
echo "Simulation results\n" | ||||||||||||
echo "${{ steps.simulation-results.outputs.result }}" | ||||||||||||
Comment on lines
+94
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix echo command to properly handle escape sequences. The current echo command may not properly expand the newline character. Update the command to use printf: - echo "Simulation results\n"
- echo "${{ steps.simulation-results.outputs.result }}"
+ printf "Simulation results\n\n%s\n" "${{ steps.simulation-results.outputs.result }}" 📝 Committable suggestion
Suggested change
🧰 Tools🪛 actionlint94-94: shellcheck reported issue in this script: SC2028:info:1:6: echo may not expand escape sequences. Use printf (shellcheck) |
||||||||||||
- name: Add simulation results as comment | ||||||||||||
if: ${{ steps.return-artifact-json.outputs.result.is_pr }} | ||||||||||||
uses: actions/github-script@v6 | ||||||||||||
with: | ||||||||||||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||
# this script reads the simulation_results.json and creates a comment on the pull request with the results. | ||||||||||||
script: | | ||||||||||||
let issue_number = Number(${{ steps.return-artifact-json.outputs.pr_id }}); | ||||||||||||
// add the results as a comment to the pull request | ||||||||||||
let issue_number = Number(fs.readFileSync('./pr_id')); | ||||||||||||
github.rest.issues.createComment({ | ||||||||||||
issue_number: issue_number, | ||||||||||||
owner: context.repo.owner, | ||||||||||||
repo: context.repo.repo, | ||||||||||||
body: "## Simulation results\n" + resultsTable | ||||||||||||
body: "## Simulation results\n" + ${{ steps.simulation-results.outputs.result }} | ||||||||||||
}); | ||||||||||||
- name: Prune all images older than 30 days from self-hosted runner | ||||||||||||
run: docker image prune -a --force --filter "until=720h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix shell script to properly expand environment variable.
The logic is correct, but there's a potential issue with variable expansion due to single quotes.
Apply this fix to ensure proper variable expansion:
📝 Committable suggestion
🧰 Tools
🪛 actionlint
99-99: shellcheck reported issue in this script: SC2016:info:2:8: Expressions don't expand in single quotes, use double quotes for that
(shellcheck)