Update deploy-scan-results-to-github-pages.yml #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy-scan-results-to-GitHub-pages | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
env: | |
scan_index: 'scan-results/scan_index.json' | |
audit_file: 'gh-pages/index.json' | |
index: 'scan-results/index.json' | |
jobs: | |
build-and-deploy: | |
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession. | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set the time | |
run: | | |
echo "ACTION_START_TIME=$(date +%s)" >> $GITHUB_OUTPUT | |
id: run_tests | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Creating scan results | |
run: | | |
reportName='scan-results/result-${{steps.run_tests.outputs.ACTION_START_TIME}}.json' | |
cat | |
{ | |
echo '' | |
echo "<script>" | |
echo "const resultJson = " | |
echo "</script>" | |
echo "<script>" | |
echo "const createdAt = ${{steps.run_tests.outputs.ACTION_START_TIME}};" | |
echo "init();" | |
echo "</script>" | |
echo "</body>" | |
echo "</html>" | |
} >>"$reportName" | |
echo "$reportName has been created!" | |
- name: Storing push event details | |
id: store_event_details | |
run: | | |
PUSH_EVENT_DETAIL='event-${{steps.run_tests.outputs.ACTION_START_TIME}}.json' | |
echo "PUSH_EVENT_DETAIL=$PUSH_EVENT_DETAIL" >> $GITHUB_OUTPUT | |
cat ${{ github.event_path }}>>"scan-results/$PUSH_EVENT_DETAIL" | |
- name: Creating Scan Details | |
run: | | |
cat | |
{ | |
echo '{' | |
echo '"Id": "${{steps.run_tests.outputs.ACTION_START_TIME}}"' | |
echo '"Sha": "${{ github.sha }}"' | |
echo '"Initiator": "${{ github.triggering_actor }}"' | |
echo '"Ref": "${{ github.ref }}"' | |
echo '"Event_Name": "${{ github.event_name }}"' | |
echo '"Event_Path": "${{ steps.store_event_details.outputs.PUSH_EVENT_DETAIL }}"' | |
echo '},' | |
} >>"$scan_index" | |
echo "$scan_index has been created!" | |
- name: Checkout gh 🛎️ | |
uses: actions/checkout@v3 | |
with: | |
ref: gh-pages | |
path: gh-pages | |
- name: Adding Scan Details to Audit db | |
run: | | |
if [ ! -f $audit_file ]; then | |
echo "$audit_file doesn't exist, creating an empty one!" | |
cat | |
{ | |
echo '{' | |
echo '"Pushes" : [' | |
echo ']}' | |
} >>"$audit_file" | |
fi | |
# copy audit file except the last line which is '}' character of json | |
head -n -1 "$audit_file" > "$index" | |
cat "$scan_index" >>"$index" | |
cat | |
{ | |
echo '' | |
echo ']}' | |
} >>"$index" | |
echo "$index has been created!" | |
# remove tmp | |
rm -f $scan_index | |
- name: Deploy 🚀 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: scan-results | |
clean: false |