From 4a81fbd616e73c114de5b0c32a215c8a957d49de Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 23 Jun 2025 08:43:42 +0200 Subject: [PATCH 1/4] daily merged prs --- .github/workflows/log-daily-pr-merges.yml | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/log-daily-pr-merges.yml diff --git a/.github/workflows/log-daily-pr-merges.yml b/.github/workflows/log-daily-pr-merges.yml new file mode 100644 index 00000000..3a430098 --- /dev/null +++ b/.github/workflows/log-daily-pr-merges.yml @@ -0,0 +1,105 @@ +name: Log number of daily merged PRs + +on: + schedule: + # Run daily at midnight UTC to get the previous day's data + - cron: '0 0 * * *' + workflow_call: + secrets: + GOOGLE_APPLICATION_CREDENTIALS: + required: true + GOOGLE_SERVICE_ACCOUNT: + required: true + SPREADSHEET_ID: + required: true + SHEET_NAME: + required: true + GITHUB_TOKEN: + required: true + workflow_dispatch: + +jobs: + log-daily-pr-merges: + name: Log number of daily merged PRs + runs-on: ubuntu-latest + steps: + - name: Download oauth2l + run: | + curl --silent https://storage.googleapis.com/oauth2l/1.3.2/linux_amd64.tgz | tar xz + echo "$PWD/linux_amd64" >> "$GITHUB_PATH" + + - name: Create service_account.json + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} + run: | + echo "$GOOGLE_SERVICE_ACCOUNT" > "$GOOGLE_APPLICATION_CREDENTIALS" + + - name: Get yesterday's date + id: yesterday + run: | + # Get yesterday's date in YYYY-MM-DD format + YESTERDAY=$(date -d "yesterday" +%Y-%m-%d) + echo "yesterday=$YESTERDAY" >> $GITHUB_OUTPUT + echo "Yesterday's date: $YESTERDAY" + + - name: Count PRs merged yesterday + id: count_prs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get the repository name from GITHUB_REPOSITORY + REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2) + echo "Repository: $REPO_NAME" + + # Count PRs merged yesterday into main branch + # Using GitHub API to search for PRs merged on yesterday's date + YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" + + # Search for PRs merged yesterday + PR_COUNT=$(curl --silent \ + --header "Authorization: token $GITHUB_TOKEN" \ + --header "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/search/issues?q=repo:$GITHUB_REPOSITORY+is:pr+is:merged+merged:$YESTERDAY..$YESTERDAY+base:main" \ + | jq '.total_count') + + echo "PRs merged yesterday: $PR_COUNT" + echo "pr_count=$PR_COUNT" >> $GITHUB_OUTPUT + + - name: Write data to google sheets + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }} + SHEET_NAME: ${{ secrets.SHEET_NAME }} + run: | + YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" + PR_COUNT="${{ steps.count_prs.outputs.pr_count }}" + + # Get OAuth token + token=$(oauth2l fetch --scope https://www.googleapis.com/auth/spreadsheets) + + # Read existing data to check if yesterday's row exists + spreadsheet_data=$(curl --silent --header "Authorization: Bearer $token" \ + https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C) + + # Check if yesterday's date exists in column A + current_date_index=$(echo "$spreadsheet_data" | jq --arg yesterday "$YESTERDAY" \ + '(.values | map(.[0])) | (index($yesterday) | if . == null then null else . + 1 end)') + + if [ "$current_date_index" == "null" ]; then + # Date doesn't exist, append new row with PR count in column C + curl --silent --header "Authorization: Bearer $token" \ + --header "Content-Type: application/json" \ + --request POST \ + --data "{\"values\":[[\"$YESTERDAY\", \"\", $PR_COUNT]]}" \ + https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C:append?valueInputOption=USER_ENTERED + echo "Added new row for $YESTERDAY with $PR_COUNT PRs merged" + else + # Date exists, update column C with PR count + curl --silent --header "Authorization: Bearer $token" \ + --header "Content-Type: application/json" \ + --request PUT \ + --data "{\"values\":[[$PR_COUNT]]}" \ + https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!C"$current_date_index":C"$current_date_index"?valueInputOption=USER_ENTERED + echo "Updated row $current_date_index for $YESTERDAY with $PR_COUNT PRs merged" + fi \ No newline at end of file From c856333f0ef6d51e437b26259ac3470252ca2abf Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 23 Jun 2025 08:47:35 +0200 Subject: [PATCH 2/4] lint fix --- .github/workflows/log-daily-pr-merges.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/log-daily-pr-merges.yml b/.github/workflows/log-daily-pr-merges.yml index 3a430098..c9ef2161 100644 --- a/.github/workflows/log-daily-pr-merges.yml +++ b/.github/workflows/log-daily-pr-merges.yml @@ -51,18 +51,18 @@ jobs: # Get the repository name from GITHUB_REPOSITORY REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2) echo "Repository: $REPO_NAME" - + # Count PRs merged yesterday into main branch # Using GitHub API to search for PRs merged on yesterday's date YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" - + # Search for PRs merged yesterday PR_COUNT=$(curl --silent \ --header "Authorization: token $GITHUB_TOKEN" \ --header "Accept: application/vnd.github.v3+json" \ "https://api.github.com/search/issues?q=repo:$GITHUB_REPOSITORY+is:pr+is:merged+merged:$YESTERDAY..$YESTERDAY+base:main" \ | jq '.total_count') - + echo "PRs merged yesterday: $PR_COUNT" echo "pr_count=$PR_COUNT" >> $GITHUB_OUTPUT @@ -74,18 +74,18 @@ jobs: run: | YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" PR_COUNT="${{ steps.count_prs.outputs.pr_count }}" - + # Get OAuth token token=$(oauth2l fetch --scope https://www.googleapis.com/auth/spreadsheets) - + # Read existing data to check if yesterday's row exists spreadsheet_data=$(curl --silent --header "Authorization: Bearer $token" \ https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C) - + # Check if yesterday's date exists in column A current_date_index=$(echo "$spreadsheet_data" | jq --arg yesterday "$YESTERDAY" \ '(.values | map(.[0])) | (index($yesterday) | if . == null then null else . + 1 end)') - + if [ "$current_date_index" == "null" ]; then # Date doesn't exist, append new row with PR count in column C curl --silent --header "Authorization: Bearer $token" \ @@ -102,4 +102,4 @@ jobs: --data "{\"values\":[[$PR_COUNT]]}" \ https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!C"$current_date_index":C"$current_date_index"?valueInputOption=USER_ENTERED echo "Updated row $current_date_index for $YESTERDAY with $PR_COUNT PRs merged" - fi \ No newline at end of file + fi From 4d46ccb113da0aa7c8fa7c35e03cb16b9e442c77 Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 23 Jun 2025 08:52:58 +0200 Subject: [PATCH 3/4] more lint --- .github/workflows/log-daily-pr-merges.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/log-daily-pr-merges.yml b/.github/workflows/log-daily-pr-merges.yml index c9ef2161..7c48a7ac 100644 --- a/.github/workflows/log-daily-pr-merges.yml +++ b/.github/workflows/log-daily-pr-merges.yml @@ -40,7 +40,7 @@ jobs: run: | # Get yesterday's date in YYYY-MM-DD format YESTERDAY=$(date -d "yesterday" +%Y-%m-%d) - echo "yesterday=$YESTERDAY" >> $GITHUB_OUTPUT + echo "yesterday=$YESTERDAY" >> "$GITHUB_OUTPUT" echo "Yesterday's date: $YESTERDAY" - name: Count PRs merged yesterday @@ -64,7 +64,7 @@ jobs: | jq '.total_count') echo "PRs merged yesterday: $PR_COUNT" - echo "pr_count=$PR_COUNT" >> $GITHUB_OUTPUT + echo "pr_count=$PR_COUNT" >> "$GITHUB_OUTPUT" - name: Write data to google sheets env: From 4db842b9afec4a06e946198739a4f00ea9884111 Mon Sep 17 00:00:00 2001 From: seaona Date: Tue, 8 Jul 2025 14:31:21 +0200 Subject: [PATCH 4/4] update --- .github/workflows/log-daily-pr-merges.yml | 105 ------------------ .github/workflows/log-merge-group-success.yml | 48 ++++++++ 2 files changed, 48 insertions(+), 105 deletions(-) delete mode 100644 .github/workflows/log-daily-pr-merges.yml create mode 100644 .github/workflows/log-merge-group-success.yml diff --git a/.github/workflows/log-daily-pr-merges.yml b/.github/workflows/log-daily-pr-merges.yml deleted file mode 100644 index 7c48a7ac..00000000 --- a/.github/workflows/log-daily-pr-merges.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: Log number of daily merged PRs - -on: - schedule: - # Run daily at midnight UTC to get the previous day's data - - cron: '0 0 * * *' - workflow_call: - secrets: - GOOGLE_APPLICATION_CREDENTIALS: - required: true - GOOGLE_SERVICE_ACCOUNT: - required: true - SPREADSHEET_ID: - required: true - SHEET_NAME: - required: true - GITHUB_TOKEN: - required: true - workflow_dispatch: - -jobs: - log-daily-pr-merges: - name: Log number of daily merged PRs - runs-on: ubuntu-latest - steps: - - name: Download oauth2l - run: | - curl --silent https://storage.googleapis.com/oauth2l/1.3.2/linux_amd64.tgz | tar xz - echo "$PWD/linux_amd64" >> "$GITHUB_PATH" - - - name: Create service_account.json - env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} - GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} - run: | - echo "$GOOGLE_SERVICE_ACCOUNT" > "$GOOGLE_APPLICATION_CREDENTIALS" - - - name: Get yesterday's date - id: yesterday - run: | - # Get yesterday's date in YYYY-MM-DD format - YESTERDAY=$(date -d "yesterday" +%Y-%m-%d) - echo "yesterday=$YESTERDAY" >> "$GITHUB_OUTPUT" - echo "Yesterday's date: $YESTERDAY" - - - name: Count PRs merged yesterday - id: count_prs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Get the repository name from GITHUB_REPOSITORY - REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2) - echo "Repository: $REPO_NAME" - - # Count PRs merged yesterday into main branch - # Using GitHub API to search for PRs merged on yesterday's date - YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" - - # Search for PRs merged yesterday - PR_COUNT=$(curl --silent \ - --header "Authorization: token $GITHUB_TOKEN" \ - --header "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/search/issues?q=repo:$GITHUB_REPOSITORY+is:pr+is:merged+merged:$YESTERDAY..$YESTERDAY+base:main" \ - | jq '.total_count') - - echo "PRs merged yesterday: $PR_COUNT" - echo "pr_count=$PR_COUNT" >> "$GITHUB_OUTPUT" - - - name: Write data to google sheets - env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} - SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }} - SHEET_NAME: ${{ secrets.SHEET_NAME }} - run: | - YESTERDAY="${{ steps.yesterday.outputs.yesterday }}" - PR_COUNT="${{ steps.count_prs.outputs.pr_count }}" - - # Get OAuth token - token=$(oauth2l fetch --scope https://www.googleapis.com/auth/spreadsheets) - - # Read existing data to check if yesterday's row exists - spreadsheet_data=$(curl --silent --header "Authorization: Bearer $token" \ - https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C) - - # Check if yesterday's date exists in column A - current_date_index=$(echo "$spreadsheet_data" | jq --arg yesterday "$YESTERDAY" \ - '(.values | map(.[0])) | (index($yesterday) | if . == null then null else . + 1 end)') - - if [ "$current_date_index" == "null" ]; then - # Date doesn't exist, append new row with PR count in column C - curl --silent --header "Authorization: Bearer $token" \ - --header "Content-Type: application/json" \ - --request POST \ - --data "{\"values\":[[\"$YESTERDAY\", \"\", $PR_COUNT]]}" \ - https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C:append?valueInputOption=USER_ENTERED - echo "Added new row for $YESTERDAY with $PR_COUNT PRs merged" - else - # Date exists, update column C with PR count - curl --silent --header "Authorization: Bearer $token" \ - --header "Content-Type: application/json" \ - --request PUT \ - --data "{\"values\":[[$PR_COUNT]]}" \ - https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!C"$current_date_index":C"$current_date_index"?valueInputOption=USER_ENTERED - echo "Updated row $current_date_index for $YESTERDAY with $PR_COUNT PRs merged" - fi diff --git a/.github/workflows/log-merge-group-success.yml b/.github/workflows/log-merge-group-success.yml new file mode 100644 index 00000000..ed59e54f --- /dev/null +++ b/.github/workflows/log-merge-group-success.yml @@ -0,0 +1,48 @@ +name: Log merge group success + +on: + workflow_call: + secrets: + GOOGLE_APPLICATION_CREDENTIALS: + required: true + GOOGLE_SERVICE_ACCOUNT: + required: true + SPREADSHEET_ID: + required: true + SHEET_NAME: + required: true + workflow_dispatch: + +jobs: + log-merge-group-success: + name: Log merge group success + runs-on: ubuntu-latest + steps: + - name: Download oauth2l + run: | + curl --silent https://storage.googleapis.com/oauth2l/1.3.2/linux_amd64.tgz | tar xz + echo "$PWD/linux_amd64" >> "$GITHUB_PATH" + + - name: Create service_account.json + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} + run: | + echo "$GOOGLE_SERVICE_ACCOUNT" > "$GOOGLE_APPLICATION_CREDENTIALS" + + - name: Write data to google sheets + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + SPREADSHEET_ID: ${{ secrets.SPREADSHEET_ID }} + SHEET_NAME: ${{ secrets.SHEET_NAME }} + run: | + current_date=$(date +%Y-%m-%d) + token=$(oauth2l fetch --scope https://www.googleapis.com/auth/spreadsheets) + spreadsheet_data=$(curl --silent --header "Authorization: Bearer $token" https://sheets.googleapis.com/v4/spreadsheets/"$SPREADSHEET_ID"/values/"$SHEET_NAME"!A:C) + 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)') + current_number_of_successes=$(echo "$spreadsheet_data" | jq --arg current_date "$current_date" '(.values[] | select(.[0] == $current_date) | .[2] | tonumber) // null') + if [ "$current_date_index" == "null" ]; then + 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 + else + 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 + fi