Skip to content

.github/workflows/evaluate-blacksmith.yml #96

.github/workflows/evaluate-blacksmith.yml

.github/workflows/evaluate-blacksmith.yml #96

name: Hourly Cost Evaluation Blacksmith
on:
schedule:
- cron: '0 * * * *' # This cron expression schedules the workflow to run every hour
jobs:
hello-world:
runs-on: blacksmith-4vcpu-ubuntu-2204
steps:
- name: Print Hello World
run: echo "Hello, World!"
evaluate-cost:
runs-on: blacksmith-4vcpu-ubuntu-2204
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"