-
Notifications
You must be signed in to change notification settings - Fork 0
42 lines (34 loc) · 1.39 KB
/
evaluate-github.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: Hourly Cost Evaluation Github
on:
schedule:
# - cron: '0 * * * *' # This cron expression schedules the workflow to run every hour
jobs:
hello-world:
runs-on: ubuntu-latest
steps:
- name: Print Hello World
run: echo "Hello, World!"
evaluate-cost:
runs-on: ubuntu-latest
needs: hello-world
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Evaluate GitHub Actions Cost
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO_OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.event.repository.name }}"
# Fetch workflow run usage data
usage=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs" | \
jq '[.workflow_runs[] | {id: .id, name: .name, run_attempt: .run_attempt, billable: .billable}]')
echo "Workflow Usage Data:"
echo "$usage"
COST_PER_MINUTE=0.008
# Calculate total minutes used and cost, skipping null billable entries
total_minutes=$(echo "$usage" | jq '[.[] | select(.billable != null) | .billable.total_minutes] | add // 0')
total_cost=$(echo "$total_minutes * $COST_PER_MINUTE" | bc)
echo "Total Minutes Used: $total_minutes"
echo "Estimated Cost: $total_cost USD"