Fetch Free CS2 Item Prices #2
This file contains hidden or 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: Fetch Free CS2 Item Prices | |
| on: | |
| schedule: | |
| - cron: '0 */5 * * *' | |
| workflow_dispatch: | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| fetch-and-commit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Fetch Free CS2 prices from API | |
| run: | | |
| HTTP_STATUS=$(curl -s -w "%{http_code}" \ | |
| -H "Accept: application/json" \ | |
| -H "x-api-key: ${{ secrets.SKINSTRACK_FREE_API_KEY }}" \ | |
| "${{ secrets.SKINSTRACK_FREE_API_URL }}" \ | |
| -o free_prices.json) | |
| echo "HTTP status: $HTTP_STATUS" | |
| if [ "$HTTP_STATUS" -lt 200 ] || [ "$HTTP_STATUS" -gt 299 ]; then | |
| echo "ERROR: API returned HTTP $HTTP_STATUS" | |
| cat free_prices.json | |
| exit 1 | |
| fi | |
| # Validate the response is valid JSON | |
| if ! python3 -c "import json; json.load(open('free_prices.json'))" 2>/dev/null; then | |
| echo "ERROR: API did not return valid JSON" | |
| cat free_prices.json | |
| exit 1 | |
| fi | |
| echo "Fetched $(python3 -c "import json; data=json.load(open('free_prices.json')); print(len(data) if isinstance(data, list) else 'N/A')" 2>/dev/null || echo '?') items" | |
| - name: Add metadata timestamp | |
| run: | | |
| python3 - <<'EOF' | |
| import json, datetime | |
| with open("free_prices.json", "r") as f: | |
| data = json.load(f) | |
| output = { | |
| "fetched_at": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"), | |
| "source": "cs2-prices-api", | |
| "data": data | |
| } | |
| with open("free_prices.json", "w") as f: | |
| json.dump(output, f, indent=2) | |
| print("Timestamp added:", output["fetched_at"]) | |
| EOF | |
| - name: Commit and push if changed | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add free_prices.json | |
| if git diff --cached --quiet; then | |
| echo "No changes to free prices — skipping commit" | |
| else | |
| git commit -m "chore: update CS2 free prices [$(date -u '+%Y-%m-%d %H:%M UTC')]" | |
| git push | |
| fi |