Repository navigation
fix: restore packageManager field for Cloudflare Workers Builds (#104) #8
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: Deploy homepage metrics Worker | |
| on: | |
| push: | |
| branches: ["main"] | |
| paths: | |
| - ".github/workflows/deploy-homepage-metrics.yml" | |
| - "lib/homepage-metrics.ts" | |
| - "package.json" | |
| - "pnpm-lock.yaml" | |
| - "public/homepage-metrics.json" | |
| - "scripts/*docker-metrics*" | |
| - "workers/homepage-metrics/**" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: homepage-metrics-worker | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v6 | |
| with: | |
| cache: true | |
| - name: Use Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: 24 | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Verify Worker | |
| run: pnpm run check:homepage-metrics-worker | |
| - name: Validate Cloudflare credentials | |
| shell: bash | |
| env: | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${CLOUDFLARE_ACCOUNT_ID}" ]]; then | |
| echo "::error::Missing CLOUDFLARE_ACCOUNT_ID repository secret." | |
| exit 1 | |
| fi | |
| if [[ -z "${CLOUDFLARE_API_TOKEN}" ]]; then | |
| echo "::error::Missing CLOUDFLARE_API_TOKEN repository secret." | |
| exit 1 | |
| fi | |
| pnpm exec wrangler whoami | |
| - name: Provision homepage metrics KV | |
| shell: bash | |
| env: | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| KV_NAMESPACE_TITLE: rustfs-homepage-metrics | |
| KV_BINDING: HOMEPAGE_METRICS | |
| run: | | |
| set -euo pipefail | |
| namespaces_json="$(pnpm exec wrangler kv namespace list)" | |
| namespace_id="$( | |
| jq -r --arg title "${KV_NAMESPACE_TITLE}" \ | |
| '[.[] | select(.title == $title)][0].id // empty' \ | |
| <<<"${namespaces_json}" | |
| )" | |
| if [[ -z "${namespace_id}" ]]; then | |
| pnpm exec wrangler kv namespace create "${KV_NAMESPACE_TITLE}" | |
| namespaces_json="$(pnpm exec wrangler kv namespace list)" | |
| namespace_id="$( | |
| jq -r --arg title "${KV_NAMESPACE_TITLE}" \ | |
| '[.[] | select(.title == $title)][0].id // empty' \ | |
| <<<"${namespaces_json}" | |
| )" | |
| fi | |
| if [[ -z "${namespace_id}" ]]; then | |
| echo "::error::KV namespace was not found after provisioning." | |
| exit 1 | |
| fi | |
| jq \ | |
| --arg binding "${KV_BINDING}" \ | |
| --arg id "${namespace_id}" \ | |
| '(.kv_namespaces[] | select(.binding == $binding) | .id) = $id' \ | |
| workers/homepage-metrics/wrangler.jsonc \ | |
| > workers/homepage-metrics/wrangler.deploy.jsonc | |
| - name: Collect and publish Docker metrics | |
| env: | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| run: | | |
| node scripts/fetch-docker-metrics.mjs "$RUNNER_TEMP/docker-metrics.json" | |
| pnpm exec wrangler kv key put docker-metrics:v1 \ | |
| --binding HOMEPAGE_METRICS --remote \ | |
| --config workers/homepage-metrics/wrangler.deploy.jsonc \ | |
| --path "$RUNNER_TEMP/docker-metrics.json" | |
| - name: Deploy Worker | |
| run: pnpm exec wrangler deploy --config workers/homepage-metrics/wrangler.deploy.jsonc | |
| env: | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| - name: Warm homepage metrics cache | |
| run: >- | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors | |
| --retry-delay 2 --max-time 45 --output /dev/null | |
| https://rustfs.com/api/homepage-metrics | |
| - name: Verify fresh Docker metrics on the homepage | |
| run: node scripts/verify-docker-metrics.mjs "$RUNNER_TEMP/docker-metrics.json" |