This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Calculate Running Time | ||
on: | ||
workflow_call: | ||
inputs: | ||
run_condition: | ||
required: true | ||
type: string | ||
runner_type: | ||
required: false | ||
type: string # The runner type, e.g., "ubuntu-latest" or "depot-latest-4" | ||
extra_properties: | ||
required: false | ||
type: string # JSON string for additional properties | ||
secrets: | ||
GITHUB_TOKEN: | ||
Check failure on line 16 in .github/workflows/calculate-running-time-workflow.yml
|
||
required: true | ||
POSTHOG_API_TOKEN: | ||
required: true | ||
jobs: | ||
calculate-running-time: | ||
name: Calculate Running Time | ||
runs-on: ${{ inputs.runner_type || 'ubuntu-24.04' }} # Default to ubuntu-24.04 if not provided | ||
if: ${{ fromJSON(inputs.run_condition) }} # Dynamically evaluate condition | ||
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=$(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/[email protected] | ||
with: | ||
posthog-token: ${{ secrets.POSTHOG_API_TOKEN }} | ||
event: 'posthog-ci-running-time' | ||
properties: >- | ||
${{ toJSON(fromJSON(inputs.extra_properties) || {}) | fromJSON | | ||
toJSON( | ||
{ "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 | ||
} + fromJSON(inputs.extra_properties) | ||
) }} |