|
| 1 | +name: Log merge group failure |
| 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-failure: |
| 18 | + name: Log merge group failure |
| 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:B) |
| 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_prs=$(echo "$spreadsheet_data" | jq --arg current_date "$current_date" '(.values[] | select(.[0] == $current_date) | .[1] | 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:A: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_prs" + 1))]]}" https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A"$current_date_index":B"$current_date_index"?valueInputOption=USER_ENTERED |
| 48 | + fi |
0 commit comments