From e770d039f11a207ce54d2553a70df6fd6698aadb Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 11 Mar 2024 10:55:33 -0700 Subject: [PATCH 1/5] chore: add weekly workflow for github issues/pr metrics --- ...o-metrics.yml => repo-metrics-monthly.yml} | 0 .github/workflows/repo-metrics-weekly.yml | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+) rename .github/workflows/{repo-metrics.yml => repo-metrics-monthly.yml} (100%) create mode 100644 .github/workflows/repo-metrics-weekly.yml diff --git a/.github/workflows/repo-metrics.yml b/.github/workflows/repo-metrics-monthly.yml similarity index 100% rename from .github/workflows/repo-metrics.yml rename to .github/workflows/repo-metrics-monthly.yml diff --git a/.github/workflows/repo-metrics-weekly.yml b/.github/workflows/repo-metrics-weekly.yml new file mode 100644 index 0000000000000..53123d689ac0a --- /dev/null +++ b/.github/workflows/repo-metrics-weekly.yml @@ -0,0 +1,58 @@ +name: Weekly repo metrics +on: + workflow_dispatch: + schedule: + - cron: '0 9 * * MON' + +permissions: + issues: write + pull-requests: read + +jobs: + build: + # this workflow will always fail in forks; bail if this isn't running in the upstream + if: github.repository == 'aws/aws-cdk' + name: metrics + runs-on: ubuntu-latest + + steps: + - name: Get dates for last week + shell: bash + run: | + # Calculate the previous Monday's date + PREVIOUS_MONDAY=$(date -d "last monday" "+%Y-%m-%d") + + # Calculate the current Sunday's date + CURRENT_SUNDAY=$(date -d "next Sunday" "+%Y-%m-%d") + + # Set an environment variable with the date range + echo "$PREVIOUS_MONDAY..$CURRENT_SUNDAY" + echo "last_week=$first_day..$last_day" >> "$GITHUB_ENV" + + - name: Report on issues + uses: github/issue-metrics@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:aws/aws-cdk is:issue created:${{ env.last_week }} -reason:"not planned"' + + - name: Create report for issues + uses: peter-evans/create-issue-from-file@v5 + with: + title: Weekly issue metrics report + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: paulhcsun + + - name: Report on PRs + uses: github/issue-metrics@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:aws/aws-cdk is:pr created:${{ env.last_week }} -is:draft' + + - name: Create report for PRs + uses: peter-evans/create-issue-from-file@v5 + with: + title: Weekly PR metrics report + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: paulhcsun \ No newline at end of file From fe9da9a8b35132dafba1ce5ed6358d2a0511dd3e Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 11 Mar 2024 15:03:23 -0700 Subject: [PATCH 2/5] add extra line space --- .github/workflows/repo-metrics-weekly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/repo-metrics-weekly.yml b/.github/workflows/repo-metrics-weekly.yml index 53123d689ac0a..f7fa957e80df8 100644 --- a/.github/workflows/repo-metrics-weekly.yml +++ b/.github/workflows/repo-metrics-weekly.yml @@ -55,4 +55,4 @@ jobs: title: Weekly PR metrics report token: ${{ secrets.GITHUB_TOKEN }} content-filepath: ./issue_metrics.md - assignees: paulhcsun \ No newline at end of file + assignees: paulhcsun From 82eea8a6c12c67d15a4c22e1a5b8b2da03b4bf96 Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 11 Mar 2024 15:22:13 -0700 Subject: [PATCH 3/5] update variables --- .github/workflows/repo-metrics-weekly.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/repo-metrics-weekly.yml b/.github/workflows/repo-metrics-weekly.yml index f7fa957e80df8..3a1823e70c3eb 100644 --- a/.github/workflows/repo-metrics-weekly.yml +++ b/.github/workflows/repo-metrics-weekly.yml @@ -23,11 +23,11 @@ jobs: PREVIOUS_MONDAY=$(date -d "last monday" "+%Y-%m-%d") # Calculate the current Sunday's date - CURRENT_SUNDAY=$(date -d "next Sunday" "+%Y-%m-%d") + CURRENT_SUNDAY=$(date -d "current Sunday" "+%Y-%m-%d") # Set an environment variable with the date range echo "$PREVIOUS_MONDAY..$CURRENT_SUNDAY" - echo "last_week=$first_day..$last_day" >> "$GITHUB_ENV" + echo "last_week=$PREVIOUS_MONDAY..$CURRENT_SUNDAY" >> "$GITHUB_ENV" - name: Report on issues uses: github/issue-metrics@v2 From 763019248159f9c9eff80c981c5bb432bd4fd0e0 Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 11 Mar 2024 15:40:37 -0700 Subject: [PATCH 4/5] update dates in shell script --- .github/workflows/repo-metrics-weekly.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/repo-metrics-weekly.yml b/.github/workflows/repo-metrics-weekly.yml index 3a1823e70c3eb..e99f445155290 100644 --- a/.github/workflows/repo-metrics-weekly.yml +++ b/.github/workflows/repo-metrics-weekly.yml @@ -19,11 +19,17 @@ jobs: - name: Get dates for last week shell: bash run: | - # Calculate the previous Monday's date - PREVIOUS_MONDAY=$(date -d "last monday" "+%Y-%m-%d") + # Calculate the current day of the week (0=Sunday, 1=Monday, ..., 6=Saturday) + CURRENT_DAY_OF_WEEK=$(date +%u) - # Calculate the current Sunday's date - CURRENT_SUNDAY=$(date -d "current Sunday" "+%Y-%m-%d") + # Calculate the number of days to subtract to get to the previous Monday + DAYS_TO_MONDAY=$((CURRENT_DAY_OF_WEEK - 1)) + + # Calculate the date of the previous Monday + PREVIOUS_MONDAY=$(date -d "$DAYS_TO_MONDAY days ago" "+%Y-%m-%d") + + # Calculate the date of the current Sunday (assuming today is not Sunday) + CURRENT_SUNDAY=$(date -d "$DAYS_TO_MONDAY days ago +6 day" "+%Y-%m-%d") # Set an environment variable with the date range echo "$PREVIOUS_MONDAY..$CURRENT_SUNDAY" From 5d334a64240007d2086b723096bc1b727812ed0f Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 11 Mar 2024 16:46:18 -0700 Subject: [PATCH 5/5] update bash script --- .github/workflows/repo-metrics-weekly.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/repo-metrics-weekly.yml b/.github/workflows/repo-metrics-weekly.yml index e99f445155290..f993bebe7c4dd 100644 --- a/.github/workflows/repo-metrics-weekly.yml +++ b/.github/workflows/repo-metrics-weekly.yml @@ -19,17 +19,11 @@ jobs: - name: Get dates for last week shell: bash run: | - # Calculate the current day of the week (0=Sunday, 1=Monday, ..., 6=Saturday) - CURRENT_DAY_OF_WEEK=$(date +%u) - - # Calculate the number of days to subtract to get to the previous Monday - DAYS_TO_MONDAY=$((CURRENT_DAY_OF_WEEK - 1)) - # Calculate the date of the previous Monday - PREVIOUS_MONDAY=$(date -d "$DAYS_TO_MONDAY days ago" "+%Y-%m-%d") + PREVIOUS_MONDAY=$(date -d "7 days ago" "+%Y-%m-%d") - # Calculate the date of the current Sunday (assuming today is not Sunday) - CURRENT_SUNDAY=$(date -d "$DAYS_TO_MONDAY days ago +6 day" "+%Y-%m-%d") + # Calculate the date of the current Sunday + CURRENT_SUNDAY=$(date -d "1 day ago" "+%Y-%m-%d") # Set an environment variable with the date range echo "$PREVIOUS_MONDAY..$CURRENT_SUNDAY"