### Deploying Pages Project with Account ID Source: https://context7.com/cloudflare/wrangler-action/llms.txt This example demonstrates deploying a Pages project. It requires both the API token and the account ID, and specifies the command to deploy the contents of the `./dist` directory to a project named `my-site`. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy ./dist --project-name=my-site ``` -------------------------------- ### Basic Deployment with API Token Source: https://context7.com/cloudflare/wrangler-action/llms.txt This snippet shows the basic setup for deploying a Worker using the wrangler-action. It requires an API token for authentication and checks out the repository code. ```yaml name: Deploy Worker on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} # Output: ✅ Wrangler Action completed ``` -------------------------------- ### Using a Wrangler Version Range Source: https://context7.com/cloudflare/wrangler-action/llms.txt This example specifies a version range for Wrangler (`^4.0.0`), allowing the action to use any version within that range. This provides flexibility while maintaining some control over the Wrangler version. ```yaml # Or use a range - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} wranglerVersion: "^4.0.0" ``` -------------------------------- ### Binding Environment Variables to Deploy Command Source: https://context7.com/cloudflare/wrangler-action/llms.txt This example shows how to bind plain environment variables to the deploy command using the `vars` input. The variable names are listed, and their values are provided in the workflow's `env` block. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} vars: | APP_VERSION SENTRY_DSN env: APP_VERSION: "2.1.0" SENTRY_DSN: ${{ secrets.SENTRY_DSN }} ``` -------------------------------- ### Executing Multiple Wrangler Commands Source: https://context7.com/cloudflare/wrangler-action/llms.txt This example shows how to execute multiple Wrangler commands sequentially. It first lists available Pages projects and then deploys a specific project, utilizing GitHub Actions expressions for dynamic values. ```yaml # Multi-line commands - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: | pages project list pages deploy ./dist --project-name=my-pages-site --branch=${{ github.ref_name }} ``` -------------------------------- ### Basic Wrangler Action Deployment Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md A fundamental setup for deploying an application using the Wrangler Action. Ensure your `accountId` is correctly set in `wrangler.toml` or provided as an input. ```yaml on: [push] jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Deploy app uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} ``` -------------------------------- ### Configure Wrangler Action with Specific Version Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Pass `wranglerVersion` to install a specific version of Wrangler from NPM. Accepts any version format NPM understands. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} wranglerVersion: "4" ``` -------------------------------- ### Schedule Worker Deployment with Cron Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Use the `schedule` trigger with cron syntax to deploy Workers on a recurring basis. This example deploys at the beginning of every hour. ```yaml on: schedule: - cron: "0 * * * *" jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Deploy app uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} ``` -------------------------------- ### Run Pre/Post Commands with Wrangler Action Source: https://context7.com/cloudflare/wrangler-action/llms.txt Execute shell commands before or after the main Wrangler deployment command. Commands starting with 'wrangler' are automatically prefixed with the package manager executor. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} preCommands: | echo "Building..." npm run build wrangler kv:key put --binding=CONFIG version "${{ github.sha }}" command: deploy postCommands: | echo "Deployed commit ${{ github.sha }}" wrangler tail --format=pretty --status=ok ``` -------------------------------- ### Suppress Wrangler Output with 'quiet' Option Source: https://context7.com/cloudflare/wrangler-action/llms.txt Set to 'true' to suppress most log output from Wrangler. Installation confirmation and action completion/failure messages are always shown. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} quiet: "true" # Suppresses group headers and wrangler stdout/stderr in GitHub Actions log ``` -------------------------------- ### Get Deployment URL from Wrangler Action Output Source: https://context7.com/cloudflare/wrangler-action/llms.txt Retrieve the URL of the deployed Worker or Pages site using `steps..outputs.deployment-url`. This output is available after deploy, pages deploy, or versions upload commands. ```yaml - name: Deploy Worker id: deploy uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: deploy - name: Notify Slack run: | curl -X POST $SLACK_WEBHOOK \ -H 'Content-type: application/json' \ --data '{"text":"Deployed to ${{ steps.deploy.outputs.deployment-url }}"}' env: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} # Example output: https://my-worker.example.workers.dev ``` -------------------------------- ### Execute Wrangler 'whoami' Command Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Use the `command` option to perform specific actions, such as running `wrangler whoami` against your project. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: whoami ``` -------------------------------- ### Create a Changeset Source: https://github.com/cloudflare/wrangler-action/blob/main/CONTRIBUTING.md Use this command to create a new changeset for tracking project changes. Follow the prompts to select affected workspaces and release type, then update the changeset with a description. ```bash npx changeset ``` -------------------------------- ### createJobSummary Source: https://context7.com/cloudflare/wrangler-action/llms.txt Writes a Markdown table to the GitHub Actions job summary, displaying commit hash, preview URL, and branch preview URL. ```APIDOC ## createJobSummary(params) ### Description Writes a Markdown table to the GitHub Actions job summary showing commit hash, preview URL, and branch preview URL. ### Parameters - **commitHash** (string) - Required - The Git commit hash. - **deploymentUrl** (string) - Required - The URL of the main deployment. - **aliasUrl** (string) - Required - The URL of the branch-specific preview deployment. ### Request Example ```typescript import { createJobSummary } from "./src/service/github"; await createJobSummary({ commitHash: "a1b2c3d4", deploymentUrl: "https://my-site.pages.dev", aliasUrl: "https://feature-branch.my-site.pages.dev", }); ``` ### Response Writes to job summary: ```markdown # Deploying with Cloudflare Pages | Name | Result | | ----------------------- | - | | **Last commit:** | a1b2c3d4 | | **Preview URL**: | https://my-site.pages.dev | | **Branch Preview URL**: | https://feature-branch.my-site.pages.dev | ``` ``` -------------------------------- ### createGitHubDeployment Source: https://context7.com/cloudflare/wrangler-action/llms.txt Creates a GitHub Deployment resource and marks it as success. It uses the current branch to determine if it's a production deployment. ```APIDOC ## createGitHubDeployment(params) ### Description Creates a GitHub Deployment resource pointing to the Cloudflare Pages deployment URL and marks it as `success`. Uses the current branch to determine if this is a production deployment. ### Parameters - **config** (WranglerActionConfig) - Required - Configuration for the Wrangler Action, requires CLOUDFLARE_ACCOUNT_ID. - **octokit** (Octokit) - Required - An authenticated Octokit instance. - **productionBranch** (string) - Required - The name of the production branch. - **environment** (string) - Required - The deployment environment (e.g., 'production'). - **deploymentId** (string) - Required - The Cloudflare Pages deployment ID. - **projectName** (string) - Required - The name of the Cloudflare Pages project. - **deploymentUrl** (string) - Required - The URL of the Cloudflare Pages deployment. ### Request Example ```typescript import { createGitHubDeployment } from "./src/service/github"; import { getOctokit } from "@actions/github"; const octokit = getOctokit(process.env.GITHUB_TOKEN!); await createGitHubDeployment({ config, octokit, productionBranch: "main", environment: "production", deploymentId: "abc123def456", projectName: "my-pages-site", deploymentUrl: "https://my-pages-site.pages.dev", }); ``` ### Response Creates deployment + deployment status in the GitHub repo. ### Response Example `log_url` → `https://dash.cloudflare.com//pages/view/my-pages-site/abc123def456` ``` -------------------------------- ### Enable GitHub Deployments and Job Summaries Source: https://context7.com/cloudflare/wrangler-action/llms.txt Provide a GitHub token to create GitHub Deployments and write job summaries after a Pages deployment. Requires Wrangler version 3.89.0 or later for full metadata. ```yaml - name: Deploy to Pages id: deploy uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy ./dist --project-name=my-site gitHubToken: ${{ secrets.GITHUB_TOKEN }} # Creates a GitHub Deployment entry with environment_url pointing to the Pages URL # Writes a job summary table with commit hash, preview URL, and branch preview URL ``` -------------------------------- ### Create GitHub Deployment with Octokit Source: https://context7.com/cloudflare/wrangler-action/llms.txt Creates a GitHub Deployment resource and status. Uses the current branch to determine if it's a production deployment. Requires WranglerActionConfig with CLOUDFLARE_ACCOUNT_ID. ```typescript import { createGitHubDeployment } from "./src/service/github"; import { getOctokit } from "@actions/github"; const octokit = getOctokit(process.env.GITHUB_TOKEN!); await createGitHubDeployment({ config, octokit, productionBranch: "main", environment: "production", deploymentId: "abc123def456", projectName: "my-pages-site", deploymentUrl: "https://my-pages-site.pages.dev", }); // Creates deployment + deployment status in the GitHub repo // log_url → https://dash.cloudflare.com//pages/view/my-pages-site/abc123def456 ``` -------------------------------- ### Configure Wrangler Action with Working Directory Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Use the `workingDirectory` key to specify a subdirectory of the repo to run the Wrangler command from. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} workingDirectory: "subfoldername" ``` -------------------------------- ### Executing a Single Wrangler Command Source: https://context7.com/cloudflare/wrangler-action/llms.txt This snippet demonstrates how to execute a single Wrangler command, `whoami`, using the action. This is useful for tasks like checking authentication or retrieving account information. ```yaml # Single command - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: whoami ``` -------------------------------- ### Configure Wrangler Action with Pre and Post Commands Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Specify shell commands to run before (`preCommands`) or after (`postCommands`) the main Wrangler command. These can include other `wrangler` commands or any available command in the action's context. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} preCommands: echo "*** pre command ***" postCommands: | echo "*** post commands ***" wrangler kv:key put --binding=MY_KV key2 value2 echo "******" ``` -------------------------------- ### Deploy Pages Application and Print Deployment URL Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Use this snippet to deploy a Pages application and then access its deployment URL via the `deployment-url` output variable. Ensure your `wrangler.toml` is configured correctly. ```yaml - name: Deploy id: deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy --project-name=example - name: print deployment-url env: DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }} run: echo $DEPLOYMENT_URL ``` -------------------------------- ### Parse First Valid Wrangler Output Entry with getOutputEntry Source: https://context7.com/cloudflare/wrangler-action/llms.txt Reads artifact files line by line, parsing each as JSON and validating against specific Zod schemas. Returns the first matching entry or null. Handles different output types like `pages-deploy-detailed`, `deploy`, and `version-upload`. ```typescript import { getOutputEntry } from "./src/wranglerArtifactManager"; const entry = await getOutputEntry("/tmp/wranglerArtifacts-abc123"); if (entry === null) { console.log("No structured output found, falling back to stdout parsing"); } else if (entry.type === "pages-deploy-detailed") { console.log("Pages URL:", entry.url); console.log("Alias URL:", entry.alias); console.log("Deployment ID:", entry.deployment_id); console.log("Environment:", entry.environment); // "production" | "preview" } else if (entry.type === "deploy") { console.log("Worker URLs:", entry.targets); // entry.targets → ["https://my-worker.example.workers.dev"] } else if (entry.type === "version-upload") { console.log("Preview URL:", entry.preview_url); } ``` -------------------------------- ### List Wrangler Output Files with getWranglerArtifacts Source: https://context7.com/cloudflare/wrangler-action/llms.txt Scans a directory for Wrangler's structured NDJSON output files matching the pattern `wrangler-output--.json`. Returns an array of absolute file paths. Returns an empty array if the directory does not exist. ```typescript import { getWranglerArtifacts } from "./src/wranglerArtifactManager"; const files = await getWranglerArtifacts("/tmp/wranglerArtifacts-abc123"); // files → ["/tmp/wranglerArtifacts-abc123/wrangler-output-2024-01-15_10-30-00_123-a1b2c3.json"] // Returns [] if directory does not exist const empty = await getWranglerArtifacts("/tmp/nonexistent"); // empty → [] ``` -------------------------------- ### Deploy Pages Site (Production & Preview) Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Deploy a Pages project using GitHub Actions. Wrangler 2 populates commit message and branch. Pushes to non-production branches deploy as previews. Requires `accountId` and optionally `gitHubToken` for GitHub Deployments. ```yaml on: [push] jobs: deploy: runs-on: ubuntu-latest name: Deploy permissions: contents: read deployments: write steps: - uses: actions/checkout@v6 - name: Deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy YOUR_DIST_FOLDER --project-name=example # Optional: Enable this if you want to have GitHub Deployments triggered gitHubToken: ${{ secrets.GITHUB_TOKEN }} ``` -------------------------------- ### semverCompare Source: https://context7.com/cloudflare/wrangler-action/llms.txt Compares two semantic versioning strings. Returns true if the second version is greater than the first. 'latest' is treated as always greater. ```APIDOC ## semverCompare(version1, version2) ### Description Compare two semver strings. Returns `true` if `version2` is greater than `version1`. Treats `"latest"` as always greater. Used internally to select between legacy and modern Wrangler command variants. ### Parameters - **version1** (string) - Required - The first semantic version string. - **version2** (string) - Required - The second semantic version string. ### Response - **boolean** - `true` if `version2` is greater than `version1`, `false` otherwise. ### Examples ```typescript import { semverCompare } from "./src/utils"; semverCompare("3.4.0", "3.5.0"); // true — 3.5.0 > 3.4.0 semverCompare("3.4.0", "3.4.0"); // false — equal semverCompare("3.4.0", "3.3.0"); // false — 3.3.0 < 3.4.0 semverCompare("3.4.0", "latest"); // true — "latest" always wins // Internal usage pattern: const useBulkSecrets = semverCompare("3.4.0", wranglerVersion); // → uses `wrangler secret bulk` for wrangler >= 3.4.0 ``` ``` -------------------------------- ### Basic Wrangler Action Deployment Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Use this snippet to deploy a Worker on a git push to the main branch. Ensure your Cloudflare API token is configured as a GitHub secret. ```yaml name: Deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} ``` -------------------------------- ### Handle Command Output Parsing in GitHub Actions Source: https://context7.com/cloudflare/wrangler-action/llms.txt Orchestrates output parsing for GitHub Actions, reading Wrangler artifact directories and setting outputs. Falls back to regex-based stdout parsing for older Wrangler versions. Can also trigger deployment summaries if GITHUB_TOKEN is present. ```typescript import { handleCommandOutputParsing } from "./src/commandOutputParsing"; // Called internally after every wrangler command execution: await handleCommandOutputParsing( config, // WranglerActionConfig "pages deploy ./dist --project-name=my-site", stdOut, // raw stdout string from wrangler ); // Sets: deployment-url, pages-deployment-alias-url, pages-deployment-id, pages-environment // Also triggers createGitHubDeploymentAndJobSummary if GITHUB_TOKEN is present ``` -------------------------------- ### Execute Shell Command Source: https://context7.com/cloudflare/wrangler-action/llms.txt Wraps Node's child_process.exec with promise support, optional output silencing, and structured error reporting. Used for pre/post commands not purely Wrangler commands. ```typescript import { execShell } from "./src/exec"; // Run a build step before deploying const exitCode = await execShell("npm run build", { cwd: "./packages/my-worker", silent: false, // streams stdout/stderr to process output }); // Prints: [command]npm run build // On failure: try { await execShell("exit 1", { silent: true }); } catch (err) { // Error: Process failed with exit code 1 } ``` -------------------------------- ### execShell Source: https://context7.com/cloudflare/wrangler-action/llms.txt Runs an arbitrary shell command, wrapping Node's child_process.exec with promise support and structured error reporting. ```APIDOC ## execShell(command, options) ### Description Wraps Node's `child_process.exec` with promise support, optional output silencing, and structured error reporting. Used for `preCommands`/`postCommands` that are not pure Wrangler commands. ### Parameters - **command** (string) - Required - The shell command to execute. - **options** (object) - Optional - Configuration options for the command execution. - **cwd** (string) - Optional - The current working directory for the command. - **silent** (boolean) - Optional - If true, stdout/stderr will not be streamed to the process output. Defaults to false. ### Request Example ```typescript import { execShell } from "./src/exec"; // Run a build step before deploying const exitCode = await execShell("npm run build", { cwd: "./packages/my-worker", silent: false, // streams stdout/stderr to process output }); // Prints: [command]npm run build // On failure: try { await execShell("exit 1", { silent: true }); } catch (err) { // Error: Process failed with exit code 1 } ``` ### Response - **exitCode** (number) - The exit code of the executed shell command. ### Error Handling Throws an error if the process fails with a non-zero exit code. ``` -------------------------------- ### Set Working Directory for Wrangler Action Source: https://context7.com/cloudflare/wrangler-action/llms.txt Specify a subdirectory containing wrangler.toml to run Wrangler commands from. This is equivalent to changing the directory before executing Wrangler. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} workingDirectory: "packages/my-worker" # Equivalent to: cd packages/my-worker && npx wrangler deploy ``` -------------------------------- ### Deploy Pages Preview with Wrangler Action Source: https://context7.com/cloudflare/wrangler-action/llms.txt Use this snippet to deploy a Pages project using the Wrangler Action. Ensure Wrangler version is 3.81.0 or higher for full output support. The alias URL is available since Wrangler 3.78.0. ```yaml - name: Deploy Pages Preview id: pages uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy ./dist --project-name=my-site ``` -------------------------------- ### Compare Semver Strings Source: https://context7.com/cloudflare/wrangler-action/llms.txt Compares two semantic version strings, returning true if the second version is greater. Treats 'latest' as always greater. Used for selecting Wrangler command variants. ```typescript import { semverCompare } from "./src/utils"; semverCompare("3.4.0", "3.5.0"); // true — 3.5.0 > 3.4.0 semverCompare("3.4.0", "3.4.0"); // false — equal semverCompare("3.4.0", "3.3.0"); // false — 3.3.0 < 3.4.0 semverCompare("3.4.0", "latest"); // true — "latest" always wins // Internal usage pattern: const useBulkSecrets = semverCompare("3.4.0", wranglerVersion); // → uses `wrangler secret bulk` for wrangler >= 3.4.0 ``` -------------------------------- ### Write GitHub Actions Job Summary Source: https://context7.com/cloudflare/wrangler-action/llms.txt Writes a Markdown table to the GitHub Actions job summary. Includes commit hash, preview URL, and branch preview URL. ```typescript import { createJobSummary } from "./src/service/github"; await createJobSummary({ commitHash: "a1b2c3d4", deploymentUrl: "https://my-site.pages.dev", aliasUrl: "https://feature-branch.my-site.pages.dev", }); // Writes to job summary: // # Deploying with Cloudflare Pages // | Name | Result | // | ----------------------- | - | // | **Last commit:** | a1b2c3d4 | // | **Preview URL**: | https://my-site.pages.dev | // | **Branch Preview URL**: | https://feature-branch.my-site.pages.dev | ``` -------------------------------- ### Targeting a Specific Wrangler Environment Source: https://context7.com/cloudflare/wrangler-action/llms.txt This configuration specifies a target environment ('production') for Wrangler commands like `deploy` or `publish`. The environment must be defined in the `wrangler.toml` file. ```yaml # wrangler.toml has [env.production] defined - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} environment: production command: deploy --env production ``` -------------------------------- ### Comment PR with Pages Deployment Preview URL Source: https://context7.com/cloudflare/wrangler-action/llms.txt This GitHub Actions script comments on a Pull Request with details of a Pages deployment, including the URL, branch URL, environment, and deployment ID. It relies on the `pages` step defined previously to access these outputs. ```javascript - name: Comment PR with preview URL uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: [ '## Preview Deployment', `- **URL**: ${{ steps.pages.outputs.deployment-url }}`, `- **Branch URL**: ${{ steps.pages.outputs.pages-deployment-alias-url }}`, `- **Environment**: ${{ steps.pages.outputs.pages-environment }}`, `- **Deployment ID**: ${{ steps.pages.outputs.pages-deployment-id }}` ].join('\n') }) ``` -------------------------------- ### Capture Wrangler stdout/stderr Outputs Source: https://context7.com/cloudflare/wrangler-action/llms.txt Access raw stdout and stderr from the executed Wrangler command in subsequent workflow steps using `steps..outputs.command-output` and `steps..outputs.command-stderr`. ```yaml - name: Deploy id: deploy uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: deploy - name: Use output run: | echo "stdout: $CMD_OUT" echo "stderr: $CMD_ERR" env: CMD_OUT: ${{ steps.deploy.outputs.command-output }} CMD_ERR: ${{ steps.deploy.outputs.command-stderr }} ``` -------------------------------- ### Execute Multi-line Wrangler Command Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Provide a multi-line command to the `command` option for executing sequential Wrangler operations. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: | pages project list pages deploy .vercel/output/static --project-name=demo-actions --branch=test ``` -------------------------------- ### Uploading Worker Secrets Source: https://context7.com/cloudflare/wrangler-action/llms.txt This snippet demonstrates uploading multiple secrets to a Worker environment. It uses the `secrets` input to list secret names and relies on the workflow's `env` block to provide their values. This utilizes `wrangler secret bulk` for atomic uploads. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} environment: production secrets: | DATABASE_URL STRIPE_SECRET_KEY SENDGRID_API_KEY env: DATABASE_URL: ${{ secrets.DATABASE_URL }} STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} # Result: All three secrets uploaded atomically via secret bulk ``` -------------------------------- ### Manually Trigger Worker Deployment with Workflow Dispatch Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Trigger a workflow manually using GitHub's `workflow_dispatch` event. This allows for deployments via the GitHub UI and accepts inputs to configure the action, such as the deployment environment. ```yaml on: workflow_dispatch: inputs: environment: description: "Choose an environment to deploy to: " required: true default: "dev" jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Deploy app uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: deploy --env ${{ github.event.inputs.environment }} ``` -------------------------------- ### Use Wrangler Command Output in Subsequent Steps Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Capture and utilize the output of Wrangler commands in subsequent workflow steps using the `command-output` output variable. This allows for parsing command results for use in other actions or for logging. ```yaml - name: Deploy id: deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: pages deploy --project-name=example - name: print wrangler command output env: CMD_OUTPUT: ${{ steps.deploy.outputs.command-output }} run: echo $CMD_OUTPUT ``` -------------------------------- ### Add Changeset to Git Source: https://github.com/cloudflare/wrangler-action/blob/main/CONTRIBUTING.md After generating a changeset, add the created changeset markdown file to your current commit. ```bash git add ./changeset/*.md ``` -------------------------------- ### Pin Wrangler Action to v3 Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md If you need to stay on Wrangler v3, pin the action version explicitly. This ensures compatibility with older Wrangler versions. ```yaml uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} wranglerVersion: "3.90.0" ``` -------------------------------- ### Configure Wrangler Action with Secrets and Environment Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Pass worker secrets via `secrets` as a string of names separated by newlines. Each secret name must match an environment variable in the `env` field. Optionally specify the worker environment. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} environment: production secrets: | SECRET1 SECRET2 env: SECRET1: ${{ secrets.SECRET1 }} SECRET2: ${{ secrets.SECRET2 }} ``` -------------------------------- ### Configure API Token Authentication Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Pass your Cloudflare API token to the action using GitHub Secrets. The token is encrypted and not printed to logs. ```yaml jobs: deploy: name: Deploy steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} ``` -------------------------------- ### Pinning Wrangler to an Exact Version Source: https://context7.com/cloudflare/wrangler-action/llms.txt This configuration pins the wrangler-action to use a specific version of Wrangler (v3.90.0). This ensures consistent behavior by avoiding updates to newer major versions. ```yaml # Pin to an exact version - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} wranglerVersion: "3.90.0" # stay on Wrangler v3 ``` -------------------------------- ### Print Pages Deployment Alias URL Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Access the alias URL for Pages deployments using the `pages-deployment-alias-url` output variable. This is particularly useful for branch aliases on preview deployments. ```yaml - name: print pages-deployment-alias-url env: DEPLOYMENT_ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }} run: echo $DEPLOYMENT_ALIAS_URL ``` -------------------------------- ### Resolve Package Manager Commands with getPackageManager Source: https://context7.com/cloudflare/wrangler-action/llms.txt This utility function resolves package manager commands. It can auto-detect the package manager from lockfiles in a specified working directory or accept an explicit name. An invalid package manager name will throw a TypeError. ```typescript import { getPackageManager } from "./src/packageManagers"; // Auto-detect from lockfile in ./my-worker (finds pnpm-lock.yaml) const pm = getPackageManager("", { workingDirectory: "./my-worker" }); // pm.install → "pnpm add" // pm.exec → "pnpm exec" // pm.execNoInstall → "pnpm exec" // Explicit override const npm = getPackageManager("npm"); // npm.install → "npm i" // npm.exec → "npx" // npm.execNoInstall → "npx --no-install" // Invalid value throws try { getPackageManager("cargo"); } catch (e) { // TypeError: invalid value provided for "packageManager": cargo // Value must be one of: [npm, yarn, pnpm, bun] } ``` -------------------------------- ### Deploy Worker on Main Branch Push Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md This workflow deploys a Worker when new commits are merged to the main branch. It serves as a basic integration step for `wrangler-action`. ```yaml on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} ``` -------------------------------- ### Upload Worker Version for Later Deployment Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Upload a new Worker version without immediate deployment using `wrangler versions upload`. Requires Wrangler v3.40.0 or above. Versions can be deployed later via `wrangler versions deploy` or the Cloudflare dashboard. ```yaml jobs: upload: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v6 - name: Upload Worker Version uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: versions upload ``` -------------------------------- ### Override Package Manager Detection in Wrangler Action Source: https://context7.com/cloudflare/wrangler-action/llms.txt Force the action to use a specific package manager. If omitted, the action auto-detects based on lockfile presence. ```yaml - uses: cloudflare/wrangler-action@v4 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} packageManager: pnpm # Uses: pnpm add wrangler@4 / pnpm exec wrangler deploy ``` -------------------------------- ### Specify Package Manager in Wrangler Action Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Override the default package manager detection by setting the `packageManager` input. This is useful when you need to enforce a specific manager like pnpm. ```yaml jobs: deploy: steps: uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} packageManager: pnpm ``` -------------------------------- ### Set Environment-Specific Worker Secret Source: https://github.com/cloudflare/wrangler-action/blob/main/README.md Configure a Worker secret for a specific environment by setting the `environment` parameter and defining the secret in the `env` block. The secret value is passed from GitHub secrets. ```yaml - uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} command: deploy --env production secrets: | SUPER_SECRET environment: production env: SUPER_SECRET: ${{ secrets.SUPER_SECRET }} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.