-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
39 lines (36 loc) · 1.48 KB
/
action.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
name: 'Cloudflare log fetcher'
description: 'Fetches Cloudflare deployment logs and prints with PR'
inputs:
cf_account_id:
description: 'Cloudflare account id'
required: true
cf_project:
description: 'Cloudflare project name'
required: true
cf_token:
description: 'Cloudflare API Token'
required: true
runs:
using: "composite"
steps:
- name: 'Setup jq'
uses: dcarbone/install-jq-action@v2
- name: Get Deployment Bot Comments
id: deployment-id
shell: bash
run: |
COMMENTS='${{ github.event.comment.body }}'
LOGID=$(echo $COMMENTS | grep -Eo "(http|https)://[a-zA-Z0-9./]*(${{inputs.cf_project}})+" | sort -u | awk -F/ '{print $3}' | awk -F. '{print $1}')
echo "LOGID: $LOGID"
echo "LOGID=$LOGID" >> $GITHUB_OUTPUT
if [ -z "$LOGID" ]; then
echo "Cloudflare deployment id is empty or not found. Exiting."
exit 1
fi
- name: Fetch and print logs
shell: bash
run: |
curl --request GET --url "https://api.cloudflare.com/client/v4/accounts/${{inputs.cf_account_id}}/pages/projects/${{inputs.cf_project}}/deployments/${{steps.deployment-id.LOGID}}/history/logs" --header "Authorization: Bearer ${{ inputs.cf_token }}" -o logs.json
echo '--------- START LOGS ---------------'
cat logs.json | jq -r '.result.data | sort_by(.ts)[] | .line' | while IFS= read -r line; do echo -e "$line"; done
echo '--------- END LOGS ---------------'