From 9a3399f11c18cb8c2f5a92dd3a6773681aa77e39 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Wed, 26 Jul 2023 14:28:14 +0100 Subject: [PATCH] chore: fix issue-metrics workflow (#26513) The blog post was wrong, added a few missing configuration bits and streamlined the date code. Also added a report for PRs. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .github/workflows/issue-metrics.yml | 47 ------------------------ .github/workflows/repo-metrics.yml | 56 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/issue-metrics.yml create mode 100644 .github/workflows/repo-metrics.yml diff --git a/.github/workflows/issue-metrics.yml b/.github/workflows/issue-metrics.yml deleted file mode 100644 index 7633db4ba11da..0000000000000 --- a/.github/workflows/issue-metrics.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Monthly issue metrics -on: - workflow_dispatch: - schedule: - - cron: '0 2 1 * *' - -jobs: - build: - name: issue metrics - runs-on: ubuntu-latest - - steps: - - - name: Get dates for last month - shell: bash - run: | - # Get the current date - current_date=$(date +'%Y-%m-%d') - - # Calculate the previous month - previous_date=$(date -d "$current_date -1 month" +'%Y-%m-%d') - - # Extract the year and month from the previous date - previous_year=$(date -d "$previous_date" +'%Y') - previous_month=$(date -d "$previous_date" +'%m') - - # Calculate the first day of the previous month - first_day=$(date -d "$previous_year-$previous_month-01" +'%Y-%m-%d') - - # Calculate the last day of the previous month - last_day=$(date -d "$first_day +1 month -1 day" +'%Y-%m-%d') - - echo "$first_day..$last_day" - echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV" - - - name: Run issue-metrics tool - uses: github/issue-metrics@v2 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SEARCH_QUERY: 'repo:aws/aws-cdk is:issue created:${{ env.last_month }} -reason:"not planned"' - - - name: Create issue - uses: peter-evans/create-issue-from-file@v4 - with: - title: Monthly issue metrics report - content-filepath: ./issue_metrics.md - assignees: evgenyka diff --git a/.github/workflows/repo-metrics.yml b/.github/workflows/repo-metrics.yml new file mode 100644 index 0000000000000..cba553913c84b --- /dev/null +++ b/.github/workflows/repo-metrics.yml @@ -0,0 +1,56 @@ +name: Monthly repo metrics +on: + workflow_dispatch: + schedule: + - cron: '0 2 1 * *' + +permissions: + issues: write + pull-requests: read + +jobs: + build: + name: metrics + runs-on: ubuntu-latest + + steps: + - name: Get dates for last month + shell: bash + run: | + # Calculate the first day of the previous month + first_day=$(date -d "last month" +%Y-%m-01) + + # Calculate the last day of the previous month + last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d) + + # Set an environment variable with the date range + echo "$first_day..$last_day" + echo "last_month=$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_month }} -reason:"not planned"' + + - name: Create report for issues + uses: peter-evans/create-issue-from-file@v4 + with: + title: Monthly issue metrics report + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: evgenyka + + - 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_month }} -is:draft' + + - name: Create report for PRs + uses: peter-evans/create-issue-from-file@v4 + with: + title: Monthly issue metrics report + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: evgenyka