Compare commits
353 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e804ea3dfd | |||
| 8d0324a88e | |||
| 2f18b18a46 | |||
| 622ff0d765 | |||
| f501f05fbd | |||
| f990691b6b | |||
| 652762d3f6 | |||
| bd3f4f0b30 | |||
| 38dbf5b59f | |||
| cdf65921e0 | |||
| bfdfae5e0f | |||
| a3edea85f7 | |||
| b6290ea70c | |||
| 65553b39e6 | |||
| 4f154b96e0 | |||
| 5f269ee58e | |||
| d181764e4b | |||
| 3c924dd85f | |||
| c1f90e624b | |||
| 0501554080 | |||
| d8f3eaa359 | |||
| febbda69f8 | |||
| 59b83385d8 | |||
| dd8ea1b72d | |||
| 1029e90033 | |||
| 707f637509 | |||
| e764ef3355 | |||
| 8d761e6bdc | |||
| cd6314a97b | |||
| ef1f9fb2b0 | |||
| 08959b2671 | |||
| abb67eda8d | |||
| 883eaf2de0 | |||
| 4ff07f4310 | |||
| 4fb15f8b7a | |||
| e8cd5f0968 | |||
| e209094e62 | |||
| 181b9fb5d6 | |||
| aac328d155 | |||
| fc89533f1e | |||
| e819570b2d | |||
| 923db6f87f | |||
| d5031c3dbe | |||
| 17da943335 | |||
| 3aee84cd6d | |||
| 9d9bee8bfd | |||
| ee57f258dc | |||
| 9fed19aa4e | |||
| 3c6e4da7b3 | |||
| 1c0eef186f | |||
| b19342b08c | |||
| d44c80928a | |||
| cada7a6312 | |||
| 1e92eee7d2 | |||
| e7e5400334 | |||
| d58f116d72 | |||
| 64b6339110 | |||
| ac2fd0ec8f | |||
| 0140ffbc93 | |||
| cc4ede3f06 | |||
| 9bf87caf2b | |||
| 81f8814855 | |||
| 6c6d3321ef | |||
| bc61e66e47 | |||
| 0e2b86ba21 | |||
| 59c0462940 | |||
| 4c3f0c27ea | |||
| 4d045615a9 | |||
| a7a2388d7b | |||
| 95555f6ed0 | |||
| 2171bbdd69 | |||
| 4f4ff59d17 | |||
| 122ee5cf5b | |||
| 44d79edf44 | |||
| b2be7abbfc | |||
| b7158dc9a4 | |||
| 43767e73de | |||
| 10d5b9c1c1 | |||
| c01035706f | |||
| fa96c39bd4 | |||
| 78dad1df07 | |||
| 3ec7f8943e | |||
| cd8a317efb | |||
| 6aa2e8946a | |||
| de0526e09b | |||
| 84316ca95c | |||
| 134b5c2a32 | |||
| 47d51f25c1 | |||
| 93fff4f656 | |||
| 66334dff0a | |||
| 9966912c1b | |||
| 7b9aec5185 | |||
| c0e117f512 | |||
| bcff5386ec | |||
| c15498da36 | |||
| 8bc5c5f050 | |||
| ac21b71592 | |||
| f111269956 | |||
| 570d521df6 | |||
| 174337b3b4 | |||
| a1467a0c8f | |||
| 3ea6e3f132 | |||
| ea11499226 | |||
| 8f2f89521c | |||
| 66efca2cbb | |||
| aa5d18dd1e | |||
| b84268f0e0 | |||
| d1b97ebf4d | |||
| baf8bc61f1 | |||
| 8edd152f63 | |||
| 2d275a8f2d | |||
| 8ef515f899 | |||
| 9b27cf271c | |||
| 405a82610b | |||
| 0545ad285a | |||
| ea5754c9ad | |||
| 983b6349c2 | |||
| b05934f581 | |||
| 31a6263ef3 | |||
| 88906781f0 | |||
| ebef541795 | |||
| 9d4ca0f255 | |||
| 1be73b90f6 | |||
| 180648017b | |||
| 9003b06015 | |||
| fd98a7c990 | |||
| 4bf3047bb8 | |||
| f2c22accd3 | |||
| 0c36639f72 | |||
| d5a1abb013 | |||
| c214b69bae | |||
| bac2829d42 | |||
| 78c994fb95 | |||
| e3434a7e98 | |||
| 08514fdece | |||
| 7451182d38 | |||
| 522c117b7d | |||
| b92719544e | |||
| bbedd8e54f | |||
| ebaf896045 | |||
| 7e684fbad9 | |||
| 2521ec00cc | |||
| ba0f485178 | |||
| 2de0b3dfd8 | |||
| f2d9b652c4 | |||
| 0e62acaf21 | |||
| bd3857047e | |||
| d13856dfc9 | |||
| f88aee4953 | |||
| a5f361f3f0 | |||
| 9aba9c34da | |||
| 9dd38ad790 | |||
| 1599928d8e | |||
| 0fff39f4b7 | |||
| ca0bf5eeba | |||
| 97c920b38e | |||
| 11fa60953d | |||
| 5ee7b681bc | |||
| 74a612d924 | |||
| 0558fc8c04 | |||
| 976ec4d78c | |||
| a8845f6d95 | |||
| 8d6fade5ad | |||
| 65996a5230 | |||
| 2b7ed1316d | |||
| 9554b3575b | |||
| 57159ca2ed | |||
| 7dd5c3621b | |||
| 581e17bc51 | |||
| 21a8414ba3 | |||
| 819ea006e6 | |||
| 473d9cbd29 | |||
| 76d614f400 | |||
| d647227bbc | |||
| 533097350a | |||
| bc7253f187 | |||
| b2e459a047 | |||
| 96c3774b77 | |||
| b00f94ea6f | |||
| c649733249 | |||
| d43f9c81c7 | |||
| 219a0887d7 | |||
| 25b114f472 | |||
| f40a9f5f82 | |||
| bd06b290b1 | |||
| a4509d507c | |||
| 0e6f0d3080 | |||
| 326ba30882 | |||
| 032a7248fa | |||
| 080373bdb6 | |||
| 231d787db1 | |||
| d9a0a00f8b | |||
| 779191a652 | |||
| 556068fb59 | |||
| caa59485d0 | |||
| c2494c1ca6 | |||
| 528687aaf4 | |||
| bd50d10af9 | |||
| 2513ffc6cc | |||
| 9df50d42e4 | |||
| 4611c14c05 | |||
| ac3f259fcf | |||
| b2645622e9 | |||
| f4e6269765 | |||
| 72931e59b2 | |||
| e0254d06bc | |||
| 13d70757d2 | |||
| aec73ae744 | |||
| f0cc3efccf | |||
| 50b529e7b8 | |||
| 6771675815 | |||
| 4ae0557f8d | |||
| 7d7b98826e | |||
| d1073d57ba | |||
| c3b99e2c18 | |||
| 2375787b23 | |||
| 11f981cea4 | |||
| 868dbd9a40 | |||
| a009342d77 | |||
| f2e4cda4dd | |||
| f4f2e854d7 | |||
| cbe5f5b523 | |||
| fcf2d83f3d | |||
| f5d1ca36ae | |||
| 4d6d6abfb4 | |||
| 416205365a | |||
| 7292a4ae99 | |||
| 4528b66125 | |||
| ee3e2a9b37 | |||
| 361844799a | |||
| 26103fa86c | |||
| 47d4afdbd8 | |||
| d7637bf514 | |||
| 71199d2757 | |||
| 2962e94ac8 | |||
| 5517edbb28 | |||
| f74c325efc | |||
| 105f191b19 | |||
| e5251df521 | |||
| b076e889fb | |||
| 30e126d1a4 | |||
| fcf648c789 | |||
| fcbabec21e | |||
| 0aa12f0c2b | |||
| ad7441b6ad | |||
| 3f40637a1c | |||
| 4132892387 | |||
| 62ce9d23a3 | |||
| f089b0a195 | |||
| 4318a2fb97 | |||
| c8bbc2b667 | |||
| 3c262de2e3 | |||
| 36ba30dcc9 | |||
| a9ac89cd00 | |||
| 93b26a6664 | |||
| 9641d961b5 | |||
| 5b3d60c156 | |||
| 3252711404 | |||
| 2faabf36a2 | |||
| b734d85d74 | |||
| 8ca2ff1612 | |||
| 7d08a8657e | |||
| e193627f19 | |||
| 55b80c5f62 | |||
| f61dc4d5a9 | |||
| 58f274b9f7 | |||
| ef7686b259 | |||
| d63b9dc486 | |||
| 88ccce72e0 | |||
| 554eea134a | |||
| a584cc5606 | |||
| 0f5076c3e7 | |||
| c7d1bd35bf | |||
| 3c728e1d5d | |||
| a333df3c9e | |||
| bb0133dcfc | |||
| 88466ea5ae | |||
| 74433eb31e | |||
| 559dd40fe6 | |||
| 9930080b73 | |||
| 43bbbb16ab | |||
| 598c6b4043 | |||
| 0c094f5307 | |||
| 6ea2e616f2 | |||
| 1b4a61cee9 | |||
| 8e3876a0c9 | |||
| 8fab856f8d | |||
| ce1ea4e7c3 | |||
| e420d29d0a | |||
| 311d514d9d | |||
| d05a65f82b | |||
| c9da75b82e | |||
| 29cef5effc | |||
| ee60b7bd5e | |||
| 0ab3500d54 | |||
| dfa59a861f | |||
| 342e6243b7 | |||
| d6590f86f4 | |||
| 97e54f3396 | |||
| f85e1acfa7 | |||
| e18e1dfc82 | |||
| 20ea506049 | |||
| 45c57ae013 | |||
| a5fd4fdd34 | |||
| 002bb083fa | |||
| 42c609b2d6 | |||
| c8f756bccf | |||
| 81fb6a9681 | |||
| 6231e31709 | |||
| 0c419bee6c | |||
| 74a9b9885f | |||
| 3dd57ff2bb | |||
| edb2a58814 | |||
| 4c10c1822a | |||
| 3d1979ca8e | |||
| 6f62debcf8 | |||
| 006366c1ae | |||
| 95ac136231 | |||
| a33b48c9fe | |||
| 60c377d0bf | |||
| 39c3d279a1 | |||
| 8df5ab90b3 | |||
| f4e53e2753 | |||
| 3424d15af2 | |||
| 212d5a5125 | |||
| bc7b76075d | |||
| 176cda2c0e | |||
| 93b9408aec | |||
| 6531840e6e | |||
| f871e6782e | |||
| aab79315b4 | |||
| c511ea2eb5 | |||
| 21f14faa06 | |||
| e5fc9a726a | |||
| 4259a86a6b | |||
| aabd478947 | |||
| 3123fc538b | |||
| 1202bb2fe9 | |||
| e5160f5528 | |||
| 1e37135bae | |||
| 1c9291f9bf | |||
| 8dd9410702 | |||
| 844c30604b | |||
| 312aaaeeaa | |||
| 1827c33732 | |||
| 9e7e2ec6db | |||
| 2360296525 | |||
| bc0254d9f8 | |||
| 05e5e7ad0d | |||
| 6b4d853121 | |||
| b190740662 | |||
| 8da7fa65b4 | |||
| d5240e236f |
@@ -0,0 +1,8 @@
|
||||
# Changesets
|
||||
|
||||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||
with multi-package repos, or single-package repos to help you version and deploy your code. You can
|
||||
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
||||
|
||||
We have a quick list of common questions to get you started engaging with this project in
|
||||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
|
||||
"changelog": [
|
||||
"@changesets/changelog-github",
|
||||
{ "repo": "cloudflare/wrangler-action" }
|
||||
],
|
||||
"commit": false,
|
||||
"linked": [],
|
||||
"access": "public",
|
||||
"baseBranch": "main",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": []
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
name: Wrangler Action Self Testing
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
wrangler_action_self_testing:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "npm"
|
||||
|
||||
- name: Install modules and build
|
||||
run: npm ci && npm run build
|
||||
|
||||
- name: Unit Tests
|
||||
run: npm run test
|
||||
|
||||
- name: Check Formatting
|
||||
run: npm run check
|
||||
|
||||
- name: Only build app
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/only-build"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Only build app w/ quiet enabled
|
||||
uses: ./
|
||||
with:
|
||||
quiet: true
|
||||
workingDirectory: "./src/test/fixtures/build-quiet"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Environment support
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/environment"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
environment: dev
|
||||
preCommands: npx wrangler deploy --env dev # https://github.com/cloudflare/wrangler-action/issues/162
|
||||
postCommands: npx wrangler delete --name wrangler-action-dev-environment-test --force
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
env:
|
||||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
|
||||
# START Setup and teardown of Workers w/ Secrets Tests
|
||||
- name: Deploy app secrets w/ hardcoded Wrangler v2
|
||||
uses: ./
|
||||
with:
|
||||
wranglerVersion: "2.20.0"
|
||||
workingDirectory: "./src/test/fixtures/secrets-v2"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
env:
|
||||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
|
||||
- name: Health Check Deployed Worker
|
||||
run: node .github/workflows/workerHealthCheck.ts wrangler-action-test-secrets-v2
|
||||
shell: bash
|
||||
|
||||
- name: Deploy app secrets w/ default version
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/secrets-default"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
env:
|
||||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
|
||||
- name: Health Check Deployed Worker
|
||||
run: node .github/workflows/workerHealthCheck.ts wrangler-action-test-secrets-default
|
||||
shell: bash
|
||||
|
||||
- name: Clean Up Deployed Workers
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/secrets-default"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: delete --name wrangler-action-test-secrets-v2 --force
|
||||
postCommands: npx wrangler delete --name wrangler-action-test-secrets-default --force
|
||||
# END Setup and teardown of Workers w/ Secrets Tests
|
||||
|
||||
- name: Support packageManager variable
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/specify-package-manager"
|
||||
packageManager: "npm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Support unspecified packageManager with no lockfile
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/unspecified-package-manager"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Support npm package manager
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/npm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Install yarn
|
||||
run: npm i -g yarn
|
||||
|
||||
- name: Support yarn package manager
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/yarn"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Install pnpm
|
||||
run: npm i -g pnpm@10
|
||||
|
||||
- name: Support pnpm package manager
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/pnpm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Change directory to pre-installed-wrangler and install dependencies
|
||||
run: |
|
||||
cd ./src/test/fixtures/pre-installed-wrangler
|
||||
npm install
|
||||
|
||||
- name: Support pre-installed wrangler
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./src/test/fixtures/pre-installed-wrangler"
|
||||
command: action-test
|
||||
@@ -0,0 +1,55 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
if: ${{ github.repository_owner == 'cloudflare' }}
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: read
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v5
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "npm"
|
||||
|
||||
- name: Install modules
|
||||
run: npm ci
|
||||
|
||||
- name: Create Version PR
|
||||
id: changesets
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
createGithubReleases: true
|
||||
publish: npx changeset tag
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build action
|
||||
if: steps.changesets.outputs.published == 'true'
|
||||
run: npm run build
|
||||
|
||||
- name: Push dist-tags
|
||||
if: steps.changesets.outputs.published == 'true'
|
||||
uses: JasonEtco/build-and-tag-action@v2
|
||||
with:
|
||||
tag_name: v${{ fromJSON(steps.changesets.outputs.publishedPackages)[0].version }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
@@ -0,0 +1,30 @@
|
||||
name: Semgrep OSS scan
|
||||
on:
|
||||
pull_request: {}
|
||||
push:
|
||||
branches: [main, master]
|
||||
workflow_dispatch: {}
|
||||
schedule:
|
||||
- cron: "0 0 20 * *"
|
||||
concurrency:
|
||||
group: semgrep-${{ github.event_name }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
semgrep:
|
||||
name: semgrep-oss
|
||||
runs-on: ubuntu-slim
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- id: cache-semgrep
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.local
|
||||
key: semgrep-1.160.0-${{ runner.os }}
|
||||
- if: steps.cache-semgrep.outputs.cache-hit != 'true'
|
||||
run: pip install --user semgrep==1.160.0
|
||||
- run: echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
- run: semgrep scan --config=auto
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Result } from "better-result";
|
||||
|
||||
async function workerHealthCheck(workerName) {
|
||||
const url = `https://${workerName}.devprod-testing7928.workers.dev/secret-health-check`;
|
||||
|
||||
const response = await fetch(url);
|
||||
const text = await response.text();
|
||||
|
||||
if (text.includes("OK")) {
|
||||
console.log(`Status: Worker is up! Response: ${text}`);
|
||||
} else {
|
||||
throw new Error(`Worker is down! Response: ${text}`);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
const args = Array.from(process.argv);
|
||||
const workerName = args.pop();
|
||||
|
||||
if (!workerName) {
|
||||
throw new Error(
|
||||
"Please provide the worker name as an argument when calling this program.",
|
||||
);
|
||||
}
|
||||
|
||||
const result = await Result.tryPromise(() => workerHealthCheck(workerName), {
|
||||
retry: {
|
||||
times: 5,
|
||||
delayMs: 2000,
|
||||
backoff: "exponential",
|
||||
},
|
||||
});
|
||||
|
||||
result.match({
|
||||
ok: () => {},
|
||||
err: (error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
},
|
||||
});
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
dist
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Node ###
|
||||
node_modules
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
|
||||
# Moved from ./templates for ignoring all locks in templates
|
||||
templates/**/*-lock.*
|
||||
templates/**/*.lock
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pnpm-lock.yaml
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"singleQuote": false,
|
||||
"semi": true,
|
||||
"useTabs": true
|
||||
}
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
# Changelog
|
||||
|
||||
## 4.0.0
|
||||
|
||||
### Major Changes
|
||||
|
||||
- [#412](https://github.com/cloudflare/wrangler-action/pull/412) [`1029e90`](https://github.com/cloudflare/wrangler-action/commit/1029e90033977ccf46c2a9b3ddc55e42ad5da467) Thanks [@ericclemmons](https://github.com/ericclemmons)! - Update default Wrangler version to v4 (`latest`). The action now installs Wrangler v4 by default when no `wranglerVersion` input is specified. Users can still pin to v3 by setting `wranglerVersion: "3.90.0"` explicitly.
|
||||
|
||||
## 3.15.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#426](https://github.com/cloudflare/wrangler-action/pull/426) [`febbda6`](https://github.com/cloudflare/wrangler-action/commit/febbda69f8c5838bf8b07fd6b9dfc836f00962db) Thanks [@WillTaylorDev](https://github.com/WillTaylorDev)! - Support version ranges and tags in `wranglerVersion` input. You can now set `wranglerVersion` to values like `4`, `^4.0.0`, `4.x`, or `latest` instead of only exact versions like `4.81.0`.
|
||||
|
||||
## 3.14.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#358](https://github.com/cloudflare/wrangler-action/pull/358) [`cd6314a`](https://github.com/cloudflare/wrangler-action/commit/cd6314a97b09d9a764e30cacd0870edc86f92986) Thanks [@penalosa](https://github.com/penalosa)! - Use `secret bulk` instead of deprecated `secret:bulk` command
|
||||
|
||||
## 3.14.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#351](https://github.com/cloudflare/wrangler-action/pull/351) [`4ff07f4`](https://github.com/cloudflare/wrangler-action/commit/4ff07f4310dc5067d84a254cd9af3d2e91df119e) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Use wrangler outputs for version upload and wrangler deploy
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#350](https://github.com/cloudflare/wrangler-action/pull/350) [`e209094`](https://github.com/cloudflare/wrangler-action/commit/e209094e624c6f6b418141b7e9d0ab7838d794a3) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Handle failures in createGitHubDeployment and createGitHubJobSummary
|
||||
|
||||
## 3.13.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#345](https://github.com/cloudflare/wrangler-action/pull/345) [`e819570`](https://github.com/cloudflare/wrangler-action/commit/e819570b2d0a69816a1c2e9d2f2954e278748d80) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - fix: Pages GitHub Deployment not triggering
|
||||
|
||||
## 3.13.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#325](https://github.com/cloudflare/wrangler-action/pull/325) [`cada7a6`](https://github.com/cloudflare/wrangler-action/commit/cada7a63124ded3471bef7e8001b76356b838e40) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Add GitHub deployments and job summaries for parity with pages-action
|
||||
|
||||
- [#334](https://github.com/cloudflare/wrangler-action/pull/334) [`9fed19a`](https://github.com/cloudflare/wrangler-action/commit/9fed19aa4ed79946f009e8aad7437a922e62d523) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Bump default wrangler version to 3.90.0
|
||||
|
||||
## 3.12.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#319](https://github.com/cloudflare/wrangler-action/pull/319) [`59c04629408d58978884fadd18755f1a15f96157`](https://github.com/cloudflare/wrangler-action/commit/59c04629408d58978884fadd18755f1a15f96157) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Fixes #317: Generate a new output directory with a randomUUID in the tmpDir, so that when the action is executed multiple times, we use the artifacts from that run, opposed to the artifacts from a previous run.
|
||||
|
||||
## 3.12.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#312](https://github.com/cloudflare/wrangler-action/pull/312) [`122ee5cf5b66847e0b6cfa67ecd9e03e38a67a42`](https://github.com/cloudflare/wrangler-action/commit/122ee5cf5b66847e0b6cfa67ecd9e03e38a67a42) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - This reapplies [303](https://github.com/cloudflare/wrangler-action/pull/303) add parity with pages-action for pages deploy outputs. Thanks @courtney-sims! - Support pages-deployment-id, pages-environment, pages-deployment-alias-url and deployment-url outputs for Pages deploys when wrangler version is >=3.81.0. deployment-alias-url was also deprecated in favour of pages-deployment-alias.
|
||||
|
||||
## 3.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#309](https://github.com/cloudflare/wrangler-action/pull/309) [`10d5b9c1c1826adaec0a9ee49fdf5b91113508ef`](https://github.com/cloudflare/wrangler-action/commit/10d5b9c1c1826adaec0a9ee49fdf5b91113508ef) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Revert "Add parity with pages-action for pages deploy outputs"
|
||||
|
||||
## 3.10.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#303](https://github.com/cloudflare/wrangler-action/pull/303) [`3ec7f8943ef83351f743cfaa8763a9056ef70993`](https://github.com/cloudflare/wrangler-action/commit/3ec7f8943ef83351f743cfaa8763a9056ef70993) Thanks [@courtney-sims](https://github.com/courtney-sims)! - Support id, environment, url, and alias outputs for Pages deploys.
|
||||
|
||||
## 3.9.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#298](https://github.com/cloudflare/wrangler-action/pull/298) [`134b5c2a3252d66b8c4d1cddd0b9baaeed6a4daa`](https://github.com/cloudflare/wrangler-action/commit/134b5c2a3252d66b8c4d1cddd0b9baaeed6a4daa) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Update wrangler version from 3.13.2 to 3.78.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#278](https://github.com/cloudflare/wrangler-action/pull/278) [`47d51f25c113ee9205110728599b43ed6a1e273b`](https://github.com/cloudflare/wrangler-action/commit/47d51f25c113ee9205110728599b43ed6a1e273b) Thanks [@acusti](https://github.com/acusti)! - fix: Detect existing wrangler install even when wrangler version output is multiline
|
||||
|
||||
## 3.8.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#291](https://github.com/cloudflare/wrangler-action/pull/291) [`a1467a0c8f2a058f8d43a4d0c40a55176ed5efe6`](https://github.com/cloudflare/wrangler-action/commit/a1467a0c8f2a058f8d43a4d0c40a55176ed5efe6) Thanks [@Ambroos](https://github.com/Ambroos)! - Adds `deployment-alias-url` output for Pages deployment aliases (since Wrangler v3.78.0): https://github.com/cloudflare/workers-sdk/pull/6643
|
||||
|
||||
## 3.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#271](https://github.com/cloudflare/wrangler-action/pull/271) [`66efca2cbb82a5a49df6af2e14c4b58d53b0e266`](https://github.com/cloudflare/wrangler-action/commit/66efca2cbb82a5a49df6af2e14c4b58d53b0e266) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - This unreverts #235 ensuring wrangler-action will re-use existing wrangler installations, thanks @AdiRishi! and ensures we don't automatically install wrangler when checking if it present
|
||||
|
||||
## 3.6.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#265](https://github.com/cloudflare/wrangler-action/pull/265) [`2d275a8f2d279dc91912c1ff8023af109ef3280c`](https://github.com/cloudflare/wrangler-action/commit/2d275a8f2d279dc91912c1ff8023af109ef3280c) Thanks [@Maximo-Guk](https://github.com/Maximo-Guk)! - Reverts #235 which may have caused the latest version of wrangler to be installed, if no wrangler version was found
|
||||
|
||||
## 3.6.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#235](https://github.com/cloudflare/wrangler-action/pull/235) [`0545ad285acaff2b92053d636ee17fb303b4c5f5`](https://github.com/cloudflare/wrangler-action/commit/0545ad285acaff2b92053d636ee17fb303b4c5f5) Thanks [@AdiRishi](https://github.com/AdiRishi)! - wrangler-action will now re-use existing wrangler installations when available
|
||||
|
||||
## 3.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#255](https://github.com/cloudflare/wrangler-action/pull/255) [`31a6263ef3ec73ff2d03cb4c0260379f96f7598c`](https://github.com/cloudflare/wrangler-action/commit/31a6263ef3ec73ff2d03cb4c0260379f96f7598c) Thanks [@matthewdavidrodgers](https://github.com/matthewdavidrodgers)! - Stop racing secret uploads
|
||||
|
||||
For up to date versions of wrangler, secrets are uploaded via the 'secret:bulk' command, which batches updates in a single API call.
|
||||
|
||||
For versions of wrangler without that capability, the action falls back to the single 'secret put' command for each secret. It races all these with a Promise.all()
|
||||
|
||||
Unfortunately, the single secret API cannot handle concurrency - at best, these calls have to wait on one another, holding requests open all the while. Often it times out and errors.
|
||||
|
||||
This fixes the legacy secret upload errors by making these calls serially instead of concurrently.
|
||||
|
||||
## 3.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#227](https://github.com/cloudflare/wrangler-action/pull/227) [`bbedd8e54f256d36f81f81f1f05b90937d533bb7`](https://github.com/cloudflare/wrangler-action/commit/bbedd8e54f256d36f81f81f1f05b90937d533bb7) Thanks [@AdiRishi](https://github.com/AdiRishi)! - Surface inner exception when secret:bulk upload command fails
|
||||
|
||||
## 3.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#213](https://github.com/cloudflare/wrangler-action/pull/213) [`d13856dfc92816473ebf47f66e263a2668a97896`](https://github.com/cloudflare/wrangler-action/commit/d13856dfc92816473ebf47f66e263a2668a97896) Thanks [@GrantBirki](https://github.com/GrantBirki)! - This change introduces three new GitHub Actions output variables. These variables are as follows:
|
||||
- `command-output` - contains the string results of `stdout`
|
||||
- `command-stderr` - contains the string results of `stderr`
|
||||
- `deployment-url` - contains the string results of the URL that was deployed (ex: `https://<your_pages_site>.pages.dev`)
|
||||
|
||||
These output variables are intended to be used by more advanced workflows that require the output results or deployment url from Wrangler commands in subsequent workflow steps.
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#216](https://github.com/cloudflare/wrangler-action/pull/216) [`9aba9c34daabca23a88191a5fe1b81fa721c1f11`](https://github.com/cloudflare/wrangler-action/commit/9aba9c34daabca23a88191a5fe1b81fa721c1f11) Thanks [@Cherry](https://github.com/Cherry)! - Fixes issues with semver comparison, where version parts were treated lexicographically instead of numerically.
|
||||
|
||||
Bulk secret uploading was introduced in wrangler `3.4.0`, and this action tries to check if the version used is greater than `3.4.0`, and then if so, using the new bulk secret API which is faster. Due to a bug in the semver comparison, `3.19.0` was being considered less than `3.4.0`, and then using an older and slower method for uploading secrets.
|
||||
|
||||
Now the semver comparison is fixed, the faster bulk method is used for uploading secrets when available.
|
||||
|
||||
## 3.3.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#171](https://github.com/cloudflare/wrangler-action/pull/171) [`76d614f`](https://github.com/cloudflare/wrangler-action/commit/76d614f400bd92237ed23c3df559f2c31b14a790) Thanks [@1000hz](https://github.com/1000hz)! - Fixed issues that caused the action to fail if any secret or var values contained shell metacharacters.
|
||||
|
||||
- [#171](https://github.com/cloudflare/wrangler-action/pull/171) [`473d9cb`](https://github.com/cloudflare/wrangler-action/commit/473d9cbd296528b41c653af10062faba6540a7ab) Thanks [@1000hz](https://github.com/1000hz)! - Bumped `DEFAULT_WRANGLER_VERSION` to 3.13.2
|
||||
|
||||
## 3.3.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#193](https://github.com/cloudflare/wrangler-action/pull/193) [`a4509d5`](https://github.com/cloudflare/wrangler-action/commit/a4509d507c62dd7f49fba7df7d2db3997222393a) Thanks [@1000hz](https://github.com/1000hz)! - Fixed the package manager not being inferred based on lockfile when the `packageManager` input isn't set.
|
||||
|
||||
## 3.3.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#188](https://github.com/cloudflare/wrangler-action/pull/188) [`d9a0a00`](https://github.com/cloudflare/wrangler-action/commit/d9a0a00f8bc502ceea2a60e5af258416b35a85b9) Thanks [@simpleauthority](https://github.com/simpleauthority)! - Added support for Bun as a package manager
|
||||
|
||||
## 3.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#190](https://github.com/cloudflare/wrangler-action/pull/190) [`528687a`](https://github.com/cloudflare/wrangler-action/commit/528687aaf436f67565918533ffd15c250f39c47b) Thanks [@1000hz](https://github.com/1000hz)! - Fixed action failure when no `packageManager` specified and no lockfile is found. The action now falls back to using npm.
|
||||
|
||||
## 3.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#166](https://github.com/cloudflare/wrangler-action/pull/166) [`7d7b988`](https://github.com/cloudflare/wrangler-action/commit/7d7b98826e14e9ad422870a7263b7074b40bf16f) Thanks [@nix6839](https://github.com/nix6839)! - Support for package managers other than npm, such as pnpm and yarn.
|
||||
|
||||
fixes #156
|
||||
|
||||
## 3.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#161](https://github.com/cloudflare/wrangler-action/pull/161) [`e5251df`](https://github.com/cloudflare/wrangler-action/commit/e5251df52154e9ebc98edb02ee0598c7210dcf0f) Thanks [@1000hz](https://github.com/1000hz)! - Refactored error handling to stop execution when action fails. Previously, the action would continue executing to completion if one of the steps encountered an error. Fixes #160.
|
||||
|
||||
## 3.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#154](https://github.com/cloudflare/wrangler-action/pull/154) [`3f40637`](https://github.com/cloudflare/wrangler-action/commit/3f40637a1c48016d2101e412a7a06f1eb4b9c2fd) Thanks [@JacobMGEvans](https://github.com/JacobMGEvans)! - feat: Quiet mode
|
||||
Some of the stderr, stdout, info & groupings can be a little noisy for some users and use cases.
|
||||
This feature allows for a option to be passed 'quiet: true' this would significantly reduce the noise.
|
||||
|
||||
There will still be output that lets the user know Wrangler Installed and Wrangler Action completed successfully.
|
||||
Any failure status will still be output to the user as well, to prevent silent failures.
|
||||
|
||||
resolves #142
|
||||
|
||||
## 3.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#147](https://github.com/cloudflare/wrangler-action/pull/147) [`58f274b`](https://github.com/cloudflare/wrangler-action/commit/58f274b9f70867447519c6fa983c813e2b167b85) Thanks [@JacobMGEvans](https://github.com/JacobMGEvans)! - Added more error logging when a command fails to execute
|
||||
Previously, we prevented any error logs from propagating too far to prevent leaking of any potentially sensitive information. However, this made it difficult for developers to debug their code.
|
||||
|
||||
In this release, we have updated our error handling to allow for more error messaging from pre/post and custom commands. We still discourage the use of these commands for secrets or other sensitive information, but we believe this change will make it easier for developers to debug their code.
|
||||
|
||||
Relates to #137
|
||||
|
||||
- [#147](https://github.com/cloudflare/wrangler-action/pull/147) [`58f274b`](https://github.com/cloudflare/wrangler-action/commit/58f274b9f70867447519c6fa983c813e2b167b85) Thanks [@JacobMGEvans](https://github.com/JacobMGEvans)! - Adding Changesets
|
||||
|
||||
- [Version 3.0.0](#version-300)
|
||||
- [Version 2.0.0](#version-200)
|
||||
|
||||
## Version 3.0.0 (Breaking update)
|
||||
|
||||
### Additions
|
||||
|
||||
- **Rewritten Wrangler Action in TypeScript.**
|
||||
- Bulk secrets API utilization from Wrangler.
|
||||
- Added testing for improved reliability.
|
||||
- Implemented multiline support for the `command` input to allow running multiple Wrangler commands.
|
||||
- Now using Node for the Action engine/runner.
|
||||
- Open discussions with the community on all changes through GitHub Discussions and monitored Issues.
|
||||
|
||||
### Removals
|
||||
|
||||
- Removed Docker as a dependency.
|
||||
- Dropped support for Wrangler v1.
|
||||
|
||||
### Changes
|
||||
|
||||
- Fixed CI/CD issues.
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- Wrangler v1 is no longer supported.
|
||||
- Please update to the latest version of Wrangler.
|
||||
- Updated default version of Wrangler to v3.4.0
|
||||
|
||||
### Additional Notes
|
||||
|
||||
- Major Version Default: [DEVX-632](https://jira.cfdata.org/browse/DEVX-632)
|
||||
- Rewrite Project Tickets: [DEVX-804](https://jira.cfdata.org/browse/DEVX-804), [DEVX-802](https://jira.cfdata.org/browse/DEVX-802), [DEVX-800](https://jira.cfdata.org/browse/DEVX-800), [DEVX-632](https://jira.cfdata.org/browse/DEVX-632)
|
||||
|
||||
---
|
||||
|
||||
## Version 2.0.0 (Breaking update)
|
||||
|
||||
### Additions
|
||||
|
||||
- New `command` input
|
||||
- This allows you to specify the Wrangler command you would like to run.
|
||||
For example, if you want to publish the production version of your Worker you may run `publish --env=production`.
|
||||
- This opens up other possibilities too like publishing a Pages project: `pages publish <directory> --project-name=<name>`.
|
||||
- New `accountId` input
|
||||
- This allows you to specify your account ID.
|
||||
|
||||
### Removals
|
||||
|
||||
- Removed `publish` input (refer to [Breaking changes](#breaking-changes)).
|
||||
|
||||
### Changes
|
||||
|
||||
-- no changes --
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- `publish` has been removed.
|
||||
- You should instead do `command:
|
||||
@@ -0,0 +1,3 @@
|
||||
* @cloudflare/wrangler @cloudflare/banda-team
|
||||
|
||||
CHANGELOG.md @cloudflare/wrangler-admins @cloudflare/banda-team
|
||||
@@ -0,0 +1,21 @@
|
||||
# Contributing Guide
|
||||
|
||||
## Releases
|
||||
|
||||
### Changesets
|
||||
|
||||
Every non-trivial change to the project - those that should appear in the changelog - must be captured in a "changeset". We use the changesets tool for creating changesets, publishing versions and updating the changelog.
|
||||
|
||||
Create a changeset for the current change.
|
||||
|
||||
> npx changeset
|
||||
> Select which workspaces are affected by the change and whether the version requires a major, minor or patch release.
|
||||
> Update the generated changeset with a description of the change.
|
||||
> Include the generate changeset in the current commit.
|
||||
> git add ./changeset/\*.md
|
||||
|
||||
### Version Packages PRs
|
||||
|
||||
Once you merge your PR, a new Version Packages PR will be opened in the wrangler-action repo. Once that PR is merged, your change will be released. Example: https://github.com/cloudflare/wrangler-action/pull/305
|
||||
|
||||
Note: Version Packages PRs are only generated if there's been at least one PR merged with a changeset.
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM node:12
|
||||
ENV XDG_CONFIG_HOME /github/workspace
|
||||
ENV WRANGLER_HOME /github/workspace
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -1,180 +1,396 @@
|
||||
# Wrangler GitHub Action
|
||||
|
||||
✨ Zero-config [Cloudflare Workers](https://workers.cloudflare.com) deployment using [Wrangler](https://github.com/cloudflare/wrangler) and [GitHub Actions](https://github.com/actions)
|
||||
Easy-to-use GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/). Makes deploying Workers a breeze.
|
||||
|
||||
## Wrangler v3 Support
|
||||
|
||||
The action now defaults to **Wrangler v4**. If you need to stay on Wrangler v3, you can pin the version explicitly:
|
||||
|
||||
```yaml
|
||||
- uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
wranglerVersion: "3.90.0"
|
||||
```
|
||||
|
||||
## Big Changes in v3
|
||||
|
||||
- Wrangler v1 is no longer supported.
|
||||
- Global API key & Email Auth no longer supported
|
||||
- Action version syntax is newly supported. This means e.g. `uses: cloudflare/wrangler-action@v3`, `uses: cloudflare/wrangler-action@v3.x`, and `uses: cloudflare/wrangler-action@v3.x.x` are all now valid syntax. Previously supported syntax e.g. `uses: cloudflare/wrangler-action@3.x.x` is no longer supported -- the prefix `v` is now necessary.
|
||||
|
||||
[Refer to Changelog for more information](CHANGELOG.md).
|
||||
|
||||
## Usage
|
||||
|
||||
Add `wrangler-action` to the workflow for your Workers application. The below example will publish your application on pushes to the `master` branch:
|
||||
Add `wrangler-action` to the workflow for your Workers/Pages application. The below example will deploy a Worker on a `git push` to the `main` branch:
|
||||
|
||||
```yaml
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- name: Deploy
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
You'll need to configure Wrangler using GitHub's Secrets feature - go to "Settings -> Secrets" and add your Cloudflare API token (for help finding this, see the [Workers documentation](https://developers.cloudflare.com/workers/wrangler/ci-cd/#api-token)). Your API token is encrypted by GitHub, and the action won't print it into logs, so it should be safe!
|
||||
|
||||
With your API token set as a secret for your repository, pass it to the action in the `with` block of your workflow. Below, I've set the secret name to `CLOUDFLARE_API_TOKEN`:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
You'll need to configure Wrangler using GitHub's Secrets feature - go to "Settings -> Secrets" and add your Cloudflare API key and email (for help finding these, see the [Workers documentation](https://developers.cloudflare.com/workers/quickstart/#finding-your-cloudflare-api-keys)). Your API key and email are encrypted by GitHub, and the action won't print them into logs, so they should be safe!
|
||||
|
||||
With your API key and email set as secrets for your repository, pass them to the action in the `with` block of your workflow. Below, I've set the secret names to `apiKey` and `email`:
|
||||
You can pass `wranglerVersion` to install a specific version of Wrangler from NPM. This accepts any version format NPM understands: an exact version like `4.81.0`, a major version like `4`, a range like `^4.0.0` or `4.x`, or `latest`.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
wranglerVersion: "4"
|
||||
```
|
||||
|
||||
Optionally, you can also pass an `environment` key to the action. If you're using Wrangler's [environments](https://github.com/cloudflare/wrangler/blob/master/docs/content/environments.md) feature, you can customize _where_ the action deploys to by passing the matching environment in the `with` block of your workflow:
|
||||
If you omit `wranglerVersion` and Wrangler is already installed in your environment, the action uses the existing installation. If Wrangler is not installed, the action installs a default version.
|
||||
|
||||
Optionally, you can also pass a `workingDirectory` key to the action. This will allow you to specify a subdirectory of the repo to run the Wrangler command from.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
# ... previous configuration ...
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
# ... api key and email ...
|
||||
environment: 'production'
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
workingDirectory: "subfoldername"
|
||||
```
|
||||
|
||||
[Worker secrets](https://developers.cloudflare.com/workers/tooling/wrangler/secrets/) can optionally be passed in via `secrets` as a string of names separated by newlines. Each secret name must match the name of an environment variable specified in the `env` field. This creates or replaces the value for the Worker secret using the `wrangler secret put` command. It's also possible to specify worker environment using environment parameter.
|
||||
|
||||
```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 }}
|
||||
```
|
||||
|
||||
If you need to run additional shell commands before or after your command, you can specify them as input to `preCommands` (before `deploy`) or `postCommands` (after `deploy`). These can include additional `wrangler` commands (that is, `whoami`, `kv:key put`) or any other commands available inside the `wrangler-action` 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 "******"
|
||||
```
|
||||
|
||||
You can use the `command` option to do 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
|
||||
```
|
||||
|
||||
You can also add a command that spans multiple lines:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
## Use cases
|
||||
|
||||
### Deploying when commits are merged to master
|
||||
### Deploy when commits are merged to main
|
||||
|
||||
The above workflow examples have already shown how to run `wrangler-action` when new commits are merged to the master branch. For most developers, this workflow will easily replace manual deploys and be a great first integration step with `wrangler-action`:
|
||||
The above workflow examples have already shown how to run `wrangler-action` when new commits are merged to the main branch. For most developers, this workflow will easily replace manual deploys and be a great first integration step with `wrangler-action`:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- name: Deploy
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
```
|
||||
|
||||
Note that there are a number of possible events, like `push`, that can be used to trigger a workflow. For more details on the events available, check out the [GitHub Actions documentation](https://help.github.com/en/articles/workflow-syntax-for-github-actions#on).
|
||||
Note that there are a number of possible events, like `push`, that can be used to trigger a workflow. For more details on the events available, refer to the [GitHub Actions documentation](https://help.github.com/en/articles/workflow-syntax-for-github-actions#on).
|
||||
|
||||
### Deploy your Pages site (production & preview)
|
||||
|
||||
If you want to deploy your Pages project with GitHub Actions rather than the built-in continous integration (CI), then this is a great way to do it. Wrangler 2 will populate the commit message and branch for you. You only need to pass the project name. If a push to a non-production branch is done, it will deploy as a preview deployment:
|
||||
|
||||
```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 }}
|
||||
```
|
||||
|
||||
### Deploying on a schedule
|
||||
|
||||
If you'd like to deploy your Workers application on a recurring basis – for instance, every hour, or daily – the `schedule` trigger allows you to use cron syntax to define a workflow schedule. The below example will deploy at the beginning of every hour:
|
||||
If you would like to deploy your Workers application on a recurring basis – for example, every hour, or daily – the `schedule` trigger allows you to use cron syntax to define a workflow schedule. The below example will deploy at the beginning of every hour:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 * * * *'
|
||||
- cron: "0 * * * *"
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
```
|
||||
|
||||
If you need help defining the correct cron syntax, check out [crontab.guru](https://crontab.guru/), which provides a friendly user interface for validating your cron schedule.
|
||||
|
||||
### Deploying on a "dispatched" event
|
||||
### Manually triggering a deployment
|
||||
|
||||
If you need to trigger a deployment at-will, you can use GitHub's API to fire a `repository_dispatch` event on your repository. By setting your workflow to trigger on that event, you'll be able to deploy your application via an API call:
|
||||
If you need to trigger a workflow at-will, you can use GitHub's `workflow_dispatch` [event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) in your workflow file. By setting your workflow to trigger on that event, you will be able to deploy your application via the GitHub UI. The UI also accepts inputs that can be used to configure the action:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
repository_dispatch:
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: "Choose an environment to deploy to: <dev|staging|prod>"
|
||||
required: true
|
||||
default: "dev"
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
command: deploy --env ${{ github.event.inputs.environment }}
|
||||
```
|
||||
|
||||
To make the GitHub API request, you can deploy a custom [Cloudflare Workers](https://workers.cloudflare.com) function, which will send a `POST` request to GitHub's API and trigger a new deploy:
|
||||
For more advanced usage or to programmatically trigger the workflow from scripts, refer to [the GitHub documentation](https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event) for making API calls.
|
||||
|
||||
```js
|
||||
const headers = {
|
||||
Accept: 'application/vnd.github.everest-preview+json',
|
||||
Authorization: 'Bearer $token',
|
||||
}
|
||||
### Upload a Worker Version
|
||||
|
||||
const body = JSON.stringify({ event_type: 'repository_dispatch' })
|
||||
To create a new version of your Worker that is not deployed immediately, use the `wrangler versions upload` command. Worker versions created in this way can then be deployed all at once at a later time or gradually deployed using the `wrangler versions deploy` command or via the Cloudflare dashboard under the Deployments tab. Wrangler v3.40.0 or above is required to use this feature.
|
||||
|
||||
const url = `https://api.github.com/repos/$owner/$repo/dispatches`
|
||||
|
||||
const handleRequest = async evt => {
|
||||
await fetch(url, { method: 'POST', headers, body })
|
||||
return new Response('OK')
|
||||
}
|
||||
|
||||
addEventListener('fetch', handleRequest)
|
||||
```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
|
||||
```
|
||||
|
||||
Note that `$token` in this code sample is a GitHub "Personal Access Token". For information on how to generate this token, see the [GitHub documentation on "repository_dispatch"](https://developer.github.com/v3/repos/#create-a-repository-dispatch-event).
|
||||
## Advanced Usage
|
||||
|
||||
## Troubleshooting
|
||||
### Setting A Worker Secret for A Specific Environment
|
||||
|
||||
This action is in beta, and I'm looking for folks to use it! If something goes wrong, please file an issue! That being said, there's a couple things you should know:
|
||||
There is an environment parameter that can be set within the workflow to enable this. Example:
|
||||
|
||||
### "I just started using Workers/Wrangler and I don't know what this is!"
|
||||
```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 }}
|
||||
```
|
||||
|
||||
No problem! Check out the [Quick Start guide](https://developers.cloudflare.com/workers/quickstart) in our docs to get started. Once you have a Workers application, you may want to set it up to automatically deploy from GitHub whenever you change your project. That's where this action comes in - nice!
|
||||
### Using Wrangler Command Output in Subsequent Steps
|
||||
|
||||
### "I'm trying to deploy my static site but it isn't working!"
|
||||
More advanced workflows may need to parse the resulting output of Wrangler commands. To do this, you can use the `command-output` output variable in subsequent steps. For example, if you want to print the output of the Wrangler command, you can do the following:
|
||||
|
||||
To deploy static sites and frontend applications to Workers, check out the documentation for [Workers Sites](https://developers.cloudflare.com/workers/sites).
|
||||
```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
|
||||
|
||||
Note that this action makes no assumptions about _how_ your project is built! **If you need to run a pre-publish step, like building your application, you need to specify a build step in your Workflow.** For instance, if I have an NPM command called `build`, my workflow TOML might resemble the following:
|
||||
- name: print wrangler command output
|
||||
env:
|
||||
CMD_OUTPUT: ${{ steps.deploy.outputs.command-output }}
|
||||
run: echo $CMD_OUTPUT
|
||||
```
|
||||
|
||||
Now when you run your workflow, you will see the full output of the Wrangler command in your workflow logs. You can also use this output in subsequent workflow steps to parse the output for specific values.
|
||||
|
||||
> Note: the `command-stderr` output variable is also available if you need to parse the standard error output of the Wrangler command.
|
||||
|
||||
### Using the `deployment-url` and `pages-deployment-alias-url` Output Variables
|
||||
|
||||
If you are executing a Wrangler command that results in either a Workers or Pages deployment, you can utilize the `deployment-url` output variable to get the URL of the deployment. For example, if you want to print the deployment URL after deploying your application, you can do the following:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
The resulting output will look something like this:
|
||||
|
||||
```text
|
||||
https://<your_pages_site>.pages.dev
|
||||
```
|
||||
|
||||
Pages deployments will also provide their alias URL (since Wrangler v3.78.0). You can use the `pages-deployment-alias-url` output variable to get the URL of the deployment alias. This is useful for, for example, branch aliases for preview deployments.
|
||||
|
||||
If the sample action above was used to deploy a branch other than main, you could use the following to get the branch URL:
|
||||
|
||||
```yaml
|
||||
- name: print pages-deployment-alias-url
|
||||
env:
|
||||
DEPLOYMENT_ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
|
||||
run: echo $DEPLOYMENT_ALIAS_URL
|
||||
```
|
||||
|
||||
Resulting in:
|
||||
|
||||
```text
|
||||
https://new-feature.<your_pages_site>.pages.dev
|
||||
```
|
||||
|
||||
### Using a different package manager
|
||||
|
||||
By default, this action will detect which package manager to use, based on the presence of a `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lockb`/`bun.lock` file.
|
||||
|
||||
If you need to use a specific package manager for your application, you can set the `packageManager` input to `npm`, `yarn`, `pnpm`, or `bun`. You don't need to set this option unless you want to override the default behavior.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
packageManager: pnpm
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "I just started using Workers/Wrangler and I don't know what this is!"
|
||||
|
||||
Refer to the [Quick Start guide](https://developers.cloudflare.com/workers/quickstart) to get started. Once you have a Workers application, you may want to set it up to automatically deploy from GitHub whenever you change your project.
|
||||
|
||||
### "[ERROR] No account id found, quitting.."
|
||||
|
||||
You will need to add `account_id = ""` in your `wrangler.toml` file or set `accountId` in this GitHub Action.
|
||||
|
||||
```yaml
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Build site
|
||||
run: 'npm run build'
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
- uses: actions/checkout@v6
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
```
|
||||
|
||||
+58
-13
@@ -1,17 +1,62 @@
|
||||
name: 'Deploy to Cloudflare Workers with Wrangler'
|
||||
name: "Deploy to Cloudflare Workers with Wrangler"
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
color: 'orange'
|
||||
description: 'Deploy your Cloudflare Workers applications and sites directly from GitHub, using Wrangler'
|
||||
icon: "upload-cloud"
|
||||
color: "orange"
|
||||
description: "Deploy your Cloudflare projects from GitHub using Wrangler"
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
# Possible values: https://github.com/actions/runner/blob/main/src/Runner.Common/Util/NodeUtil.cs#L9
|
||||
using: "node24"
|
||||
main: "dist/index.mjs"
|
||||
inputs:
|
||||
apiKey:
|
||||
description: "Your Cloudflare API Key"
|
||||
required: true
|
||||
email:
|
||||
description: "Your Cloudflare Email"
|
||||
required: true
|
||||
apiToken:
|
||||
description: "Your Cloudflare API Token"
|
||||
required: false
|
||||
accountId:
|
||||
description: "Your Cloudflare Account ID"
|
||||
required: false
|
||||
quiet:
|
||||
description: "Supresses output from Wrangler commands, defaults to `false`"
|
||||
required: false
|
||||
default: "false"
|
||||
environment:
|
||||
description: "The environment you'd like to publish your Workers project to - must be defined in wrangler.toml"
|
||||
description: "The environment you'd like to deploy your Workers project to - must be defined in wrangler.toml"
|
||||
workingDirectory:
|
||||
description: "The relative path which Wrangler commands should be run from"
|
||||
required: false
|
||||
wranglerVersion:
|
||||
description: "The version of Wrangler you'd like to use to deploy your Workers project"
|
||||
required: false
|
||||
secrets:
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker as Secrets and must match the names of environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
preCommands:
|
||||
description: "Commands to execute before deploying the Workers project"
|
||||
required: false
|
||||
postCommands:
|
||||
description: "Commands to execute after deploying the Workers project"
|
||||
required: false
|
||||
command:
|
||||
description: 'The Wrangler command (along with any arguments) you wish to run. Multiple Wrangler commands can be run by separating each command with a newline. Defaults to `"deploy"`.'
|
||||
required: false
|
||||
vars:
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
packageManager:
|
||||
description: "The package manager you'd like to use to install and run wrangler. If not specified, the preferred package manager will be inferred based on the presence of a lockfile or fallback to using npm if no lockfile is found. Valid values are `npm` | `pnpm` | `yarn` | `bun`."
|
||||
required: false
|
||||
gitHubToken:
|
||||
description: "GitHub Token"
|
||||
required: false
|
||||
outputs:
|
||||
command-output:
|
||||
description: "The output of the Wrangler command (comes from stdout)"
|
||||
command-stderr:
|
||||
description: "The error output of the Wrangler command (comes from stderr)"
|
||||
deployment-url:
|
||||
description: "If the command was a Workers or Pages deployment, this will be the URL of the deployment"
|
||||
pages-deployment-alias-url:
|
||||
description: "If the command was a Pages deployment, this will be the URL of the deployment alias (if it exists) - needs wrangler >= 3.78.0"
|
||||
pages-deployment-id:
|
||||
description: "If the command was a Pages deployment, this will be the ID of the deployment - needs wrangler >= 3.81.0"
|
||||
pages-environment:
|
||||
description: "If the command was a Pages deployment, this will be the environment of the deployment - needs wrangler >= 3.81.0"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
export HOME="/github/workspace"
|
||||
export NVM_DIR="/github/workspace/nvm"
|
||||
export WRANGLER_HOME="/github/workspace"
|
||||
|
||||
# h/t https://github.com/elgohr/Publish-Docker-Github-Action
|
||||
sanitize() {
|
||||
if [ -z "${1}" ]
|
||||
then
|
||||
>&2 echo "Unable to find ${2}. Did you add a GitHub secret called key ${2}, and pass in secrets.${2} in your workflow?"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||
|
||||
mkdir -p "$HOME/.wrangler"
|
||||
chmod -R 770 "$HOME/.wrangler"
|
||||
|
||||
sanitize "${INPUT_EMAIL}" "email"
|
||||
sanitize "${INPUT_APIKEY}" "apiKey"
|
||||
|
||||
export CF_EMAIL="$INPUT_EMAIL"
|
||||
export CF_API_KEY="$INPUT_APIKEY"
|
||||
|
||||
npm i @cloudflare/wrangler -g
|
||||
|
||||
if [ -z "$INPUT_ENVIRONMENT" ]
|
||||
then
|
||||
wrangler publish
|
||||
else
|
||||
wrangler publish -e "$INPUT_ENVIRONMENT"
|
||||
fi
|
||||
|
||||
Generated
+3982
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "wrangler-action",
|
||||
"version": "4.0.0",
|
||||
"description": "GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/).",
|
||||
"author": "wrangler@cloudflare.com",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cloudflare/wrangler-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/cloudflare/wrangler-action#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/cloudflare/wrangler-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"script",
|
||||
"cli",
|
||||
"serverless",
|
||||
"cloudflare",
|
||||
"cloudflare-workers",
|
||||
"typescript"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "dist/index.mjs",
|
||||
"scripts": {
|
||||
"build": "npx ncc build ./src/index.ts && mv ./dist/index.js ./dist/index.mjs",
|
||||
"test": "vitest",
|
||||
"format": "prettier --write .",
|
||||
"check": "prettier --check ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.5.0",
|
||||
"@changesets/cli": "^2.27.12",
|
||||
"@cloudflare/workers-types": "^4.20241022.0",
|
||||
"@types/mock-fs": "^4.13.4",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@vercel/ncc": "^0.38.2",
|
||||
"better-result": "^2.9.2",
|
||||
"mock-fs": "^5.4.1",
|
||||
"msw": "^2.6.4",
|
||||
"prettier": "^3.3.3",
|
||||
"semver": "^7.6.3",
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"overrides": {
|
||||
"undici": "^6.23.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { setOutput } from "@actions/core";
|
||||
import { info, WranglerActionConfig } from "./wranglerAction";
|
||||
import {
|
||||
getOutputEntry,
|
||||
OutputEntryDeployment,
|
||||
OutputEntryPagesDeployment,
|
||||
OutputEntryVersionUpload,
|
||||
} from "./wranglerArtifactManager";
|
||||
import { createGitHubDeploymentAndJobSummary } from "./service/github";
|
||||
|
||||
// fallback to trying to extract the deployment-url and pages-deployment-alias-url from stdout for wranglerVersion < 3.81.0
|
||||
function extractDeploymentUrlsFromStdout(stdOut: string): {
|
||||
deploymentUrl?: string;
|
||||
aliasUrl?: string;
|
||||
} {
|
||||
let deploymentUrl = "";
|
||||
let aliasUrl = "";
|
||||
|
||||
// Try to extract the deployment URL
|
||||
const deploymentUrlMatch = stdOut.match(/https?:\/\/[a-zA-Z0-9-./]+/);
|
||||
if (deploymentUrlMatch && deploymentUrlMatch[0]) {
|
||||
deploymentUrl = deploymentUrlMatch[0].trim();
|
||||
}
|
||||
|
||||
// And also try to extract the alias URL (since wrangler@3.78.0)
|
||||
const aliasUrlMatch = stdOut.match(/alias URL: (https?:\/\/[a-zA-Z0-9-./]+)/);
|
||||
if (aliasUrlMatch && aliasUrlMatch[1]) {
|
||||
aliasUrl = aliasUrlMatch[1].trim();
|
||||
}
|
||||
|
||||
return { deploymentUrl, aliasUrl };
|
||||
}
|
||||
|
||||
async function handlePagesDeployOutputEntry(
|
||||
config: WranglerActionConfig,
|
||||
pagesDeployOutputEntry: OutputEntryPagesDeployment,
|
||||
) {
|
||||
setOutput("deployment-url", pagesDeployOutputEntry.url);
|
||||
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
|
||||
setOutput("deployment-alias-url", pagesDeployOutputEntry.alias);
|
||||
setOutput("pages-deployment-alias-url", pagesDeployOutputEntry.alias);
|
||||
setOutput("pages-deployment-id", pagesDeployOutputEntry.deployment_id);
|
||||
setOutput("pages-environment", pagesDeployOutputEntry.environment);
|
||||
|
||||
// Create github deployment, if GITHUB_TOKEN is present in config
|
||||
await createGitHubDeploymentAndJobSummary(config, pagesDeployOutputEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* If no wrangler output file found, fallback to extracting deployment-url from stdout.
|
||||
* @deprecated Use {@link handlePagesDeployOutputEntry} instead.
|
||||
*/
|
||||
function handlePagesDeployCommand(
|
||||
config: WranglerActionConfig,
|
||||
stdOut: string,
|
||||
) {
|
||||
info(
|
||||
config,
|
||||
"Unable to find a WRANGLER_OUTPUT_DIR, environment and id fields will be unavailable for output. Have you updated wrangler to version >=3.81.0?",
|
||||
);
|
||||
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
|
||||
const { deploymentUrl, aliasUrl } = extractDeploymentUrlsFromStdout(stdOut);
|
||||
|
||||
setOutput("deployment-url", deploymentUrl);
|
||||
// DEPRECATED: deployment-alias-url in favour of pages-deployment-alias, drop in next wrangler-action major version change
|
||||
setOutput("deployment-alias-url", aliasUrl);
|
||||
setOutput("pages-deployment-alias-url", aliasUrl);
|
||||
}
|
||||
|
||||
function handleWranglerDeployOutputEntry(
|
||||
config: WranglerActionConfig,
|
||||
wranglerDeployOutputEntry: OutputEntryDeployment,
|
||||
) {
|
||||
// If no deployment urls found in wrangler output file, log that we couldn't find any urls and return.
|
||||
if (
|
||||
!wranglerDeployOutputEntry.targets ||
|
||||
wranglerDeployOutputEntry.targets.length === 0
|
||||
) {
|
||||
info(config, "No deployment-url found in wrangler deploy output file");
|
||||
return;
|
||||
}
|
||||
|
||||
// If more than 1 deployment url found, log that we're going to set deployment-url to the first match.
|
||||
// In a future wrangler-action version we should consider how we're going to output multiple deployment-urls
|
||||
if (wranglerDeployOutputEntry.targets.length > 1) {
|
||||
info(
|
||||
config,
|
||||
"Multiple deployment urls found in wrangler deploy output file, deployment-url will be set to the first url",
|
||||
);
|
||||
}
|
||||
|
||||
setOutput("deployment-url", wranglerDeployOutputEntry.targets[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* If no wrangler output file found, fallback to extracting deployment-url from stdout.
|
||||
* @deprecated Use {@link handleWranglerDeployOutputEntry} instead.
|
||||
*/
|
||||
function handleWranglerDeployCommand(
|
||||
config: WranglerActionConfig,
|
||||
stdOut: string,
|
||||
) {
|
||||
info(
|
||||
config,
|
||||
"Unable to find a WRANGLER_OUTPUT_DIR, deployment-url may have an unreliable output. Have you updated wrangler to version >=3.88.0?",
|
||||
);
|
||||
const { deploymentUrl } = extractDeploymentUrlsFromStdout(stdOut);
|
||||
setOutput("deployment-url", deploymentUrl);
|
||||
}
|
||||
|
||||
function handleVersionsUploadOutputEntry(
|
||||
versionsOutputEntry: OutputEntryVersionUpload,
|
||||
) {
|
||||
setOutput("deployment-url", versionsOutputEntry.preview_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* If no wrangler output file found, log a message stating deployment-url will be unavailable for output.
|
||||
* @deprecated Use {@link handleVersionsOutputEntry} instead.
|
||||
*/
|
||||
function handleVersionsOutputCommand(config: WranglerActionConfig) {
|
||||
info(
|
||||
config,
|
||||
"Unable to find a WRANGLER_OUTPUT_DIR, deployment-url will be unavailable for output. Have you updated wrangler to version >=3.88.0?",
|
||||
);
|
||||
}
|
||||
|
||||
function handleDeprectatedStdoutParsing(
|
||||
config: WranglerActionConfig,
|
||||
command: string,
|
||||
stdOut: string,
|
||||
) {
|
||||
// Check if this command is a pages deployment
|
||||
if (
|
||||
command.startsWith("pages deploy") ||
|
||||
command.startsWith("pages publish")
|
||||
) {
|
||||
handlePagesDeployCommand(config, stdOut);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this command is a workers deployment
|
||||
if (command.startsWith("deploy") || command.startsWith("publish")) {
|
||||
handleWranglerDeployCommand(config, stdOut);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this command is a versions deployment
|
||||
if (command.startsWith("versions upload")) {
|
||||
handleVersionsOutputCommand(config);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleCommandOutputParsing(
|
||||
config: WranglerActionConfig,
|
||||
command: string,
|
||||
stdOut: string,
|
||||
) {
|
||||
// get first OutputEntry found within wrangler artifact output directory
|
||||
const outputEntry = await getOutputEntry(config.WRANGLER_OUTPUT_DIR);
|
||||
|
||||
if (outputEntry === null) {
|
||||
// if no outputEntry found, fallback to deprecated stdOut parsing
|
||||
handleDeprectatedStdoutParsing(config, command, stdOut);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (outputEntry.type) {
|
||||
case "pages-deploy-detailed":
|
||||
await handlePagesDeployOutputEntry(config, outputEntry);
|
||||
break;
|
||||
case "deploy":
|
||||
handleWranglerDeployOutputEntry(config, outputEntry);
|
||||
break;
|
||||
case "version-upload":
|
||||
handleVersionsUploadOutputEntry(outputEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
exec as _childProcessExec,
|
||||
type ExecException,
|
||||
} from "node:child_process";
|
||||
import { EOL } from "node:os";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
export { exec } from "@actions/exec";
|
||||
|
||||
const childProcessExec = promisify(_childProcessExec);
|
||||
|
||||
type ExecAsyncException = ExecException & {
|
||||
stderr: string;
|
||||
stdout: string;
|
||||
};
|
||||
|
||||
function isExecAsyncException(err: unknown): err is ExecAsyncException {
|
||||
return err instanceof Error && "code" in err && "stderr" in err;
|
||||
}
|
||||
|
||||
export async function execShell(
|
||||
command: string,
|
||||
{
|
||||
silent = false,
|
||||
...options
|
||||
}: Parameters<typeof childProcessExec>[1] & { silent?: boolean } = {},
|
||||
) {
|
||||
if (!silent) {
|
||||
process.stdout.write("[command]" + command + EOL);
|
||||
}
|
||||
|
||||
try {
|
||||
const promise = childProcessExec(command, {
|
||||
...options,
|
||||
});
|
||||
|
||||
const { child } = promise;
|
||||
|
||||
if (!silent) {
|
||||
child.stdout?.on("data", (data: Buffer) => process.stdout.write(data));
|
||||
child.stderr?.on("data", (data: Buffer) => process.stderr.write(data));
|
||||
}
|
||||
|
||||
await promise;
|
||||
return child.exitCode;
|
||||
} catch (err) {
|
||||
if (isExecAsyncException(err)) {
|
||||
process.stderr.write(err.stderr);
|
||||
throw new Error(`Process failed with exit code ${err.code}`);
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
import { getBooleanInput, getInput, getMultilineInput } from "@actions/core";
|
||||
import { tmpdir } from "os";
|
||||
import { join } from "path";
|
||||
import { getPackageManager } from "./packageManagers";
|
||||
import { checkWorkingDirectory } from "./utils";
|
||||
import { main, WranglerActionConfig } from "./wranglerAction";
|
||||
|
||||
const DEFAULT_WRANGLER_VERSION = "4";
|
||||
|
||||
/**
|
||||
* A configuration object that contains all the inputs & immutable state for the action.
|
||||
*/
|
||||
const config: WranglerActionConfig = {
|
||||
WRANGLER_VERSION: getInput("wranglerVersion") || DEFAULT_WRANGLER_VERSION,
|
||||
didUserProvideWranglerVersion: Boolean(getInput("wranglerVersion")),
|
||||
secrets: getMultilineInput("secrets"),
|
||||
workingDirectory: checkWorkingDirectory(getInput("workingDirectory")),
|
||||
CLOUDFLARE_API_TOKEN: getInput("apiToken"),
|
||||
CLOUDFLARE_ACCOUNT_ID: getInput("accountId"),
|
||||
ENVIRONMENT: getInput("environment"),
|
||||
VARS: getMultilineInput("vars"),
|
||||
COMMANDS: getMultilineInput("command"),
|
||||
QUIET_MODE: getBooleanInput("quiet"),
|
||||
PACKAGE_MANAGER: getInput("packageManager"),
|
||||
WRANGLER_OUTPUT_DIR: `${join(
|
||||
tmpdir(),
|
||||
`wranglerArtifacts-${crypto.randomUUID()}`,
|
||||
)}`,
|
||||
GITHUB_TOKEN: getInput("gitHubToken", { required: false }),
|
||||
} as const;
|
||||
|
||||
const packageManager = getPackageManager(config.PACKAGE_MANAGER, {
|
||||
workingDirectory: config.workingDirectory,
|
||||
});
|
||||
|
||||
main(config, packageManager);
|
||||
@@ -0,0 +1,110 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { getPackageManager } from "./packageManagers";
|
||||
|
||||
describe("getPackageManager", () => {
|
||||
test("should use provided value instead of inferring from lockfile", () => {
|
||||
expect(
|
||||
getPackageManager("npm", { workingDirectory: "src/test/fixtures/npm" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "npx",
|
||||
"execNoInstall": "npx --no-install",
|
||||
"install": "npm i",
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
getPackageManager("yarn", { workingDirectory: "src/test/fixtures/npm" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "yarn",
|
||||
"execNoInstall": "yarn",
|
||||
"install": "yarn add",
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
getPackageManager("pnpm", { workingDirectory: "src/test/fixtures/npm" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "pnpm exec",
|
||||
"execNoInstall": "pnpm exec",
|
||||
"install": "pnpm add",
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
getPackageManager("bun", { workingDirectory: "src/test/fixtures/bun" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "bunx",
|
||||
"execNoInstall": "bun run",
|
||||
"install": "bun i",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should use npm if no value provided and package-lock.json exists", () => {
|
||||
expect(getPackageManager("", { workingDirectory: "src/test/fixtures/npm" }))
|
||||
.toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "npx",
|
||||
"execNoInstall": "npx --no-install",
|
||||
"install": "npm i",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should use yarn if no value provided and yarn.lock exists", () => {
|
||||
expect(
|
||||
getPackageManager("", { workingDirectory: "src/test/fixtures/yarn" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "yarn",
|
||||
"execNoInstall": "yarn",
|
||||
"install": "yarn add",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should use pnpm if no value provided and pnpm-lock.yaml exists", () => {
|
||||
expect(
|
||||
getPackageManager("", { workingDirectory: "src/test/fixtures/pnpm" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "pnpm exec",
|
||||
"execNoInstall": "pnpm exec",
|
||||
"install": "pnpm add",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should use bun if no value provided and bun.lockb exists", () => {
|
||||
expect(getPackageManager("", { workingDirectory: "src/test/fixtures/bun" }))
|
||||
.toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "bunx",
|
||||
"execNoInstall": "bun run",
|
||||
"install": "bun i",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should use npm if no value provided and no lockfile is present", () => {
|
||||
expect(
|
||||
getPackageManager("", { workingDirectory: "src/test/fixtures/empty" }),
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"exec": "npx",
|
||||
"execNoInstall": "npx --no-install",
|
||||
"install": "npm i",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test("should throw if an invalid value is provided", () => {
|
||||
expect(() =>
|
||||
getPackageManager("cargo", { workingDirectory: "src/test/fixtures/npm" }),
|
||||
).toThrowError();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import * as path from "node:path";
|
||||
|
||||
export interface PackageManager {
|
||||
install: string;
|
||||
exec: string;
|
||||
execNoInstall: string;
|
||||
}
|
||||
|
||||
const PACKAGE_MANAGERS = {
|
||||
npm: {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
execNoInstall: "npx --no-install",
|
||||
},
|
||||
yarn: {
|
||||
install: "yarn add",
|
||||
exec: "yarn",
|
||||
execNoInstall: "yarn",
|
||||
},
|
||||
pnpm: {
|
||||
install: "pnpm add",
|
||||
exec: "pnpm exec",
|
||||
execNoInstall: "pnpm exec",
|
||||
},
|
||||
bun: {
|
||||
install: "bun i",
|
||||
exec: "bunx",
|
||||
execNoInstall: "bun run",
|
||||
},
|
||||
} as const satisfies Readonly<Record<string, PackageManager>>;
|
||||
|
||||
type PackageManagerValue = keyof typeof PACKAGE_MANAGERS;
|
||||
|
||||
function detectPackageManager(
|
||||
workingDirectory = ".",
|
||||
): PackageManagerValue | null {
|
||||
if (existsSync(path.join(workingDirectory, "package-lock.json"))) {
|
||||
return "npm";
|
||||
}
|
||||
if (existsSync(path.join(workingDirectory, "yarn.lock"))) {
|
||||
return "yarn";
|
||||
}
|
||||
if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
|
||||
return "pnpm";
|
||||
}
|
||||
if (
|
||||
existsSync(path.join(workingDirectory, "bun.lockb")) ||
|
||||
existsSync(path.join(workingDirectory, "bun.lock"))
|
||||
) {
|
||||
return "bun";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function assertValidPackageManagerValue(
|
||||
name: string,
|
||||
): asserts name is PackageManagerValue | "" {
|
||||
if (name && !Object.keys(PACKAGE_MANAGERS).includes(name)) {
|
||||
throw new TypeError(
|
||||
`invalid value provided for "packageManager": ${name}
|
||||
Value must be one of: [${Object.keys(PACKAGE_MANAGERS).join(", ")}]`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function getPackageManager(
|
||||
name: string,
|
||||
{ workingDirectory = "." }: { workingDirectory?: string } = {},
|
||||
) {
|
||||
assertValidPackageManagerValue(name);
|
||||
|
||||
return PACKAGE_MANAGERS[
|
||||
name || detectPackageManager(workingDirectory) || "npm"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { setupServer } from "msw/node";
|
||||
import { createGitHubDeployment, createJobSummary } from "./github";
|
||||
import { getOctokit } from "@actions/github";
|
||||
import { mockGithubDeployments } from "../test/mocks";
|
||||
import { getTestConfig } from "../test/test-utils";
|
||||
import mockfs from "mock-fs";
|
||||
import { readFile } from "fs/promises";
|
||||
|
||||
afterEach(() => {
|
||||
mockfs.restore();
|
||||
});
|
||||
|
||||
describe("github", () => {
|
||||
it("Calls createGitHubDeployment successfully", async () => {
|
||||
const githubUser = "mock-user";
|
||||
const githubRepoName = "wrangler-action";
|
||||
const server = setupServer(
|
||||
...mockGithubDeployments({ githubUser, githubRepoName }).handlers,
|
||||
);
|
||||
server.listen({ onUnhandledRequest: "error" });
|
||||
vi.stubEnv("GITHUB_REPOSITORY", `${githubUser}/${githubRepoName}`);
|
||||
|
||||
const testConfig = getTestConfig();
|
||||
const octokit = getOctokit(testConfig.GITHUB_TOKEN, { request: fetch });
|
||||
await createGitHubDeployment({
|
||||
config: testConfig,
|
||||
octokit,
|
||||
productionBranch: "production-branch",
|
||||
deploymentId: "fake-deployment-id",
|
||||
projectName: "fake-project-name",
|
||||
deploymentUrl: "https://fake-deployment-url.com",
|
||||
environment: "production",
|
||||
});
|
||||
server.close();
|
||||
});
|
||||
it("Calls createJobSummary successfully", async () => {
|
||||
vi.stubEnv("GITHUB_STEP_SUMMARY", "summary");
|
||||
mockfs({
|
||||
summary: mockfs.file(),
|
||||
});
|
||||
await createJobSummary({
|
||||
commitHash: "fake-commit-hash",
|
||||
deploymentUrl: "https://fake-deployment-url.com",
|
||||
aliasUrl: "https://fake-alias-url.com",
|
||||
});
|
||||
expect((await readFile("summary")).toString()).toMatchInlineSnapshot(`
|
||||
"
|
||||
# Deploying with Cloudflare Pages
|
||||
|
||||
| Name | Result |
|
||||
| ----------------------- | - |
|
||||
| **Last commit:** | fake-commit-hash |
|
||||
| **Preview URL**: | https://fake-deployment-url.com |
|
||||
| **Branch Preview URL**: | https://fake-alias-url.com |
|
||||
"
|
||||
`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
import { summary } from "@actions/core";
|
||||
import { context, getOctokit } from "@actions/github";
|
||||
import { env } from "process";
|
||||
import { info, warn } from "../utils";
|
||||
import { OutputEntryPagesDeployment } from "../wranglerArtifactManager";
|
||||
import { WranglerActionConfig } from "../wranglerAction";
|
||||
|
||||
type Octokit = ReturnType<typeof getOctokit>;
|
||||
|
||||
export async function createGitHubDeployment({
|
||||
config,
|
||||
octokit,
|
||||
productionBranch,
|
||||
environment,
|
||||
deploymentId,
|
||||
projectName,
|
||||
deploymentUrl,
|
||||
}: {
|
||||
config: WranglerActionConfig;
|
||||
octokit: Octokit;
|
||||
productionBranch: string;
|
||||
environment: string;
|
||||
deploymentId: string | null;
|
||||
projectName: string;
|
||||
deploymentUrl?: string;
|
||||
}) {
|
||||
const githubBranch = env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME;
|
||||
const productionEnvironment = githubBranch === productionBranch;
|
||||
|
||||
const deployment = await octokit.rest.repos.createDeployment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: githubBranch || context.ref,
|
||||
auto_merge: false,
|
||||
description: "Cloudflare Pages",
|
||||
required_contexts: [],
|
||||
environment,
|
||||
production_environment: productionEnvironment,
|
||||
});
|
||||
|
||||
if (deployment.status !== 201) {
|
||||
info(config, "Error creating GitHub deployment");
|
||||
return;
|
||||
}
|
||||
await octokit.rest.repos.createDeploymentStatus({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
deployment_id: deployment.data.id,
|
||||
environment,
|
||||
environment_url: deploymentUrl,
|
||||
production_environment: productionEnvironment,
|
||||
// don't have project_name or deployment_id I think
|
||||
log_url: `https://dash.cloudflare.com/${config.CLOUDFLARE_ACCOUNT_ID}/pages/view/${projectName}/${deploymentId}`,
|
||||
description: "Cloudflare Pages",
|
||||
state: "success",
|
||||
auto_inactive: false,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createJobSummary({
|
||||
commitHash,
|
||||
deploymentUrl,
|
||||
aliasUrl,
|
||||
}: {
|
||||
commitHash: string;
|
||||
deploymentUrl?: string;
|
||||
aliasUrl?: string;
|
||||
}) {
|
||||
await summary
|
||||
.addRaw(
|
||||
`
|
||||
# Deploying with Cloudflare Pages
|
||||
|
||||
| Name | Result |
|
||||
| ----------------------- | - |
|
||||
| **Last commit:** | ${commitHash} |
|
||||
| **Preview URL**: | ${deploymentUrl} |
|
||||
| **Branch Preview URL**: | ${aliasUrl} |
|
||||
`,
|
||||
)
|
||||
.write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create github deployment, if GITHUB_TOKEN is present in config
|
||||
*/
|
||||
export async function createGitHubDeploymentAndJobSummary(
|
||||
config: WranglerActionConfig,
|
||||
pagesArtifactFields: OutputEntryPagesDeployment,
|
||||
) {
|
||||
if (
|
||||
config.GITHUB_TOKEN &&
|
||||
pagesArtifactFields.production_branch &&
|
||||
pagesArtifactFields.pages_project &&
|
||||
pagesArtifactFields.deployment_trigger
|
||||
) {
|
||||
const octokit = getOctokit(config.GITHUB_TOKEN);
|
||||
const [createGitHubDeploymentRes, createJobSummaryRes] =
|
||||
await Promise.allSettled([
|
||||
createGitHubDeployment({
|
||||
config,
|
||||
octokit,
|
||||
deploymentUrl: pagesArtifactFields.url,
|
||||
productionBranch: pagesArtifactFields.production_branch,
|
||||
environment: pagesArtifactFields.environment,
|
||||
deploymentId: pagesArtifactFields.deployment_id,
|
||||
projectName: pagesArtifactFields.pages_project,
|
||||
}),
|
||||
createJobSummary({
|
||||
commitHash:
|
||||
pagesArtifactFields.deployment_trigger.metadata.commit_hash.substring(
|
||||
0,
|
||||
8,
|
||||
),
|
||||
deploymentUrl: pagesArtifactFields.url,
|
||||
aliasUrl: pagesArtifactFields.alias,
|
||||
}),
|
||||
]);
|
||||
|
||||
if (createGitHubDeploymentRes.status === "rejected") {
|
||||
warn(config, "Creating Github Deployment failed");
|
||||
}
|
||||
|
||||
if (createJobSummaryRes.status === "rejected") {
|
||||
warn(config, "Creating Github Job summary failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-build-quiet"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-bun-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret") {
|
||||
const { SECRET1 = "", SECRET2 = "" } = env;
|
||||
return new Response(`${SECRET1} ${SECRET2}`);
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-environment-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-environment-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-environment-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
name = "wrangler-action-environment-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
|
||||
[env.dev]
|
||||
name = "wrangler-action-dev-environment-test"
|
||||
[env.dev.vars]
|
||||
DEV_VAR = "example_production_token"
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-npm-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-npm-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "wrangler-action-npm-test"
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-only-build"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-pnpm-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const args = Array.from(process.argv);
|
||||
const command = args.pop();
|
||||
switch (command) {
|
||||
case "--version":
|
||||
console.log(`
|
||||
⛅️ wrangler 1.1.1 (update available 1.2.3)
|
||||
------------------------------------------`);
|
||||
process.exit(0);
|
||||
case "action-test":
|
||||
console.log("Test successful.");
|
||||
process.exit(0);
|
||||
default:
|
||||
console.error("Invalid command");
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "wrangler",
|
||||
"version": "1.1.1",
|
||||
"main": "index.js",
|
||||
"bin": "index.js"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "wrangler-action-pre-installed-wrangler-test",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-pre-installed-wrangler-test",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"wrangler": "file:mock_packages/wrangler"
|
||||
}
|
||||
},
|
||||
"mock_packages/wrangler": {
|
||||
"version": "1.1.1",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"wrangler": "index.js"
|
||||
}
|
||||
},
|
||||
"node_modules/wrangler": {
|
||||
"resolved": "mock_packages/wrangler",
|
||||
"link": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"wrangler": {
|
||||
"version": "file:mock_packages/wrangler"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "wrangler-action-pre-installed-wrangler-test",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"wrangler": "file:mock_packages/wrangler"
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-secrets-default"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-secrets-v2"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-detect-package-manager-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-specify-package-manager"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-detect-package-manager-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test-unspecified-package-manager"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
type Env = {
|
||||
SECRET1?: string;
|
||||
SECRET2?: string;
|
||||
};
|
||||
|
||||
export default {
|
||||
fetch(request: Request, env: Env) {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === "/secret-health-check") {
|
||||
const { SECRET1, SECRET2 } = env;
|
||||
|
||||
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
|
||||
throw new Error("SECRET1 or SECRET2 is not defined");
|
||||
}
|
||||
|
||||
return new Response("OK");
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "wrangler-action-yarn-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { z } from "zod";
|
||||
|
||||
export function mockGithubDeployments({
|
||||
githubUser,
|
||||
githubRepoName,
|
||||
}: {
|
||||
githubUser: string;
|
||||
githubRepoName: string;
|
||||
}) {
|
||||
return {
|
||||
handlers: [
|
||||
http.post(
|
||||
`https://api.github.com/repos/${githubUser}/${githubRepoName}/deployments`,
|
||||
async ({ request }) => {
|
||||
if (request.headers.get("Authorization") === null) {
|
||||
return HttpResponse.text("error: no auth token", { status: 400 });
|
||||
}
|
||||
const GithubDeploymentsRequest = z.object({
|
||||
auto_merge: z.literal(false),
|
||||
description: z.literal("Cloudflare Pages"),
|
||||
required_contexts: z.array(z.string()).length(0),
|
||||
environment: z.literal("production"),
|
||||
production_environment: z.literal(false),
|
||||
});
|
||||
// validate request body
|
||||
GithubDeploymentsRequest.parse(await request.json());
|
||||
|
||||
return HttpResponse.json(null);
|
||||
},
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { WranglerActionConfig } from "../wranglerAction";
|
||||
|
||||
export function getTestConfig({
|
||||
config = {},
|
||||
}: {
|
||||
config?: Partial<WranglerActionConfig>;
|
||||
} = {}): WranglerActionConfig {
|
||||
return Object.assign(
|
||||
{
|
||||
WRANGLER_VERSION: "4.72.0",
|
||||
didUserProvideWranglerVersion: false,
|
||||
secrets: [],
|
||||
workingDirectory: "/src/test/fixtures",
|
||||
CLOUDFLARE_API_TOKEN: "foo",
|
||||
CLOUDFLARE_ACCOUNT_ID: "bar",
|
||||
ENVIRONMENT: "dev",
|
||||
VARS: [],
|
||||
COMMANDS: [],
|
||||
QUIET_MODE: false,
|
||||
PACKAGE_MANAGER: "npm",
|
||||
WRANGLER_OUTPUT_DIR: "/tmp/wranglerArtifacts",
|
||||
GITHUB_TOKEN: "xxxxyy23213123132131",
|
||||
} as const satisfies WranglerActionConfig,
|
||||
config,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { checkWorkingDirectory, semverCompare } from "./utils";
|
||||
|
||||
describe("semverCompare", () => {
|
||||
test("should return false if the second argument is equal to the first argument", () => {
|
||||
const isVersion1LessThanVersion2 = semverCompare("1.2.3", "1.2.3");
|
||||
|
||||
expect(isVersion1LessThanVersion2).toBe(false);
|
||||
});
|
||||
|
||||
test("should return true if the first argument is less than the second argument", () => {
|
||||
const isVersion1LessThanVersion2 = semverCompare("1.2.2", "1.2.3");
|
||||
|
||||
expect(isVersion1LessThanVersion2).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkWorkingDirectory", () => {
|
||||
test("should return the normalized path if the directory exists", () => {
|
||||
const normalizedPath = checkWorkingDirectory(".");
|
||||
expect(normalizedPath).toBe(path.normalize("."));
|
||||
});
|
||||
|
||||
test("should fail if the directory does not exist", () => {
|
||||
expect(() =>
|
||||
checkWorkingDirectory("/does/not/exist"),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`[Error: Directory /does/not/exist does not exist.]`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("semverCompare", () => {
|
||||
test.each([
|
||||
["1.2.3", "1.2.3", false],
|
||||
["1.2.2", "1.2.3", true],
|
||||
["2.0.0", "3.0.0", true],
|
||||
["3.1.0", "3.1.1", true],
|
||||
["3.1.0", "3.5.0", true],
|
||||
["3.1.0", "3.10.0", true],
|
||||
["3.1.0", "3.15.0", true],
|
||||
["3.10.0", "3.1.0", false],
|
||||
["3.20.0", "3.2.0", false],
|
||||
["3.1.0", "4.0.0", true],
|
||||
["2.20.0", "4.72.0", true],
|
||||
["3.4.0", "4.72.0", true],
|
||||
["3.60.0", "4.72.0", true],
|
||||
["3.1.0", "latest", true],
|
||||
["4.0.0", "latest", true],
|
||||
])(
|
||||
"should semver compare %s vs %s correctly, expecting %s",
|
||||
(version1, version2, expected) => {
|
||||
const isVersion1LessThanVersion2 = semverCompare(version1, version2);
|
||||
|
||||
expect(isVersion1LessThanVersion2).toBe(expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import semverGt from "semver/functions/gt";
|
||||
import {
|
||||
info as originalInfo,
|
||||
error as originalError,
|
||||
warning as originalWarn,
|
||||
} from "@actions/core";
|
||||
import { WranglerActionConfig } from "./wranglerAction";
|
||||
|
||||
/**
|
||||
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
|
||||
*/
|
||||
export function semverCompare(version1: string, version2: string) {
|
||||
if (version2 === "latest") return true;
|
||||
|
||||
return semverGt(version2, version1);
|
||||
}
|
||||
|
||||
export function checkWorkingDirectory(workingDirectory = ".") {
|
||||
const normalizedPath = path.normalize(workingDirectory);
|
||||
if (existsSync(normalizedPath)) {
|
||||
return normalizedPath;
|
||||
} else {
|
||||
throw new Error(`Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function info(
|
||||
config: WranglerActionConfig,
|
||||
message: string,
|
||||
bypass?: boolean,
|
||||
): void {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
originalInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function warn(
|
||||
config: WranglerActionConfig,
|
||||
message: string,
|
||||
bypass?: boolean,
|
||||
): void {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
originalWarn(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function error(
|
||||
config: WranglerActionConfig,
|
||||
message: string,
|
||||
bypass?: boolean,
|
||||
): void {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
originalError(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,512 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
installWrangler,
|
||||
isExactSemver,
|
||||
main,
|
||||
parseWranglerVersion,
|
||||
uploadSecrets,
|
||||
} from "./wranglerAction";
|
||||
import { getTestConfig } from "./test/test-utils";
|
||||
|
||||
describe("parseWranglerVersion", () => {
|
||||
it("parses version from verbose wrangler output", () => {
|
||||
expect(
|
||||
parseWranglerVersion(` ⛅️ wrangler 3.48.0 (update available 3.53.1)`),
|
||||
).toBe("3.48.0");
|
||||
});
|
||||
|
||||
it("parses version from bare version output", () => {
|
||||
expect(parseWranglerVersion("4.18.1\n")).toBe("4.18.1");
|
||||
});
|
||||
|
||||
it("returns empty string for unparseable output", () => {
|
||||
expect(parseWranglerVersion("something unexpected")).toBe("");
|
||||
});
|
||||
|
||||
it("parses prerelease version", () => {
|
||||
expect(parseWranglerVersion(` ⛅️ wrangler 4.0.0-beta.1`)).toBe(
|
||||
"4.0.0-beta.1",
|
||||
);
|
||||
});
|
||||
|
||||
it("parses bare prerelease version", () => {
|
||||
expect(parseWranglerVersion("4.0.0-rc.0\n")).toBe("4.0.0-rc.0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isExactSemver", () => {
|
||||
it.each([
|
||||
["4.81.0", true],
|
||||
["3.48.0", true],
|
||||
["2.20.0", true],
|
||||
["4.0.0-beta.1", true],
|
||||
["4", false],
|
||||
["4.x", false],
|
||||
["4.*", false],
|
||||
["^4.0.0", false],
|
||||
["~4.0.0", false],
|
||||
["latest", false],
|
||||
["", false],
|
||||
])("isExactSemver(%s) === %s", (input, expected) => {
|
||||
expect(isExactSemver(input)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("installWrangler", () => {
|
||||
const testPackageManager = {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
execNoInstall: "npx --no-install",
|
||||
};
|
||||
|
||||
it("Errors on unsupported wrangler version", async () => {
|
||||
const testConfig = getTestConfig({ config: { WRANGLER_VERSION: "1" } });
|
||||
await expect(
|
||||
installWrangler(testConfig, testPackageManager),
|
||||
).rejects.toThrowError(
|
||||
`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`,
|
||||
);
|
||||
});
|
||||
|
||||
it("Does nothing if no wrangler version is specified and wrangler is already installed", async () => {
|
||||
const testConfig = getTestConfig();
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.48.0 (update available 3.53.1)`,
|
||||
};
|
||||
});
|
||||
const infoSpy = vi.spyOn(core, "info");
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(infoSpy).toBeCalledWith(
|
||||
"✅ No wrangler version specified, using pre-installed wrangler version 3.48.0",
|
||||
);
|
||||
expect(resolvedVersion).toBe("3.48.0");
|
||||
});
|
||||
|
||||
it("Does nothing if the wrangler version specified is the same as the one installed", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.48.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.48.0 (update available 3.53.1)`,
|
||||
};
|
||||
});
|
||||
const infoSpy = vi.spyOn(core, "info");
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(infoSpy).toBeCalledWith("✅ Using Wrangler 3.48.0");
|
||||
expect(resolvedVersion).toBe("3.48.0");
|
||||
});
|
||||
|
||||
it("Should install wrangler if the version specified is not already available", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.48.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
// Pre-install check: different version installed
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.20.0 (update available 3.53.1)`,
|
||||
};
|
||||
}
|
||||
// Post-install check: correct version now installed
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.48.0`,
|
||||
};
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async () => {
|
||||
return 0;
|
||||
});
|
||||
const infoSpy = vi.spyOn(core, "info");
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(infoSpy).toBeCalledWith("✅ Wrangler installed");
|
||||
expect(resolvedVersion).toBe("3.48.0");
|
||||
});
|
||||
|
||||
it("Should install and resolve version when a range like '4' is specified", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
// Pre-install check: older version installed
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.90.0`,
|
||||
};
|
||||
}
|
||||
// Post-install check: v4 now installed
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: `4.18.1`,
|
||||
};
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
if (cmd === "npm i") expect(args).toStrictEqual(["wrangler@4"]);
|
||||
return 0;
|
||||
});
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(resolvedVersion).toBe("4.18.1");
|
||||
});
|
||||
|
||||
it("Should install and resolve version when 'latest' is specified", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "latest",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
// Pre-install: no wrangler found
|
||||
throw new Error("command not found");
|
||||
}
|
||||
// Post-install check
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: `4.20.0`,
|
||||
};
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
if (cmd === "npm i") {
|
||||
expect(args).toStrictEqual(["wrangler@latest"]);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(resolvedVersion).toBe("4.20.0");
|
||||
});
|
||||
|
||||
it("Throws if version cannot be resolved after install", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
throw new Error("not found");
|
||||
}
|
||||
// Post-install: unparseable output
|
||||
return { exitCode: 0, stderr: "", stdout: "garbage output" };
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockResolvedValue(0);
|
||||
await expect(
|
||||
installWrangler(testConfig, testPackageManager),
|
||||
).rejects.toThrowError(
|
||||
"Failed to determine installed Wrangler version after installing wrangler@4",
|
||||
);
|
||||
});
|
||||
|
||||
it("Falls back to raw version when post-install resolution fails for exact semver", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.48.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
throw new Error("not found");
|
||||
}
|
||||
throw new Error("wrangler --version failed");
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockResolvedValue(0);
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(resolvedVersion).toBe("3.48.0");
|
||||
});
|
||||
|
||||
it("Skips reinstall when range is satisfied by pre-installed version", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: `4.18.1`,
|
||||
};
|
||||
});
|
||||
const execSpy = vi.spyOn(exec, "exec");
|
||||
const infoSpy = vi.spyOn(core, "info");
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(infoSpy).toBeCalledWith("✅ Using Wrangler 4.18.1");
|
||||
expect(resolvedVersion).toBe("4.18.1");
|
||||
expect(execSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Reinstalls when range is NOT satisfied by pre-installed version", async () => {
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4",
|
||||
didUserProvideWranglerVersion: true,
|
||||
},
|
||||
});
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
// Pre-installed is v3, doesn't satisfy "4"
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: ` ⛅️ wrangler 3.90.0`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
exitCode: 0,
|
||||
stderr: "",
|
||||
stdout: `4.18.1`,
|
||||
};
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockResolvedValue(0);
|
||||
const resolvedVersion = await installWrangler(
|
||||
testConfig,
|
||||
testPackageManager,
|
||||
);
|
||||
expect(resolvedVersion).toBe("4.18.1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("uploadSecrets", () => {
|
||||
const testPackageManager = {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
execNoInstall: "npx --no-install",
|
||||
};
|
||||
|
||||
it("WRANGLER_VERSION < 3.4.0 uses wrangler secret put", async () => {
|
||||
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.3.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["FAKE_SECRET"],
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
expect(cmd).toBe("npx");
|
||||
expect(args).toStrictEqual([
|
||||
"wrangler",
|
||||
"secret",
|
||||
"put",
|
||||
"FAKE_SECRET",
|
||||
"--env",
|
||||
"dev",
|
||||
]);
|
||||
return 0;
|
||||
});
|
||||
const startGroup = vi.spyOn(core, "startGroup");
|
||||
const endGroup = vi.spyOn(core, "endGroup");
|
||||
|
||||
await uploadSecrets(testConfig, testPackageManager);
|
||||
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
|
||||
expect(endGroup).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("WRANGLER_VERSION < 3.60.0 uses wrangler secret:bulk", async () => {
|
||||
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.59.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["FAKE_SECRET"],
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
expect(cmd).toBe("npx");
|
||||
expect(args).toStrictEqual(["wrangler", "secret:bulk", "--env", "dev"]);
|
||||
return 0;
|
||||
});
|
||||
const startGroup = vi.spyOn(core, "startGroup");
|
||||
const endGroup = vi.spyOn(core, "endGroup");
|
||||
|
||||
await uploadSecrets(testConfig, testPackageManager);
|
||||
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
|
||||
expect(endGroup).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("WRANGLER_VERSION 3.61.0 uses wrangler secret bulk", async () => {
|
||||
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "3.61.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["FAKE_SECRET"],
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
expect(cmd).toBe("npx");
|
||||
expect(args).toStrictEqual([
|
||||
"wrangler",
|
||||
"secret",
|
||||
"bulk",
|
||||
"--env",
|
||||
"dev",
|
||||
]);
|
||||
return 0;
|
||||
});
|
||||
const startGroup = vi.spyOn(core, "startGroup");
|
||||
const endGroup = vi.spyOn(core, "endGroup");
|
||||
|
||||
await uploadSecrets(testConfig, testPackageManager);
|
||||
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
|
||||
expect(endGroup).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("WRANGLER_VERSION 4.x uses wrangler secret bulk", async () => {
|
||||
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4.72.0",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["FAKE_SECRET"],
|
||||
},
|
||||
});
|
||||
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
|
||||
expect(cmd).toBe("npx");
|
||||
expect(args).toStrictEqual([
|
||||
"wrangler",
|
||||
"secret",
|
||||
"bulk",
|
||||
"--env",
|
||||
"dev",
|
||||
]);
|
||||
return 0;
|
||||
});
|
||||
const startGroup = vi.spyOn(core, "startGroup");
|
||||
const endGroup = vi.spyOn(core, "endGroup");
|
||||
|
||||
await uploadSecrets(testConfig, testPackageManager);
|
||||
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
|
||||
expect(endGroup).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
describe("main", () => {
|
||||
const testPackageManager = {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
execNoInstall: "npx --no-install",
|
||||
};
|
||||
|
||||
it("Completes with wranglerVersion '4' and secrets without Invalid Version error", async () => {
|
||||
vi.stubEnv("MY_SECRET", "secret_value");
|
||||
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "4",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["MY_SECRET"],
|
||||
COMMANDS: ["deploy"],
|
||||
},
|
||||
});
|
||||
|
||||
vi.spyOn(core, "getMultilineInput").mockReturnValue([]);
|
||||
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
throw new Error("command not found");
|
||||
}
|
||||
return { exitCode: 0, stderr: "", stdout: "4.18.1" };
|
||||
});
|
||||
|
||||
vi.spyOn(exec, "exec").mockResolvedValue(0);
|
||||
const setFailedSpy = vi.spyOn(core, "setFailed");
|
||||
|
||||
await main(testConfig, testPackageManager);
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Completes with wranglerVersion 'latest' and secrets without Invalid Version error", async () => {
|
||||
vi.stubEnv("MY_SECRET", "secret_value");
|
||||
|
||||
const testConfig = getTestConfig({
|
||||
config: {
|
||||
WRANGLER_VERSION: "latest",
|
||||
didUserProvideWranglerVersion: true,
|
||||
secrets: ["MY_SECRET"],
|
||||
COMMANDS: ["deploy"],
|
||||
},
|
||||
});
|
||||
|
||||
vi.spyOn(core, "getMultilineInput").mockReturnValue([]);
|
||||
|
||||
let callCount = 0;
|
||||
vi.spyOn(exec, "getExecOutput").mockImplementation(async () => {
|
||||
callCount++;
|
||||
if (callCount === 1) {
|
||||
throw new Error("command not found");
|
||||
}
|
||||
return { exitCode: 0, stderr: "", stdout: "4.20.0" };
|
||||
});
|
||||
|
||||
vi.spyOn(exec, "exec").mockResolvedValue(0);
|
||||
|
||||
const setFailedSpy = vi.spyOn(core, "setFailed");
|
||||
|
||||
await main(testConfig, testPackageManager);
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,420 @@
|
||||
import {
|
||||
debug,
|
||||
getMultilineInput,
|
||||
endGroup as originalEndGroup,
|
||||
startGroup as originalStartGroup,
|
||||
setFailed,
|
||||
setOutput,
|
||||
} from "@actions/core";
|
||||
import { getExecOutput } from "@actions/exec";
|
||||
import semverSatisfies from "semver/functions/satisfies";
|
||||
import semverValid from "semver/functions/valid";
|
||||
import { z } from "zod";
|
||||
import { exec, execShell } from "./exec";
|
||||
import { PackageManager } from "./packageManagers";
|
||||
import { error, info, semverCompare } from "./utils";
|
||||
import { handleCommandOutputParsing } from "./commandOutputParsing";
|
||||
import semverLt from "semver/functions/lt";
|
||||
|
||||
export type WranglerActionConfig = z.infer<typeof wranglerActionConfig>;
|
||||
export const wranglerActionConfig = z.object({
|
||||
WRANGLER_VERSION: z.string(),
|
||||
didUserProvideWranglerVersion: z.boolean(),
|
||||
secrets: z.array(z.string()),
|
||||
workingDirectory: z.string(),
|
||||
CLOUDFLARE_API_TOKEN: z.string(),
|
||||
CLOUDFLARE_ACCOUNT_ID: z.string(),
|
||||
ENVIRONMENT: z.string(),
|
||||
VARS: z.array(z.string()),
|
||||
COMMANDS: z.array(z.string()),
|
||||
QUIET_MODE: z.boolean(),
|
||||
PACKAGE_MANAGER: z.string(),
|
||||
WRANGLER_OUTPUT_DIR: z.string(),
|
||||
GITHUB_TOKEN: z.string(),
|
||||
});
|
||||
|
||||
function startGroup(config: WranglerActionConfig, name: string): void {
|
||||
if (!config.QUIET_MODE) {
|
||||
originalStartGroup(name);
|
||||
}
|
||||
}
|
||||
|
||||
function endGroup(config: WranglerActionConfig): void {
|
||||
if (!config.QUIET_MODE) {
|
||||
originalEndGroup();
|
||||
}
|
||||
}
|
||||
|
||||
async function main(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
) {
|
||||
try {
|
||||
wranglerActionConfig.parse(config);
|
||||
authenticationSetup(config);
|
||||
const resolvedVersion = await installWrangler(config, packageManager);
|
||||
const resolvedConfig = { ...config, WRANGLER_VERSION: resolvedVersion };
|
||||
|
||||
await execCommands(
|
||||
resolvedConfig,
|
||||
packageManager,
|
||||
getMultilineInput("preCommands"),
|
||||
"pre",
|
||||
);
|
||||
await uploadSecrets(resolvedConfig, packageManager);
|
||||
await wranglerCommands(resolvedConfig, packageManager);
|
||||
await execCommands(
|
||||
resolvedConfig,
|
||||
packageManager,
|
||||
getMultilineInput("postCommands"),
|
||||
"post",
|
||||
);
|
||||
info(resolvedConfig, "🏁 Wrangler Action completed", true);
|
||||
} catch (err: unknown) {
|
||||
err instanceof Error && error(config, err.message);
|
||||
setFailed("🚨 Action failed");
|
||||
}
|
||||
}
|
||||
|
||||
function parseWranglerVersion(stdout: string): string {
|
||||
const match =
|
||||
stdout.match(/wrangler (\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?)/) ??
|
||||
stdout.match(/^(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?)/m);
|
||||
return match ? match[1] : "";
|
||||
}
|
||||
|
||||
function isExactSemver(version: string): boolean {
|
||||
return semverValid(version) !== null;
|
||||
}
|
||||
|
||||
async function resolveInstalledVersion(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
): Promise<string> {
|
||||
const { stdout } = await getExecOutput(
|
||||
packageManager.execNoInstall,
|
||||
["wrangler", "--version"],
|
||||
{
|
||||
cwd: config["workingDirectory"],
|
||||
silent: config.QUIET_MODE,
|
||||
},
|
||||
);
|
||||
return parseWranglerVersion(stdout);
|
||||
}
|
||||
|
||||
async function installWrangler(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
): Promise<string> {
|
||||
if (config["WRANGLER_VERSION"].startsWith("1")) {
|
||||
throw new Error(
|
||||
`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`,
|
||||
);
|
||||
}
|
||||
|
||||
startGroup(config, "🔍 Checking for existing Wrangler installation");
|
||||
let installedVersion = "";
|
||||
let versionSatisfied = false;
|
||||
try {
|
||||
installedVersion = await resolveInstalledVersion(config, packageManager);
|
||||
|
||||
if (config.didUserProvideWranglerVersion && installedVersion) {
|
||||
if (isExactSemver(config["WRANGLER_VERSION"])) {
|
||||
versionSatisfied = installedVersion === config["WRANGLER_VERSION"];
|
||||
} else {
|
||||
// semverSatisfies handles ranges like "4", "^4.0.0", "4.x".
|
||||
// Returns false for dist-tags like "latest", falling through to reinstall.
|
||||
try {
|
||||
versionSatisfied = semverSatisfies(
|
||||
installedVersion,
|
||||
config["WRANGLER_VERSION"],
|
||||
);
|
||||
} catch {
|
||||
versionSatisfied = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!config.didUserProvideWranglerVersion && installedVersion) {
|
||||
info(
|
||||
config,
|
||||
`✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`,
|
||||
true,
|
||||
);
|
||||
endGroup(config);
|
||||
return installedVersion;
|
||||
}
|
||||
if (config.didUserProvideWranglerVersion && versionSatisfied) {
|
||||
info(config, `✅ Using Wrangler ${installedVersion}`, true);
|
||||
endGroup(config);
|
||||
return installedVersion;
|
||||
}
|
||||
info(
|
||||
config,
|
||||
"⚠️ Wrangler not found or version is incompatible. Installing...",
|
||||
true,
|
||||
);
|
||||
} catch (error) {
|
||||
debug(`Error checking Wrangler version: ${error}`);
|
||||
info(
|
||||
config,
|
||||
"⚠️ Wrangler not found or version is incompatible. Installing...",
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
endGroup(config);
|
||||
}
|
||||
|
||||
startGroup(config, "📥 Installing Wrangler");
|
||||
try {
|
||||
await exec(
|
||||
packageManager.install,
|
||||
[`wrangler@${config["WRANGLER_VERSION"]}`],
|
||||
{
|
||||
cwd: config["workingDirectory"],
|
||||
silent: config["QUIET_MODE"],
|
||||
},
|
||||
);
|
||||
|
||||
info(config, `✅ Wrangler installed`, true);
|
||||
} finally {
|
||||
endGroup(config);
|
||||
}
|
||||
|
||||
let resolvedVersion = "";
|
||||
try {
|
||||
resolvedVersion = await resolveInstalledVersion(config, packageManager);
|
||||
} catch (err) {
|
||||
debug(`Error resolving installed Wrangler version: ${err}`);
|
||||
}
|
||||
|
||||
if (resolvedVersion) {
|
||||
return resolvedVersion;
|
||||
}
|
||||
|
||||
// Fall back to the raw version string if it's already valid semver.
|
||||
// This preserves pre-existing behavior for exact version inputs.
|
||||
if (isExactSemver(config["WRANGLER_VERSION"])) {
|
||||
return config["WRANGLER_VERSION"];
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Failed to determine installed Wrangler version after installing wrangler@${config["WRANGLER_VERSION"]}`,
|
||||
);
|
||||
}
|
||||
|
||||
function authenticationSetup(config: WranglerActionConfig) {
|
||||
process.env.CLOUDFLARE_API_TOKEN = config["CLOUDFLARE_API_TOKEN"];
|
||||
process.env.CLOUDFLARE_ACCOUNT_ID = config["CLOUDFLARE_ACCOUNT_ID"];
|
||||
}
|
||||
|
||||
async function execCommands(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
commands: string[],
|
||||
cmdType: string,
|
||||
) {
|
||||
if (!commands.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
startGroup(config, `🚀 Running ${cmdType}Commands`);
|
||||
try {
|
||||
for (const command of commands) {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${packageManager.exec} ${command}`
|
||||
: command;
|
||||
|
||||
await execShell(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
silent: config["QUIET_MODE"],
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
endGroup(config);
|
||||
}
|
||||
}
|
||||
|
||||
function getSecret(secret: string) {
|
||||
if (!secret) {
|
||||
throw new Error("Secret name cannot be blank.");
|
||||
}
|
||||
|
||||
const value = process.env[secret];
|
||||
if (!value) {
|
||||
throw new Error(`Value for secret ${secret} not found in environment.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function getEnvVar(envVar: string) {
|
||||
if (!envVar) {
|
||||
throw new Error("Var name cannot be blank.");
|
||||
}
|
||||
|
||||
const value = process.env[envVar];
|
||||
if (!value) {
|
||||
throw new Error(`Value for var ${envVar} not found in environment.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
async function legacyUploadSecrets(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
secrets: string[],
|
||||
environment?: string,
|
||||
workingDirectory?: string,
|
||||
) {
|
||||
for (const secret of secrets) {
|
||||
const args = ["wrangler", "secret", "put", secret];
|
||||
if (environment) {
|
||||
args.push("--env", environment);
|
||||
}
|
||||
await exec(packageManager.exec, args, {
|
||||
cwd: workingDirectory,
|
||||
silent: config["QUIET_MODE"],
|
||||
input: Buffer.from(getSecret(secret)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadSecrets(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
) {
|
||||
const secrets: string[] = config["secrets"];
|
||||
const environment = config["ENVIRONMENT"];
|
||||
const workingDirectory = config["workingDirectory"];
|
||||
|
||||
if (!secrets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
startGroup(config, "🔑 Uploading secrets...");
|
||||
|
||||
try {
|
||||
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0")) {
|
||||
return legacyUploadSecrets(
|
||||
config,
|
||||
packageManager,
|
||||
secrets,
|
||||
environment,
|
||||
workingDirectory,
|
||||
);
|
||||
}
|
||||
|
||||
let args = ["wrangler", "secret", "bulk"];
|
||||
// if we're on a WRANGLER_VERSION prior to 3.60.0 use wrangler secret:bulk
|
||||
if (semverLt(config["WRANGLER_VERSION"], "3.60.0")) {
|
||||
args = ["wrangler", "secret:bulk"];
|
||||
}
|
||||
|
||||
if (environment) {
|
||||
args.push("--env", environment);
|
||||
}
|
||||
|
||||
await exec(packageManager.exec, args, {
|
||||
cwd: workingDirectory,
|
||||
silent: config["QUIET_MODE"],
|
||||
input: Buffer.from(
|
||||
JSON.stringify(
|
||||
Object.fromEntries(
|
||||
secrets.map((secret) => [secret, getSecret(secret)]),
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof Error) {
|
||||
error(config, err.message);
|
||||
err.stack && debug(err.stack);
|
||||
}
|
||||
throw new Error(`Failed to upload secrets.`);
|
||||
} finally {
|
||||
endGroup(config);
|
||||
}
|
||||
}
|
||||
|
||||
async function wranglerCommands(
|
||||
config: WranglerActionConfig,
|
||||
packageManager: PackageManager,
|
||||
) {
|
||||
startGroup(config, "🚀 Running Wrangler Commands");
|
||||
try {
|
||||
const commands = config["COMMANDS"];
|
||||
const environment = config["ENVIRONMENT"];
|
||||
|
||||
if (!commands.length) {
|
||||
const wranglerVersion = config["WRANGLER_VERSION"];
|
||||
const deployCommand = semverCompare("2.20.0", wranglerVersion)
|
||||
? "deploy"
|
||||
: "publish";
|
||||
commands.push(deployCommand);
|
||||
}
|
||||
|
||||
for (let command of commands) {
|
||||
const args = [];
|
||||
|
||||
if (environment && !command.includes("--env")) {
|
||||
args.push("--env", environment);
|
||||
}
|
||||
|
||||
if (
|
||||
config["VARS"].length &&
|
||||
(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes("--var")
|
||||
) {
|
||||
args.push("--var");
|
||||
for (const v of config["VARS"]) {
|
||||
args.push(`${v}:${getEnvVar(v)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Used for saving the wrangler output
|
||||
let stdOut = "";
|
||||
let stdErr = "";
|
||||
|
||||
// set WRANGLER_OUTPUT_FILE_DIRECTORY env for exec
|
||||
process.env.WRANGLER_OUTPUT_FILE_DIRECTORY = config.WRANGLER_OUTPUT_DIR;
|
||||
|
||||
const options = {
|
||||
cwd: config["workingDirectory"],
|
||||
silent: config["QUIET_MODE"],
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
stdOut += data.toString();
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
stdErr += data.toString();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Execute the wrangler command
|
||||
await exec(`${packageManager.exec} wrangler ${command}`, args, options);
|
||||
|
||||
// Set the outputs for the command
|
||||
setOutput("command-output", stdOut);
|
||||
setOutput("command-stderr", stdErr);
|
||||
|
||||
// Handles setting github action outputs and creating github deployment and job summary
|
||||
await handleCommandOutputParsing(config, command, stdOut);
|
||||
}
|
||||
} finally {
|
||||
endGroup(config);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
authenticationSetup,
|
||||
execCommands,
|
||||
info,
|
||||
installWrangler,
|
||||
isExactSemver,
|
||||
main,
|
||||
parseWranglerVersion,
|
||||
uploadSecrets,
|
||||
wranglerCommands,
|
||||
};
|
||||
@@ -0,0 +1,183 @@
|
||||
import mockfs from "mock-fs";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
getOutputEntry,
|
||||
getWranglerArtifacts,
|
||||
} from "./wranglerArtifactManager";
|
||||
|
||||
afterEach(() => {
|
||||
mockfs.restore();
|
||||
});
|
||||
describe("wranglerArtifactsManager", () => {
|
||||
describe("getWranglerArtifacts()", async () => {
|
||||
it("Returns only wrangler output files from a given directory", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
{"version": 1, "type":"wrangler-session", "wrangler_version":"3.81.0", "command_line_args":["what's up"], "log_file_path": "/here"}
|
||||
{"version": 1, "type":"pages-deploy-detailed", "environment":"production", "alias":"test.com", "deployment_id": "123", "url":"url.com"}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifacts = await getWranglerArtifacts("./testOutputDir");
|
||||
|
||||
expect(artifacts).toEqual([
|
||||
"./testOutputDir/wrangler-output-2024-10-17_18-48-40_463-2e6e83.json",
|
||||
]);
|
||||
});
|
||||
it("Returns an empty list when the output directory doesn't exist", async () => {
|
||||
mockfs({
|
||||
notTheDirWeWant: {},
|
||||
});
|
||||
|
||||
const artifacts = await getWranglerArtifacts("./testOutputDir");
|
||||
expect(artifacts).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getOutputEntry()", async () => {
|
||||
describe("OutputEntryPagesDeployment", async () => {
|
||||
it("Returns only detailed pages deploy output from wrangler artifacts", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
{"version": 1, "type":"wrangler-session", "wrangler_version":"3.81.0", "command_line_args":["what's up"], "log_file_path": "/here"}
|
||||
{"version": 1, "type":"pages-deploy-detailed", "pages_project": "project", "environment":"production", "alias":"test.com", "deployment_id": "123", "url":"url.com"}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "pages-deploy-detailed") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
pages_project: "project",
|
||||
type: "pages-deploy-detailed",
|
||||
url: "url.com",
|
||||
environment: "production",
|
||||
deployment_id: "123",
|
||||
alias: "test.com",
|
||||
});
|
||||
}),
|
||||
it("Skips artifact entries that are not parseable", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
this line is invalid json.
|
||||
{"version": 1, "type":"pages-deploy-detailed", "pages_project": "project", "environment":"production", "alias":"test.com", "deployment_id": "123", "url":"url.com"}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "pages-deploy-detailed") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
type: "pages-deploy-detailed",
|
||||
pages_project: "project",
|
||||
url: "url.com",
|
||||
environment: "production",
|
||||
deployment_id: "123",
|
||||
alias: "test.com",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("OutputEntryDeployment", async () => {
|
||||
it("Returns only wrangler deploy output from wrangler artifacts", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
{"version": 1, "type":"wrangler-session", "wrangler_version":"3.81.0", "command_line_args":["what's up"], "log_file_path": "/here"}
|
||||
{"version": 1, "type":"deploy", "targets": ["https://example.com"]}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "deploy") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
type: "deploy",
|
||||
targets: ["https://example.com"],
|
||||
});
|
||||
}),
|
||||
it("Skips artifact entries that are not parseable", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
this line is invalid json.
|
||||
{"version": 1, "type":"deploy", "targets": ["https://example.com"]}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "deploy") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
type: "deploy",
|
||||
targets: ["https://example.com"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("OutputEntryVersionUpload", async () => {
|
||||
it("Returns only version upload output from wrangler artifacts", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
{"version": 1, "type":"wrangler-session", "wrangler_version":"3.81.0", "command_line_args":["what's up"], "log_file_path": "/here"}
|
||||
{"version": 1, "type":"version-upload", "preview_url": "https://example.com"}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "version-upload") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
type: "version-upload",
|
||||
preview_url: "https://example.com",
|
||||
});
|
||||
}),
|
||||
it("Skips artifact entries that are not parseable", async () => {
|
||||
mockfs({
|
||||
testOutputDir: {
|
||||
"wrangler-output-2024-10-17_18-48-40_463-2e6e83.json": `
|
||||
this line is invalid json.
|
||||
{"version": 1, "type":"version-upload", "preview_url": "https://example.com"}`,
|
||||
"not-wrangler-output.json": "test",
|
||||
},
|
||||
});
|
||||
|
||||
const artifact = await getOutputEntry("./testOutputDir");
|
||||
if (artifact?.type !== "version-upload") {
|
||||
throw new Error(`Unexpected type ${artifact?.type}`);
|
||||
}
|
||||
|
||||
expect(artifact).toEqual({
|
||||
version: 1,
|
||||
type: "version-upload",
|
||||
preview_url: "https://example.com",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
import { access, open, readdir } from "fs/promises";
|
||||
import { z } from "zod";
|
||||
|
||||
const OutputEntryBase = z.object({
|
||||
version: z.literal(1),
|
||||
type: z.string(),
|
||||
});
|
||||
|
||||
export type OutputEntryPagesDeployment = z.infer<
|
||||
typeof OutputEntryPagesDeployment
|
||||
>;
|
||||
const OutputEntryPagesDeployment = OutputEntryBase.merge(
|
||||
z.object({
|
||||
type: z.literal("pages-deploy-detailed"),
|
||||
pages_project: z.string().nullable(),
|
||||
deployment_id: z.string().nullable(),
|
||||
url: z.string().optional(),
|
||||
alias: z.string().optional(),
|
||||
environment: z.enum(["production", "preview"]),
|
||||
// optional, added in wrangler@3.89.0
|
||||
production_branch: z.string().optional(),
|
||||
// optional, added in wrangler@3.89.0
|
||||
deployment_trigger: z
|
||||
.object({
|
||||
metadata: z.object({
|
||||
/** Commit hash of the deployment trigger metadata for the pages project */
|
||||
commit_hash: z.string(),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export type OutputEntryDeployment = z.infer<typeof OutputEntryDeployment>;
|
||||
const OutputEntryDeployment = OutputEntryBase.merge(
|
||||
z.object({
|
||||
type: z.literal("deploy"),
|
||||
/** A list of URLs that represent the HTTP triggers associated with this deployment */
|
||||
/** basically, for wrangler-action purposes this is the deployment urls */
|
||||
targets: z.array(z.string()).optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export type OutputEntryVersionUpload = z.infer<typeof OutputEntryVersionUpload>;
|
||||
const OutputEntryVersionUpload = OutputEntryBase.merge(
|
||||
z.object({
|
||||
type: z.literal("version-upload"),
|
||||
/** The preview URL associated with this version upload */
|
||||
preview_url: z.string().optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export type SupportedOutputEntry = z.infer<typeof SupportedOutputEntry>;
|
||||
const SupportedOutputEntry = z.discriminatedUnion("type", [
|
||||
OutputEntryPagesDeployment,
|
||||
OutputEntryDeployment,
|
||||
OutputEntryVersionUpload,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Parses file names in a directory to find wrangler artifact files
|
||||
*
|
||||
* @param artifactDirectory
|
||||
* @returns All artifact files from the directory
|
||||
*/
|
||||
export async function getWranglerArtifacts(
|
||||
artifactDirectory: string,
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
await access(artifactDirectory);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
// read files in asset directory
|
||||
const dirent = await readdir(artifactDirectory, {
|
||||
withFileTypes: true,
|
||||
recursive: false,
|
||||
});
|
||||
|
||||
// Match files to wrangler-output-<timestamp>-xxxxxx.json
|
||||
const regex = new RegExp(
|
||||
/^wrangler-output-[\d]{4}-[\d]{2}-[\d]{2}_[\d]{2}-[\d]{2}-[\d]{2}_[\d]{3}-[A-Fa-f0-9]{6}\.json$/,
|
||||
);
|
||||
const artifactFilePaths = dirent
|
||||
.filter((d) => d.name.match(regex))
|
||||
.map((d) => `${artifactDirectory}/${d.name}`);
|
||||
|
||||
return artifactFilePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a supported wrangler OutputEntry
|
||||
*
|
||||
* @param artifactDirectory
|
||||
* @returns The first SupportedOutputEntry found within a wrangler artifact directory
|
||||
*/
|
||||
export async function getOutputEntry(
|
||||
artifactDirectory: string,
|
||||
): Promise<SupportedOutputEntry | null> {
|
||||
const artifactFilePaths = await getWranglerArtifacts(artifactDirectory);
|
||||
|
||||
for (const filePath of artifactFilePaths) {
|
||||
const file = await open(filePath, "r");
|
||||
try {
|
||||
for await (const line of file.readLines()) {
|
||||
try {
|
||||
// Attempt to parse and validate the JSON line against the union schema.
|
||||
// Assume, in the context of the action, the first OutputEntry seen will suffice
|
||||
return SupportedOutputEntry.parse(JSON.parse(line));
|
||||
} catch {
|
||||
// Skip lines that are invalid JSON or don't match any schema.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"files": ["./src/index.ts"],
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"composite": true,
|
||||
"incremental": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"isolatedModules": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"lib": ["ESNext"],
|
||||
"types": ["node", "@cloudflare/workers-types"]
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user