Generate Manifests from R2 #115
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: Generate Manifests from R2 | |
| on: | |
| # Trigger after mirror workflows complete | |
| workflow_run: | |
| workflows: ["Mirror Sync"] | |
| types: | |
| - completed | |
| # Manual trigger | |
| workflow_dispatch: | |
| inputs: | |
| runtime: | |
| description: 'Runtime to generate (node, python, ruby, or all)' | |
| required: true | |
| default: 'all' | |
| type: choice | |
| options: | |
| - all | |
| - node | |
| - python | |
| - ruby | |
| dry_run: | |
| description: 'Dry run (report only, no file changes)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate: | |
| name: Generate Manifests | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.CONTRIBUTORS_TOKEN }} | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: 'go.mod' | |
| - name: Build manifest generator | |
| run: | | |
| cd scripts/generate-manifests-from-r2 | |
| go build -o generate-manifests . | |
| - name: Generate manifests (dry run) | |
| if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }} | |
| env: | |
| R2_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com | |
| R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_BUILDS_BUCKET }} | |
| R2_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} | |
| R2_SECRET_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} | |
| run: | | |
| RUNTIME="${{ inputs.runtime || 'all' }}" | |
| ./scripts/generate-manifests-from-r2/generate-manifests \ | |
| --runtime="$RUNTIME" \ | |
| --output-dir=src/internal/manifest/data \ | |
| --base-url="https://builds.dtvem.io" \ | |
| --r2-endpoint="$R2_ENDPOINT" \ | |
| --r2-bucket="$R2_BUCKET" \ | |
| --r2-access-key="$R2_ACCESS_KEY" \ | |
| --r2-secret-key="$R2_SECRET_KEY" \ | |
| --dry-run | |
| - name: Generate manifests | |
| if: ${{ github.event_name != 'workflow_dispatch' || !inputs.dry_run }} | |
| env: | |
| R2_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com | |
| R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_BUILDS_BUCKET }} | |
| R2_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} | |
| R2_SECRET_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} | |
| run: | | |
| RUNTIME="${{ inputs.runtime || 'all' }}" | |
| ./scripts/generate-manifests-from-r2/generate-manifests \ | |
| --runtime="$RUNTIME" \ | |
| --output-dir=src/internal/manifest/data \ | |
| --base-url="https://builds.dtvem.io" \ | |
| --r2-endpoint="$R2_ENDPOINT" \ | |
| --r2-bucket="$R2_BUCKET" \ | |
| --r2-access-key="$R2_ACCESS_KEY" \ | |
| --r2-secret-key="$R2_SECRET_KEY" | |
| - name: Deploy manifests to R2 | |
| if: ${{ github.event_name != 'workflow_dispatch' || !inputs.dry_run }} | |
| env: | |
| R2_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com | |
| R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_MANIFESTS_BUCKET }} | |
| run: | | |
| aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} | |
| aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} | |
| aws configure set default.region auto | |
| echo "Deploying manifests to R2..." | |
| for file in src/internal/manifest/data/*.json; do | |
| filename=$(basename "$file") | |
| echo "Uploading $filename..." | |
| aws s3 cp "$file" "s3://${R2_BUCKET}/${filename}" \ | |
| --endpoint-url "${R2_ENDPOINT}" \ | |
| --content-type "application/json" \ | |
| --cache-control "public, max-age=300" | |
| done | |
| echo "Manifests deployed to R2!" | |
| - name: Check for changes | |
| id: check-changes | |
| if: ${{ github.event_name != 'workflow_dispatch' || !inputs.dry_run }} | |
| run: | | |
| git diff --quiet src/internal/manifest/data/ || echo "changed=true" >> $GITHUB_OUTPUT | |
| - name: Commit and push changes | |
| if: ${{ steps.check-changes.outputs.changed == 'true' }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git stash --include-untracked | |
| git pull --rebase origin main | |
| git stash pop | |
| git add src/internal/manifest/data/ | |
| git commit -m "chore(manifest): regenerate manifests from R2" | |
| git push | |
| - name: Generate summary | |
| if: always() | |
| run: | | |
| echo "## Manifest Generation" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ inputs.dry_run }}" = "true" ]; then | |
| echo "**Mode:** Dry run (no changes made)" >> $GITHUB_STEP_SUMMARY | |
| elif [ "${{ steps.check-changes.outputs.changed }}" = "true" ]; then | |
| echo "**Result:** Changes detected" >> $GITHUB_STEP_SUMMARY | |
| echo "- Manifests deployed to R2 (live immediately)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Embedded manifests committed to main" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "**Result:** No changes detected" >> $GITHUB_STEP_SUMMARY | |
| fi |