compare-pricing-data.yaml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. name: Compare Pricing Data
  2. on:
  3. schedule:
  4. - cron: '0 18 * * *'
  5. permissions:
  6. contents: read
  7. jobs:
  8. compare-usd:
  9. runs-on: ubuntu-latest
  10. outputs:
  11. exit_code: ${{ steps.compare.outputs.exit_code }}
  12. steps:
  13. - uses: actions/checkout@v6.0.2
  14. - name: Install Go
  15. uses: actions/setup-go@v6
  16. with:
  17. go-version: 'stable'
  18. - name: Go Mod cache
  19. uses: actions/cache@v5
  20. with:
  21. path: |
  22. ~/.cache/go-build
  23. ~/go/pkg/mod
  24. key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
  25. - name: Compare USD pricing data
  26. id: compare
  27. working-directory: modules/pricing/public/cmd
  28. env:
  29. GCP_API_KEY: ${{ secrets.GCP_API_KEY }}
  30. # Capture the exit code before the shell exits so downstream steps can
  31. # distinguish drift (2) from a generation/infra error (1).
  32. run: |
  33. set +e
  34. go run . --currency USD --compare
  35. CODE=$?
  36. echo "exit_code=$CODE" >> $GITHUB_OUTPUT
  37. exit $CODE
  38. compare-cny:
  39. runs-on: ubuntu-latest
  40. outputs:
  41. exit_code: ${{ steps.compare.outputs.exit_code }}
  42. steps:
  43. - uses: actions/checkout@v6.0.2
  44. - name: Install Go
  45. uses: actions/setup-go@v6
  46. with:
  47. go-version: 'stable'
  48. - name: Go Mod cache
  49. uses: actions/cache@v5
  50. with:
  51. path: |
  52. ~/.cache/go-build
  53. ~/go/pkg/mod
  54. key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
  55. - name: Compare CNY pricing data
  56. id: compare
  57. working-directory: modules/pricing/public/cmd
  58. # CNY does not use GCP so no API key needed
  59. run: |
  60. set +e
  61. go run . --currency CNY --compare
  62. CODE=$?
  63. echo "exit_code=$CODE" >> $GITHUB_OUTPUT
  64. exit $CODE
  65. notify-drift:
  66. runs-on: ubuntu-latest
  67. needs: [compare-usd, compare-cny]
  68. if: |
  69. always() &&
  70. (needs.compare-usd.outputs.exit_code == '2' || needs.compare-cny.outputs.exit_code == '2')
  71. steps:
  72. - name: Notify Slack — pricing drift
  73. uses: slackapi/slack-github-action@v2
  74. with:
  75. method: chat.postMessage
  76. token: ${{ secrets.SLACK_BOT_TOKEN }}
  77. payload: |
  78. channel: ${{ secrets.SLACK_PRICING_CHANNEL_ID }}
  79. text: ":warning: Pricing data drift detected :warning:"
  80. blocks:
  81. - type: section
  82. text:
  83. type: mrkdwn
  84. text: ":warning: *Pricing data drift detected*\nUSD: ${{ needs.compare-usd.outputs.exit_code == '2' && 'drifted :x:' || 'ok :white_check_mark:' }} | CNY: ${{ needs.compare-cny.outputs.exit_code == '2' && 'drifted :x:' || 'ok :white_check_mark:' }}\nThe live cloud provider pricing no longer matches the committed <https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}/modules/pricing/public|pricing-data.json>.\n*Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>"