Skip to content
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

fix: GHA report #92

Merged
merged 15 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 26 additions & 38 deletions .github/workflows/daily_report_receipt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,38 @@ jobs:
- name: Run reports
shell: bash
run: |
export RECEIPTS_COSMOS_CONN_STRING='${{ secrets.RECEIPTS_COSMOS_CONN_STRING }}'

cd ./report
chmod +x ./run.sh
./run.sh local > report.md && grep ">" report.md > report.cp && mv report.cp report.md
export RECEIPTS_COSMOS_CONN_STRING='${{ secrets.RECEIPTS_COSMOS_CONN_STRING }}'

echo "REPORT_PDF=$(cat report.md)" >> $GITHUB_ENV
echo "CVE_MEDIUM=$(echo $SCAN_RESULTS | grep -o MEDIUM | wc -l)" >> $GITHUB_ENV
cd ./report
chmod +x ./run.sh
./run.sh local


debug_script:
needs: [ report_script ]
name: Debug Report ${{(github.event.inputs == null && 'prod') || inputs.environment }}
runs-on: [ self-hosted, "${{ needs.create_runner.outputs.runner_name }}" ]
environment: ${{(github.event.inputs == null && 'prod') || inputs.environment }}
steps:

- name: Debug reports
shell: bash
run: |
export RECEIPTS_COSMOS_CONN_STRING='${{ secrets.RECEIPTS_COSMOS_CONN_STRING }}'
# - name: Set the value in bash
# id: save-env-report
# run: |
# cd ./report
# {
# echo 'REPORT_PDF<<EOF'
# cat report.md
# echo EOF
# } >> "$GITHUB_ENV"

echo "Below 👇 PDF's daily report 🧾"
# - name: Debug reports
# shell: bash
# run: |
# echo ${{ env.REPORT_PDF }}

echo $REPORT_PDF

# notify:
# needs: [ create_runner, report_script ]
# runs-on: [ self-hosted, "${{ needs.create_runner.outputs.runner_name }}" ]
# name: Notify
# if: always()
# steps:
# - name: Report Status
# if: always()
# uses: ravsamhq/notify-slack-action@v2
# with:
# status: ${{ needs.integration_test.result }}
# token: ${{ secrets.GITHUB_TOKEN }}
# notify_when: 'failure,skipped'
# notification_title: "<{run_url}|Scheduled Integration Test> has {status_message} in ${{( github.event.inputs == null && 'uat') || inputs.environment }} env"
# message_format: '{emoji} <{run_url}|{workflow}> {status_message} in <{repo_url}|{repo}>'
# footer: 'Linked to <{workflow_url}| workflow file>'
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send notification to Slack
id: slack
if: always()
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 #v1.24.0
with:
payload-file-path: "./report/src/report.json"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

cleanup_runner:
name: Cleanup Runner
Expand Down
29 changes: 24 additions & 5 deletions report/src/utils/report.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('fs');

const { getReceiptsStatusCount } = require("./utils");

// const from = "2023-11-23T00:00:00";
Expand Down Expand Up @@ -58,9 +60,26 @@ const dictionary = {
"NOT_TO_NOTIFY" : "🟢"
}

console.log(`> Report receipt of ${yesterday_}`);
res.then(function(result) {
console.log(result.resources.forEach(e => {
console.log(`> ${dictionary[e.status]} ${e.num.toString().padEnd(8, ' ')}\t ${e.status} `);
}))

// let report_ = '{"title":"","detail":[]}'
let report_ = '{"text":""}'

report=JSON.parse(report_);

report.text = `Report 📈 receipt 🧾 of ${yesterday_} 🧐\n`
let p = res.then(function(result) {
// console.log(result.resources.forEach(e => {
// console.log(`> ${dictionary[e.status]} ${e.num.toString().padEnd(8, ' ')}\t ${e.status} `);
// }))
let index = 0;
result.resources.forEach(e => {
// report["detail"].push( {"status": `${dictionary[e.status]} ${e.status}`, "num":`${e.num}` });
report.text+=`${dictionary[e.status]} ${e.num.toString().padEnd(8, ' ')}\t ${e.status} \n`
})

console.log(JSON.stringify(report));
fs.writeFileSync('report.json', JSON.stringify(report));


})

Loading