-
Notifications
You must be signed in to change notification settings - Fork 5
66 lines (50 loc) · 2.1 KB
/
gcloud-logging.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
# more details this workflow and other at https://github.com/didier-durand/gcloud-tests
name: Use GCP logging
on:
workflow_dispatch:
inputs:
push:
#protection to avoid triggering when other workflow is modified
paths:
- '!.github/workflows/**'
- '.github/workflows/gcloud-logging.yml'
schedule:
- cron: '0 4 * * MON'
env:
GCP_VERBOSITY: warning
GCP_TEST_LOG: gcp-test-log
jobs:
use-GCP-logging-services:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Setup gcloud CLI
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCP_PROJECT }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Get gcloud version & info
run: |-
echo '--- gcloud version ---'
gcloud version
echo '--- gcloud info ---'
gcloud info --anonymize
- name: List project active logs
run: |-
gcloud logging logs list --verbosity=$GCP_VERBOSITY --project=${{ secrets.GCP_PROJECT }} --quiet
- name: List logging resource descriptors
run: |-
gcloud logging resource-descriptors list --verbosity=$GCP_VERBOSITY --project=${{ secrets.GCP_PROJECT }} --quiet
- name: Write message to test log
run: |-
gcloud logging write $GCP_TEST_LOG "test log entry @ $(date) at Github revision $GITHUB_SHA" --verbosity=$GCP_VERBOSITY --project=${{ secrets.GCP_PROJECT }} --quiet
- name: Read test log message
# sleep 10s to give enough time for log message to be centralized in aggregate logging.
run: |-
sleep 10s
gcloud logging read --verbosity=$GCP_VERBOSITY --limit=1000 --order=desc --freshness=2m --project=${{ secrets.GCP_PROJECT }} --quiet
grep "textPayload:.*Github.*$GITHUB_SHA" <<< $(gcloud logging read --order=desc --freshness=2m --verbosity=$GCP_VERBOSITY --limit=1000 --project=${{ secrets.GCP_PROJECT }} --quiet)
- name: Delete test log
run: |-
gcloud logging logs delete $GCP_TEST_LOG --quiet