-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (90 loc) · 4.12 KB
/
Copy pathaws-pricing.yml
File metadata and controls
100 lines (90 loc) · 4.12 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: AWS Pricing
# Pulls AWS **On-Demand** list prices from the PUBLIC Price List Bulk API (no credentials) and
# PUBLISHES compact JSON to the `aws-pricing/data` branch, which the cost-dashboard Netlify site
# reads at runtime. Regions accumulate on the branch: re-running a region overwrites its file, a
# new region adds one; index.json is rebuilt from every pricing_<region>.json present each run.
on:
workflow_dispatch:
inputs:
regions:
description: 'Region(s) to pull, comma-separated (e.g. us-west-2,us-east-1)'
type: string
required: false
default: 'us-east-1,us-west-2,eu-west-1'
schedule:
- cron: '0 13 * * 1' # Mondays 13:00 UTC (prices change rarely; weekly is plenty)
permissions:
contents: write # publish to the aws-pricing/data branch
jobs:
aws-pricing:
name: Pull AWS On-Demand prices → publish JSON
runs-on: ubuntu-latest
env:
REGIONS: ${{ github.event.inputs.regions || 'us-east-1,us-west-2,eu-west-1' }}
steps:
- name: "1 · Checkout repository"
uses: actions/checkout@v4
with:
fetch-depth: 0 # full history so the data branch can be based/pushed
- name: "2 · Set up Python"
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: "3 · Offline golden test (filters must keep real SKUs, reject decoys)"
run: python3 aws-pricing/test_generate.py
- name: "4 · Generate pricing JSON (live public bulk API, no creds)"
run: |
python3 aws-pricing/generate_aws_pricing.py \
--region "$REGIONS" \
--out-dir reports \
--now "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
- name: "5 · Upload artifact"
uses: actions/upload-artifact@v4
with:
name: aws-pricing
path: reports/
- name: "6 · Publish to aws-pricing/data branch (accumulate by region)"
run: |
BR="aws-pricing/data"
# Stash this run's outputs AND the generator (the data branch has neither) before switching.
mkdir -p "$RUNNER_TEMP/out" && cp -R reports/. "$RUNNER_TEMP/out/"
cp aws-pricing/generate_aws_pricing.py "$RUNNER_TEMP/gen.py"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin "$BR" || true
if git rev-parse --verify --quiet "origin/$BR"; then
git checkout -f -B "$BR" "origin/$BR" # continue history: prior regions persist
else
git checkout -f -B "$BR"
fi
mkdir -p reports
# Keep only pricing snapshots + the index (drop anything inherited from main).
find reports -maxdepth 1 -type f ! -name 'pricing_*.json' ! -name 'index.json' -delete 2>/dev/null || true
# Copy in THIS run's region files (same region overwrites; new regions add).
cp "$RUNNER_TEMP/out/"pricing_*.json reports/
# Rebuild index.json from ALL region files now on the branch (no network).
python3 "$RUNNER_TEMP/gen.py" --reindex-only reports --now "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
git add -f reports
if git diff --cached --quiet; then
echo "No pricing changes for $BR."
else
git commit -m "AWS pricing — ${REGIONS} (run ${{ github.run_id }})"
git push origin "$BR"
echo "Published to branch: $BR"
fi
- name: "7 · Dashboard link in job summary"
if: always()
env:
DASHBOARD_URL: "https://veda-aws-dashboard.netlify.app"
run: |
{
echo "### 💵 AWS Cost Calculator"
echo ""
echo "Published On-Demand prices for **${REGIONS}** to the \`aws-pricing/data\` branch."
echo ""
echo "Dashboard → ${DASHBOARD_URL}"
} >> "$GITHUB_STEP_SUMMARY"
- name: "8 · Restore default checkout"
# Step 6 switched the tree to aws-pricing/data; put the run's commit back for the post phase.
if: always()
run: git checkout -f "${{ github.sha }}" 2>/dev/null || git checkout -f main