ReportPdf #2
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: ReportPdf | |
on: | |
schedule: | |
- cron: '00 05 * * *' | |
workflow_dispatch: | |
inputs: | |
environment: | |
required: true | |
type: choice | |
description: Select the Environment | |
options: | |
- dev | |
- uat | |
- prod | |
default: prod | |
permissions: | |
id-token: write | |
contents: read | |
deployments: write | |
jobs: | |
create_runner: | |
name: Create Runner | |
runs-on: ubuntu-22.04 | |
environment: | |
name: ${{(github.event.inputs == null && 'prod') || inputs.environment }} | |
outputs: | |
runner_name: ${{ steps.create_github_runner.outputs.runner_name }} | |
steps: | |
- name: Create GitHub Runner | |
id: create_github_runner | |
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-create-action | |
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-create-action@main | |
with: | |
client_id: ${{ secrets.CLIENT_ID }} | |
tenant_id: ${{ secrets.TENANT_ID }} | |
subscription_id: ${{ secrets.SUBSCRIPTION_ID }} | |
container_app_environment_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_NAME }} | |
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} # RG of the runner | |
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }} | |
# self_hosted_runner_image_tag: "v1.6.0" | |
report_script: | |
needs: [ create_runner ] | |
name: 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: Checkout | |
id: checkout | |
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 | |
- name: Login | |
id: login | |
# from https://github.com/Azure/login/commits/master | |
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 | |
with: | |
client-id: ${{ secrets.CLIENT_ID }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
subscription-id: ${{ secrets.SUBSCRIPTION_ID }} | |
- 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 | |
echo "REPORT_PDF=$(cat report.md)" >> $GITHUB_ENV | |
echo "CVE_MEDIUM=$(echo $SCAN_RESULTS | grep -o MEDIUM | wc -l)" >> $GITHUB_ENV | |
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 }}' | |
echo "Below 👇 PDF's daily report 🧾" | |
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 }} | |
cleanup_runner: | |
name: Cleanup Runner | |
needs: [ create_runner, report_script ] | |
if: ${{ always() }} | |
runs-on: ubuntu-22.04 | |
environment: ${{(github.event.inputs == null && 'uat') || inputs.environment }} | |
steps: | |
- name: Cleanup GitHub Runner | |
id: cleanup_github_runner | |
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-cleanup-action | |
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-cleanup-action@0ee2f58fd46d10ac7f00bce4304b98db3dbdbe9a | |
with: | |
client_id: ${{ secrets.CLIENT_ID }} | |
tenant_id: ${{ secrets.TENANT_ID }} | |
subscription_id: ${{ secrets.SUBSCRIPTION_ID }} | |
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} | |
runner_name: ${{ needs.create_runner.outputs.runner_name }} | |
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }} |