From 1778471986c9cd3ec861d1aaf1bc0682690abbf5 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Tue, 19 Mar 2024 15:55:13 +0000 Subject: [PATCH] chore(ci): report workflow running time to PostHog (#21002) --- .github/workflows/ci-backend-depot.yml | 34 +++++++++++++++++++++++++ .github/workflows/ci-backend.yml | 35 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/.github/workflows/ci-backend-depot.yml b/.github/workflows/ci-backend-depot.yml index 0c9ff85d7d1dd..e555082455c9f 100644 --- a/.github/workflows/ci-backend-depot.yml +++ b/.github/workflows/ci-backend-depot.yml @@ -371,3 +371,37 @@ jobs: - name: Run async migrations tests run: | pytest -m "async_migrations" + calculate-running-time: + name: Calculate running time + needs: [django, async-migrations] + runs-on: ubuntu-latest + if: needs.changes.outputs.backend == 'true' + steps: + - name: Calculate running time + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token + run_id=${GITHUB_RUN_ID} + repo=${GITHUB_REPOSITORY} + run_info=$(gh api repos/${repo}/actions/runs/${run_id}) + echo run_info: ${run_info} + # name is the name of the workflow file + # run_started_at is the start time of the workflow + # we want to get the number of seconds between the start time and now + name=$(echo ${run_info} | jq -r '.name') + run_url=$(echo ${run_info} | jq -r '.url') + run_started_at=$(echo ${run_info} | jq -r '.run_started_at') + run_attempt=$(echo ${run_info} | jq -r '.run_attempt') + start_seconds=$(date -d "${run_started_at}" +%s) + now_seconds=$(date +%s) + duration=$((now_seconds-start_seconds)) + echo running_time_duration_seconds=${duration} >> $GITHUB_ENV + echo running_time_run_url=${run_url} >> $GITHUB_ENV + echo running_time_run_attempt=${run_attempt} >> $GITHUB_ENV + echo running_time_run_id=${run_id} >> $GITHUB_ENV + echo running_time_run_started_at=${run_started_at} >> $GITHUB_ENV + - name: Capture running time to PostHog + uses: PostHog/posthog-github-action@v0.1 + with: + posthog-token: ${{secrets.POSTHOG_API_TOKEN}} + event: 'posthog-ci-running-time' + properties: '{"duration_seconds": ${{ env.running_time_duration_seconds }}, "run_url": "${{ env.running_time_run_url }}", "run_attempt": "${{ env.running_time_run_attempt }}", "run_id": "${{ env.running_time_run_id }}", "run_started_at": "${{ env.running_time_run_started_at }}"}' diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index 0a1dc38b3260c..9dafdd497d595 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -371,3 +371,38 @@ jobs: - name: Run async migrations tests run: | pytest -m "async_migrations" + + calculate-running-time: + name: Calculate running time + needs: [django, async-migrations] + runs-on: ubuntu-latest + if: needs.changes.outputs.backend == 'true' + steps: + - name: Calculate running time + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token + run_id=${GITHUB_RUN_ID} + repo=${GITHUB_REPOSITORY} + run_info=$(gh api repos/${repo}/actions/runs/${run_id}) + echo run_info: ${run_info} + # name is the name of the workflow file + # run_started_at is the start time of the workflow + # we want to get the number of seconds between the start time and now + name=$(echo ${run_info} | jq -r '.name') + run_url=$(echo ${run_info} | jq -r '.url') + run_started_at=$(echo ${run_info} | jq -r '.run_started_at') + run_attempt=$(echo ${run_info} | jq -r '.run_attempt') + start_seconds=$(date -d "${run_started_at}" +%s) + now_seconds=$(date +%s) + duration=$((now_seconds-start_seconds)) + echo running_time_duration_seconds=${duration} >> $GITHUB_ENV + echo running_time_run_url=${run_url} >> $GITHUB_ENV + echo running_time_run_attempt=${run_attempt} >> $GITHUB_ENV + echo running_time_run_id=${run_id} >> $GITHUB_ENV + echo running_time_run_started_at=${run_started_at} >> $GITHUB_ENV + - name: Capture running time to PostHog + uses: PostHog/posthog-github-action@v0.1 + with: + posthog-token: ${{secrets.POSTHOG_API_TOKEN}} + event: 'posthog-ci-running-time' + properties: '{"duration_seconds": ${{ env.running_time_duration_seconds }}, "run_url": "${{ env.running_time_run_url }}", "run_attempt": "${{ env.running_time_run_attempt }}", "run_id": "${{ env.running_time_run_id }}", "run_started_at": "${{ env.running_time_run_started_at }}"}'