Skip to content

Commit 4db842b

Browse files
committed
update
1 parent 4d46ccb commit 4db842b

File tree

2 files changed

+48
-105
lines changed

2 files changed

+48
-105
lines changed

.github/workflows/log-daily-pr-merges.yml

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Log merge group success
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
GOOGLE_APPLICATION_CREDENTIALS:
7+
required: true
8+
GOOGLE_SERVICE_ACCOUNT:
9+
required: true
10+
SPREADSHEET_ID:
11+
required: true
12+
SHEET_NAME:
13+
required: true
14+
workflow_dispatch:
15+
16+
jobs:
17+
log-merge-group-success:
18+
name: Log merge group success
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Download oauth2l
22+
run: |
23+
curl --silent https://storage.googleapis.com/oauth2l/1.3.2/linux_amd64.tgz | tar xz
24+
echo "$PWD/linux_amd64" >> "$GITHUB_PATH"
25+
26+
- name: Create service_account.json
27+
env:
28+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
29+
GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
30+
run: |
31+
echo "$GOOGLE_SERVICE_ACCOUNT" > "$GOOGLE_APPLICATION_CREDENTIALS"
32+
33+
- name: Write data to google sheets
34+
env:
35+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
36+
SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }}
37+
SHEET_NAME: ${{ secrets.SHEET_NAME }}
38+
run: |
39+
current_date=$(date +%Y-%m-%d)
40+
token=$(oauth2l fetch --scope https://www.googleapis.com/auth/spreadsheets)
41+
spreadsheet_data=$(curl --silent --header "Authorization: Bearer $token" https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C)
42+
current_date_index=$(echo "$spreadsheet_data" | jq --arg current_date "$current_date" '(.values | map(.[0])) | (index($current_date) | if . == null then null else . + 1 end)')
43+
current_number_of_successes=$(echo "$spreadsheet_data" | jq --arg current_date "$current_date" '(.values[] | select(.[0] == $current_date) | .[2] | tonumber) // null')
44+
if [ "$current_date_index" == "null" ]; then
45+
curl --silent --header "Authorization: Bearer $token" --header "Content-Type: application/json" --request POST --data "{\"values\":[[\"$current_date\", \"\", 1]]}" https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C:append?valueInputOption=USER_ENTERED
46+
else
47+
curl --silent --header "Authorization: Bearer $token" --header "Content-Type: application/json" --request PUT --data "{\"values\":[[\"$current_date\", \"\", $(("$current_number_of_successes" + 1))]]}" https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A"$current_date_index":C"$current_date_index"?valueInputOption=USER_ENTERED
48+
fi

0 commit comments

Comments
 (0)