### Local Testing Setup and Execution Source: https://context7.com/ryand56/r2-upload-action/llms.txt Instructions for setting up and running the action's test suite locally. This involves copying an environment file, installing dependencies, building the action, and executing the tests. ```bash # Copy the example env file and fill in your R2 credentials cp .env.example .env # Build the action pnpm install pnpm build # Run the test suite (requires valid R2 credentials in .env) pnpm test ``` -------------------------------- ### R2 Upload with Multiple Source Directories Source: https://context7.com/ryand56/r2-upload-action/llms.txt This example configures the action to upload files from multiple local directories into a specified destination directory in the R2 bucket. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: | dist/ public/assets/ destination-dir: artifacts/v1.4/ ``` -------------------------------- ### Basic Static Site Deployment to R2 Source: https://context7.com/ryand56/r2-upload-action/llms.txt A complete workflow example for deploying a static site to R2. It includes building the site and uploading the output to a specified bucket. ```yaml name: Deploy to R2 on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build site run: npm ci && npm run build - name: Upload build output to R2 uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: my-static-site source-dir: dist/ destination-dir: ./ keep-file-fresh: true output-file-url: false ``` -------------------------------- ### Basic R2 Upload Configuration Source: https://context7.com/ryand56/r2-upload-action/llms.txt This example demonstrates the minimum required inputs for the R2 Upload Action to upload files from a local 'dist/' directory to a Cloudflare R2 bucket. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: dist/ ``` -------------------------------- ### Release Artifact Upload with Multipart Configuration Source: https://context7.com/ryand56/r2-upload-action/llms.txt Example workflow for uploading release artifacts using multipart uploads. Configurable options include `multipart-size`, `multipart-concurrent`, `max-retries`, and `retry-timeout`. ```yaml name: Release on: release: types: [published] jobs: upload-artifacts: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build release archive run: make package # produces release/app-${{ github.ref_name }}.tar.gz - name: Upload release to R2 id: r2 uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: releases-bucket source-dir: release/ destination-dir: releases/${{ github.ref_name }}/ multipart-size: 50 multipart-concurrent: true max-retries: 5 retry-timeout: 2000 output-file-url: true - name: Log uploaded URLs run: echo "${{ steps.r2.outputs.file-urls }}" ``` -------------------------------- ### R2 Upload with Jurisdiction Override Source: https://context7.com/ryand56/r2-upload-action/llms.txt This example shows how to specify a custom jurisdiction for the R2 bucket endpoint, useful for EU-resident buckets, and sets a destination directory. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} r2-jurisdiction: eu source-dir: dist/ destination-dir: releases/ ``` -------------------------------- ### Conditional Step Based on Upload Result Source: https://context7.com/ryand56/r2-upload-action/llms.txt Execute subsequent workflow steps based on the `result` output of the upload action. This example checks if all files were uploaded successfully. ```yaml - name: Conditional step on upload result if: steps.upload.outputs.result == 'success' run: | echo "All files uploaded successfully" echo "URLs: ${{ steps.upload.outputs.file-urls }}" ``` -------------------------------- ### R2 Upload with File Synchronization Source: https://context7.com/ryand56/r2-upload-action/llms.txt This example enables the 'keep-file-fresh' option, which deletes existing objects in the destination directory before uploading new files, ensuring the bucket mirrors the source directory. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: site/ destination-dir: production/ keep-file-fresh: true # Deletes old files in production/ before uploading ``` -------------------------------- ### Basic GitHub Action Usage for R2 Upload Source: https://github.com/ryand56/r2-upload-action/blob/master/README.md Demonstrates the fundamental configuration for uploading files from a local directory to a Cloudflare R2 bucket using the action. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: src destination-dir: ./ ``` -------------------------------- ### Upload with Output File URLs Enabled Source: https://context7.com/ryand56/r2-upload-action/llms.txt Configure the action to output a JSON map of local file paths to their pre-signed R2 URLs. Consume these URLs in subsequent workflow steps using `steps..outputs.file-urls`. ```yaml jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Upload to R2 id: upload uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: dist/ output-file-url: true - name: Print uploaded URLs run: echo "${{ steps.upload.outputs.file-urls }}" # Output example: # { "dist/index.html": "https://...", "dist/app.js": "https://..." } ``` -------------------------------- ### Advanced GitHub Action Configuration for R2 Upload Source: https://github.com/ryand56/r2-upload-action/blob/master/README.md Shows advanced configuration options for the R2 Upload Action, including specifying bucket jurisdiction, multipart upload settings, and output file URLs. ```yaml - uses: ryand56/r2-upload-action@latest # Can be any release with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} r2-jurisdiction: eu # Add if the bucket location is different from the default one source-dir: src destination-dir: artifacts # Can be anything as long as it is an actual path output-file-url: true # defaults to true multipart-size: 100 # If the file size is greater than the value provided here, then use multipart upload max-retries: 5 # The maximum number of retries it takes to upload a multipart chunk until it moves on to the next part multipart-concurrent: true # Whether to concurrently upload a multipart chunk keep-file-fresh: false # defaults to false ``` -------------------------------- ### Create Feature Branch Source: https://github.com/ryand56/r2-upload-action/blob/master/CONTRIBUTING.md Use this command to create a new branch for your feature or bugfix. ```git git checkout -b patch-1 ``` -------------------------------- ### Commit Changes Source: https://github.com/ryand56/r2-upload-action/blob/master/CONTRIBUTING.md Stage and commit your changes to the current branch. ```git git commit -m 'Add some code' ``` -------------------------------- ### Integration Test for R2 Upload Action Source: https://context7.com/ryand56/r2-upload-action/llms.txt An integration test written in TypeScript using `github-action-ts-run-api` to verify the action's functionality. It tests uploading a directory to the root of an R2 bucket. ```typescript // tests/action.test.ts — integration test pattern import { RunOptions, RunTarget } from "github-action-ts-run-api"; import * as dotenv from "dotenv"; dotenv.config(); describe("r2-upload-action", () => { const target = process.env.CI ? RunTarget.mainJs("action.yml") : RunTarget.jsFile("dist/index.js", "action.yml"); it("Upload test directory to root of R2", async () => { const options = RunOptions.create({ inputs: { "r2-account-id": process.env.TEST_R2_ACCOUNT_ID, "r2-access-key-id": process.env.TEST_R2_AKID, "r2-secret-access-key": process.env.TEST_R2_SECRET_AK, "r2-bucket": process.env.TEST_R2_BUCKET, "source-dir": "tests/dir/", "destination-dir": "./" } }); const res = await target.run(options); expect(res.isSuccess).toEqual(true); }); }); ``` -------------------------------- ### R2 Upload with Custom Multipart Size and Retries Source: https://context7.com/ryand56/r2-upload-action/llms.txt This configuration sets a custom threshold for multipart uploads and enables concurrent part uploads. It also configures retry attempts and timeout. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: backups/ multipart-size: 50 # Files > 50 MB use multipart upload multipart-concurrent: true # Upload all parts concurrently max-retries: 3 retry-timeout: 1000 # ms between retries ``` -------------------------------- ### Upload with Custom Character Set Source: https://context7.com/ryand56/r2-upload-action/llms.txt Append a `; charset=` suffix to the MIME `Content-Type` header for uploaded files. This is useful for serving text files with explicit character encoding. ```yaml - uses: ryand56/r2-upload-action@latest with: r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET }} source-dir: public/ custom-charset: utf-8 # Results in Content-Type: text/html; charset=utf-8 ``` -------------------------------- ### Push Changes Source: https://github.com/ryand56/r2-upload-action/blob/master/CONTRIBUTING.md Push your committed changes to the remote feature branch. ```git git push origin patch-1 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.