generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (136 loc) · 5.29 KB
/
daily_report_receipt.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: ReportPdf
on:
schedule:
- cron: '00 05 * * MON'
workflow_dispatch:
inputs:
environment:
required: true
type: choice
description: Select the Environment
options:
- dev
- uat
- prod
default: prod
time_range:
required: true
type: choice
description: Select the Time Range
options:
- daily
- weekly
- dozen
- monthly
- custom
default: weekly
custom_start_date:
required: false
type: number
description: Start date for custom range in millis
custom_end_date:
required: false
type: number
description: End date for custom range in millis
notify:
description: 'notify report results'
required: false
type: boolean
default: true
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: "latest"
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_ENDPOINT=${{ secrets.RECEIPTS_COSMOS_ENDPOINT }}
export RECEIPTS_COSMOS_KEY=${{ secrets.RECEIPTS_COSMOS_KEY }}
export RECEIPTS_COSMOS_TIMEOUT=${{ secrets.RECEIPTS_COSMOS_TIMEOUT }}
export BIZ_COSMOS_ENDPOINT=${{ secrets.BIZ_COSMOS_ENDPOINT }}
export BIZ_COSMOS_KEY=${{ secrets.BIZ_COSMOS_KEY }}
export BIZ_COSMOS_TIMEOUT=${{ secrets.BIZ_COSMOS_TIMEOUT }}
export DATE_RANGE=${{(github.event.inputs == null && 'weekly') || inputs.time_range }}
export CUSTOM_START_DATE=${{(github.event.inputs == null && '0') || inputs.custom_start_date }}
export CUSTOM_END_DATE=${{(github.event.inputs == null && '0') || inputs.custom_end_date }}
cd ./report
chmod +x ./run.sh
./run.sh local
# - name: Set the value in bash
# id: save-env-report
# run: |
# cd ./report
# {
# echo 'REPORT_PDF<<EOF'
# cat report.md
# echo EOF
# } >> "$GITHUB_ENV"
# - name: Debug reports
# shell: bash
# run: |
# echo ${{ env.REPORT_PDF }}
- name: Send notification to Slack
id: slack
if: ${{ (success() || failure()) && (github.event.inputs == null || inputs.notify)}}
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
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 }}