Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"wrangler-action": minor
|
||||
---
|
||||
|
||||
Support for package managers other than npm, such as pnpm and yarn.
|
||||
|
||||
fixes #156
|
||||
@@ -34,6 +34,15 @@ jobs:
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Only build app w/ quiet enabled
|
||||
uses: ./
|
||||
with:
|
||||
quiet: true
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
# START Setup and teardown of Worker Environment Tests
|
||||
- name: Environment support
|
||||
uses: ./
|
||||
@@ -42,6 +51,7 @@ jobs:
|
||||
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
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
@@ -101,4 +111,43 @@ jobs:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: delete --name wrangler-action-test --force
|
||||
# END Setup and teardown of Workers w/ Secrets Tests
|
||||
# END Setup and teardown of Workers w/ Secrets Tests
|
||||
|
||||
- name: Support packageManager variable
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/empty"
|
||||
packageManager: "npm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Support npm package manager
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/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: "./test/yarn"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
- name: Install pnpm
|
||||
run: npm i -g pnpm
|
||||
|
||||
- name: Support pnpm package manager
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/pnpm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
@@ -13,4 +13,4 @@ jobs:
|
||||
- uses: actions/add-to-project@v0.5.0
|
||||
with:
|
||||
project-url: https://github.com/orgs/cloudflare/projects/1
|
||||
github-token: ${{ secrets.GH_ACCESS_TOKEN }}
|
||||
github-token: ${{ secrets.GH_ACCESS_TOKEN }}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
name: Publish
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.release.tag_name }}
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "latest"
|
||||
cache: "npm"
|
||||
|
||||
- name: Install modules and build
|
||||
run: npm ci && npm run build
|
||||
|
||||
- uses: JasonEtco/build-and-tag-action@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
@@ -38,3 +38,15 @@ jobs:
|
||||
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 }}
|
||||
@@ -8,9 +8,11 @@ function workerHealthCheck() {
|
||||
|
||||
const response = buffer.toString();
|
||||
|
||||
response.includes("OK")
|
||||
? console.log(`Status: Worker is up! Secrets: ${response}`)
|
||||
: console.log(`Worker is down!`);
|
||||
if (response.includes("OK")) {
|
||||
console.log(`Status: Worker is up! Response: ${response}`);
|
||||
} else {
|
||||
throw new Error(`Worker is down! Response: ${response}`);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pnpm-lock.yaml
|
||||
@@ -1,5 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
## 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
|
||||
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
* @cloudflare/wrangler
|
||||
* @cloudflare/wrangler
|
||||
|
||||
CHANGELOG.md @cloudflare/wrangler-admins
|
||||
@@ -1,12 +1,12 @@
|
||||
# Wrangler GitHub Action
|
||||
|
||||
Easy-to-use GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/). Makes deploying Workers, Pages or modifying R2 easy to do.
|
||||
Easy-to-use GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/). Makes deploying Workers a breeze.
|
||||
|
||||
## 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` and `uses: cloudflare/wrangler-action@v3.x` are both now valid syntax. Previously supported syntax e.g. `uses: cloudflare/wrangler-action@3.x.x` continues to be 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).
|
||||
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -58,7 +58,7 @@ If you need to install a specific version of Wrangler to use for deployment, you
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
wranglerVersion: "2.20.0"
|
||||
@@ -70,7 +70,7 @@ Optionally, you can also pass a `workingDirectory` key to the action. This will
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
workingDirectory: "subfoldername"
|
||||
@@ -82,7 +82,7 @@ jobs:
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
secrets: |
|
||||
@@ -99,7 +99,7 @@ If you need to run additional shell commands before or after your command, you c
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
preCommands: echo "*** pre command ***"
|
||||
@@ -115,7 +115,7 @@ You can use the `command` option to do specific actions such as running `wrangle
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
command: whoami
|
||||
@@ -140,7 +140,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -161,7 +161,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
@@ -184,7 +184,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -210,7 +210,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
command: deploy --env ${{ github.event.inputs.environment }}
|
||||
@@ -238,7 +238,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Deploy app
|
||||
uses: cloudflare/wrangler-action@3.0.0
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
|
||||
+9
-2
@@ -4,7 +4,8 @@ branding:
|
||||
color: "orange"
|
||||
description: "Deploy your Cloudflare projects from GitHub using Wrangler"
|
||||
runs:
|
||||
using: "node16"
|
||||
# Possible values: https://github.com/actions/runner/blob/main/src/Runner.Common/Util/NodeUtil.cs#L9
|
||||
using: "node20"
|
||||
main: "dist/index.mjs"
|
||||
inputs:
|
||||
apiToken:
|
||||
@@ -13,7 +14,10 @@ inputs:
|
||||
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 deploy your Workers project to - must be defined in wrangler.toml"
|
||||
workingDirectory:
|
||||
@@ -37,3 +41,6 @@ inputs:
|
||||
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 name of the package manager to install and run wrangler. If not provided, it will be detected via the lock file. Valid values: [npm, pnpm, yarn]"
|
||||
required: false
|
||||
|
||||
Generated
+57
-57
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "wrangler-action",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0"
|
||||
@@ -14,12 +14,12 @@
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.4.8",
|
||||
"@changesets/cli": "^2.26.2",
|
||||
"@cloudflare/workers-types": "^4.20230710.1",
|
||||
"@types/node": "^20.4.2",
|
||||
"@cloudflare/workers-types": "^4.20230814.0",
|
||||
"@types/node": "^20.5.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"prettier": "^3.0.0",
|
||||
"prettier": "^3.0.1",
|
||||
"typescript": "^5.1.6",
|
||||
"vitest": "^0.33.0"
|
||||
"vitest": "^0.34.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/core": {
|
||||
@@ -366,9 +366,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@cloudflare/workers-types": {
|
||||
"version": "4.20230801.0",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230801.0.tgz",
|
||||
"integrity": "sha512-RzRUR+J/T3h58qbTZHYntYsnZXu3JnrlZIhqP2hhdyfoZAZ/+ko4wX0foAqlYHi+kXWaWtySHBuMcx6ec6TXlQ==",
|
||||
"version": "4.20230814.0",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230814.0.tgz",
|
||||
"integrity": "sha512-+jHiGjZg2UpULZSSHmHLqUG45TLg1s+uppSMlGvMn0u/xyFsRX9HX6b8Ydg/oHSp3jfSuPtX05GSvtgRAmrWTg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
@@ -879,9 +879,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.4.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.6.tgz",
|
||||
"integrity": "sha512-q0RkvNgMweWWIvSMDiXhflGUKMdIxBo2M2tYM/0kEGDueQByFzK4KZAgu5YHGFNxziTlppNpTIBcqHQAxlfHdA==",
|
||||
"version": "20.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.0.tgz",
|
||||
"integrity": "sha512-Mgq7eCtoTjT89FqNoTzzXg2XvCi5VMhRV6+I2aYanc6kQCBImeNaAYRs/DyoVqk1YEUJK5gN9VO7HRIdz4Wo3Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/normalize-package-data": {
|
||||
@@ -906,13 +906,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.33.0.tgz",
|
||||
"integrity": "sha512-sVNf+Gla3mhTCxNJx+wJLDPp/WcstOe0Ksqz4Vec51MmgMth/ia0MGFEkIZmVGeTL5HtjYR4Wl/ZxBxBXZJTzQ==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.34.1.tgz",
|
||||
"integrity": "sha512-q2CD8+XIsQ+tHwypnoCk8Mnv5e6afLFvinVGCq3/BOT4kQdVQmY6rRfyKkwcg635lbliLPqbunXZr+L1ssUWiQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@vitest/spy": "0.33.0",
|
||||
"@vitest/utils": "0.33.0",
|
||||
"@vitest/spy": "0.34.1",
|
||||
"@vitest/utils": "0.34.1",
|
||||
"chai": "^4.3.7"
|
||||
},
|
||||
"funding": {
|
||||
@@ -920,12 +920,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/runner": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-0.33.0.tgz",
|
||||
"integrity": "sha512-UPfACnmCB6HKRHTlcgCoBh6ppl6fDn+J/xR8dTufWiKt/74Y9bHci5CKB8tESSV82zKYtkBJo9whU3mNvfaisg==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-0.34.1.tgz",
|
||||
"integrity": "sha512-YfQMpYzDsYB7yqgmlxZ06NI4LurHWfrH7Wy3Pvf/z/vwUSgq1zLAb1lWcItCzQG+NVox+VvzlKQrYEXb47645g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@vitest/utils": "0.33.0",
|
||||
"@vitest/utils": "0.34.1",
|
||||
"p-limit": "^4.0.0",
|
||||
"pathe": "^1.1.1"
|
||||
},
|
||||
@@ -949,9 +949,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-0.33.0.tgz",
|
||||
"integrity": "sha512-tJjrl//qAHbyHajpFvr8Wsk8DIOODEebTu7pgBrP07iOepR5jYkLFiqLq2Ltxv+r0uptUb4izv1J8XBOwKkVYA==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-0.34.1.tgz",
|
||||
"integrity": "sha512-0O9LfLU0114OqdF8lENlrLsnn024Tb1CsS9UwG0YMWY2oGTQfPtkW+B/7ieyv0X9R2Oijhi3caB1xgGgEgclSQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"magic-string": "^0.30.1",
|
||||
@@ -963,9 +963,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/spy": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-0.33.0.tgz",
|
||||
"integrity": "sha512-Kv+yZ4hnH1WdiAkPUQTpRxW8kGtH8VRTnus7ZTGovFYM1ZezJpvGtb9nPIjPnptHbsyIAxYZsEpVPYgtpjGnrg==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-0.34.1.tgz",
|
||||
"integrity": "sha512-UT4WcI3EAPUNO8n6y9QoEqynGGEPmmRxC+cLzneFFXpmacivjHZsNbiKD88KUScv5DCHVDgdBsLD7O7s1enFcQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"tinyspy": "^2.1.1"
|
||||
@@ -975,9 +975,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-0.33.0.tgz",
|
||||
"integrity": "sha512-pF1w22ic965sv+EN6uoePkAOTkAPWM03Ri/jXNyMIKBb/XHLDPfhLvf/Fa9g0YECevAIz56oVYXhodLvLQ/awA==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-0.34.1.tgz",
|
||||
"integrity": "sha512-/ql9dsFi4iuEbiNcjNHQWXBum7aL8pyhxvfnD9gNtbjR9fUKAjxhj4AA3yfLXg6gJpMGGecvtF8Au2G9y3q47Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"diff-sequences": "^29.4.3",
|
||||
@@ -3054,9 +3054,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz",
|
||||
"integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.1.tgz",
|
||||
"integrity": "sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
@@ -3288,9 +3288,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/rollup": {
|
||||
"version": "3.27.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.27.0.tgz",
|
||||
"integrity": "sha512-aOltLCrYZ0FhJDm7fCqwTjIUEVjWjcydKBV/Zeid6Mn8BWgDCUBBWT5beM5ieForYNo/1ZHuGJdka26kvQ3Gzg==",
|
||||
"version": "3.28.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.0.tgz",
|
||||
"integrity": "sha512-d7zhvo1OUY2SXSM6pfNjgD5+d0Nz87CUp4mt8l/GgVP3oBsPwzNvSzyu1me6BSG9JIgWNTVcafIXBIyM8yQ3yw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
@@ -3772,9 +3772,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tinypool": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tinypool/-/tinypool-0.6.0.tgz",
|
||||
"integrity": "sha512-FdswUUo5SxRizcBc6b1GSuLpLjisa8N8qMyYoP3rl+bym+QauhtJP5bvZY1ytt8krKGmMLYIRl36HBZfeAoqhQ==",
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/tinypool/-/tinypool-0.7.0.tgz",
|
||||
"integrity": "sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
@@ -4075,14 +4075,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "4.4.8",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.4.8.tgz",
|
||||
"integrity": "sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==",
|
||||
"version": "4.4.9",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.4.9.tgz",
|
||||
"integrity": "sha512-2mbUn2LlUmNASWwSCNSJ/EG2HuSRTnVNaydp6vMCm5VIqJsjMfbIWtbH2kDuwUVW5mMUKKZvGPX/rqeqVvv1XA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.18.10",
|
||||
"postcss": "^8.4.26",
|
||||
"rollup": "^3.25.2"
|
||||
"postcss": "^8.4.27",
|
||||
"rollup": "^3.27.1"
|
||||
},
|
||||
"bin": {
|
||||
"vite": "bin/vite.js"
|
||||
@@ -4130,9 +4130,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vite-node": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/vite-node/-/vite-node-0.33.0.tgz",
|
||||
"integrity": "sha512-19FpHYbwWWxDr73ruNahC+vtEdza52kA90Qb3La98yZ0xULqV8A5JLNPUff0f5zID4984tW7l3DH2przTJUZSw==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/vite-node/-/vite-node-0.34.1.tgz",
|
||||
"integrity": "sha512-odAZAL9xFMuAg8aWd7nSPT+hU8u2r9gU3LRm9QKjxBEF2rRdWpMuqkrkjvyVQEdNFiBctqr2Gg4uJYizm5Le6w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"cac": "^6.7.14",
|
||||
@@ -4153,19 +4153,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vitest": {
|
||||
"version": "0.33.0",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-0.33.0.tgz",
|
||||
"integrity": "sha512-1CxaugJ50xskkQ0e969R/hW47za4YXDUfWJDxip1hwbnhUjYolpfUn2AMOulqG/Dtd9WYAtkHmM/m3yKVrEejQ==",
|
||||
"version": "0.34.1",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-0.34.1.tgz",
|
||||
"integrity": "sha512-G1PzuBEq9A75XSU88yO5G4vPT20UovbC/2osB2KEuV/FisSIIsw7m5y2xMdB7RsAGHAfg2lPmp2qKr3KWliVlQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/chai": "^4.3.5",
|
||||
"@types/chai-subset": "^1.3.3",
|
||||
"@types/node": "*",
|
||||
"@vitest/expect": "0.33.0",
|
||||
"@vitest/runner": "0.33.0",
|
||||
"@vitest/snapshot": "0.33.0",
|
||||
"@vitest/spy": "0.33.0",
|
||||
"@vitest/utils": "0.33.0",
|
||||
"@vitest/expect": "0.34.1",
|
||||
"@vitest/runner": "0.34.1",
|
||||
"@vitest/snapshot": "0.34.1",
|
||||
"@vitest/spy": "0.34.1",
|
||||
"@vitest/utils": "0.34.1",
|
||||
"acorn": "^8.9.0",
|
||||
"acorn-walk": "^8.2.0",
|
||||
"cac": "^6.7.14",
|
||||
@@ -4178,9 +4178,9 @@
|
||||
"std-env": "^3.3.3",
|
||||
"strip-literal": "^1.0.1",
|
||||
"tinybench": "^2.5.0",
|
||||
"tinypool": "^0.6.0",
|
||||
"tinypool": "^0.7.0",
|
||||
"vite": "^3.0.0 || ^4.0.0",
|
||||
"vite-node": "0.33.0",
|
||||
"vite-node": "0.34.1",
|
||||
"why-is-node-running": "^2.2.2"
|
||||
},
|
||||
"bin": {
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wrangler-action",
|
||||
"version": "3.0.2",
|
||||
"version": "3.1.1",
|
||||
"description": "GitHub Action to use [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/).",
|
||||
"author": "wrangler@cloudflare.com",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
@@ -25,8 +25,8 @@
|
||||
"scripts": {
|
||||
"build": "npx ncc build ./src/index.ts && mv ./dist/index.js ./dist/index.mjs",
|
||||
"test": "vitest",
|
||||
"format": "prettier --write . --ignore-path ./dist/**",
|
||||
"check": "prettier --check . --ignore-path ./dist/**"
|
||||
"format": "prettier --write .",
|
||||
"check": "prettier --check ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0"
|
||||
@@ -34,11 +34,11 @@
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.4.8",
|
||||
"@changesets/cli": "^2.26.2",
|
||||
"@cloudflare/workers-types": "^4.20230710.1",
|
||||
"@types/node": "^20.4.2",
|
||||
"@cloudflare/workers-types": "^4.20230814.0",
|
||||
"@types/node": "^20.5.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"prettier": "^3.0.0",
|
||||
"prettier": "^3.0.1",
|
||||
"typescript": "^5.1.6",
|
||||
"vitest": "^0.33.0"
|
||||
"vitest": "^0.34.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import { expect, test, describe } from "vitest";
|
||||
import { checkWorkingDirectory, getNpxCmd, semverCompare } from "./index";
|
||||
import path from "node:path";
|
||||
|
||||
const config = {
|
||||
WRANGLER_VERSION: "mockVersion",
|
||||
secrets: ["mockSercret", "mockSecretAgain"],
|
||||
workingDirectory: "./mockWorkingDirectory",
|
||||
CLOUDFLARE_API_TOKEN: "mockAPIToken",
|
||||
CLOUDFLARE_ACCOUNT_ID: "mockAccountID",
|
||||
ENVIRONMENT: undefined,
|
||||
VARS: ["mockVar", "mockVarAgain"],
|
||||
COMMANDS: ["mockCommand", "mockCommandAgain"],
|
||||
};
|
||||
|
||||
test("getNpxCmd ", async () => {
|
||||
process.env.RUNNER_OS = "Windows";
|
||||
expect(getNpxCmd()).toBe("npx.cmd");
|
||||
|
||||
process.env.RUNNER_OS = "Mac";
|
||||
expect(getNpxCmd()).toBe("npx");
|
||||
|
||||
process.env.RUNNER_OS = "Linux";
|
||||
expect(getNpxCmd()).toBe("npx");
|
||||
|
||||
delete process.env.RUNNER_OS;
|
||||
});
|
||||
|
||||
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", () => {
|
||||
try {
|
||||
checkWorkingDirectory("/does/not/exist");
|
||||
} catch (error) {
|
||||
expect(error.message).toMatchInlineSnapshot();
|
||||
}
|
||||
});
|
||||
|
||||
test("should fail if an error occurs while checking/creating the directory", () => {
|
||||
try {
|
||||
checkWorkingDirectory("/does/not/exist");
|
||||
} catch (error) {
|
||||
expect(error.message).toMatchInlineSnapshot();
|
||||
}
|
||||
});
|
||||
});
|
||||
+164
-137
@@ -1,19 +1,45 @@
|
||||
import {
|
||||
getBooleanInput,
|
||||
getInput,
|
||||
getMultilineInput,
|
||||
info,
|
||||
endGroup as originalEndGroup,
|
||||
error as originalError,
|
||||
info as originalInfo,
|
||||
startGroup as originalStartGroup,
|
||||
setFailed,
|
||||
endGroup,
|
||||
startGroup,
|
||||
error,
|
||||
} from "@actions/core";
|
||||
import { execSync, exec } from "node:child_process";
|
||||
import { existsSync } from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { exec, execSync } from "node:child_process";
|
||||
import * as util from "node:util";
|
||||
import {
|
||||
PackageManager,
|
||||
checkWorkingDirectory,
|
||||
detectPackageManager,
|
||||
isValidPackageManager,
|
||||
semverCompare,
|
||||
} from "./utils";
|
||||
const execAsync = util.promisify(exec);
|
||||
|
||||
const DEFAULT_WRANGLER_VERSION = "3.4.0";
|
||||
const DEFAULT_WRANGLER_VERSION = "3.5.1";
|
||||
|
||||
interface PackageManagerCommands {
|
||||
install: string;
|
||||
exec: string;
|
||||
}
|
||||
|
||||
const PACKAGE_MANAGER_COMMANDS = {
|
||||
npm: {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
},
|
||||
yarn: {
|
||||
install: "yarn add",
|
||||
exec: "yarn",
|
||||
},
|
||||
pnpm: {
|
||||
install: "pnpm add",
|
||||
exec: "pnpm exec",
|
||||
},
|
||||
} as const satisfies Readonly<Record<PackageManager, PackageManagerCommands>>;
|
||||
|
||||
/**
|
||||
* A configuration object that contains all the inputs & immutable state for the action.
|
||||
@@ -27,39 +53,62 @@ const config = {
|
||||
ENVIRONMENT: getInput("environment"),
|
||||
VARS: getMultilineInput("vars"),
|
||||
COMMANDS: getMultilineInput("command"),
|
||||
QUIET_MODE: getBooleanInput("quiet"),
|
||||
PACKAGE_MANAGER: getInput("packageManager"),
|
||||
} as const;
|
||||
|
||||
function getNpxCmd() {
|
||||
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
|
||||
*/
|
||||
function semverCompare(version1: string, version2: string) {
|
||||
if (version2 === "latest") return true;
|
||||
|
||||
const version1Parts = version1.split(".");
|
||||
const version2Parts = version2.split(".");
|
||||
|
||||
for (const version1Part of version1Parts) {
|
||||
const version2Part = version2Parts.shift();
|
||||
|
||||
if (version1Part !== version2Part && version2Part) {
|
||||
return version1Part < version2Part ? true : false;
|
||||
}
|
||||
function realPackageManager(): PackageManager {
|
||||
if (isValidPackageManager(config.PACKAGE_MANAGER)) {
|
||||
return config.PACKAGE_MANAGER;
|
||||
}
|
||||
|
||||
return false;
|
||||
const packageManager = detectPackageManager(config.workingDirectory);
|
||||
if (packageManager !== null) {
|
||||
return packageManager;
|
||||
}
|
||||
|
||||
throw new Error("Package manager is not detected");
|
||||
}
|
||||
|
||||
const pkgManagerCmd = PACKAGE_MANAGER_COMMANDS[realPackageManager()];
|
||||
|
||||
function info(message: string, bypass?: boolean): void {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
originalInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
function error(message: string, bypass?: boolean): void {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
originalError(message);
|
||||
}
|
||||
}
|
||||
|
||||
function startGroup(name: string): void {
|
||||
if (!config.QUIET_MODE) {
|
||||
originalStartGroup(name);
|
||||
}
|
||||
}
|
||||
|
||||
function endGroup(): void {
|
||||
if (!config.QUIET_MODE) {
|
||||
originalEndGroup();
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
installWrangler();
|
||||
authenticationSetup();
|
||||
await execCommands(getMultilineInput("preCommands"), "pre");
|
||||
await uploadSecrets();
|
||||
await wranglerCommands();
|
||||
await execCommands(getMultilineInput("postCommands"), "post");
|
||||
try {
|
||||
installWrangler();
|
||||
authenticationSetup();
|
||||
await execCommands(getMultilineInput("preCommands"), "pre");
|
||||
await uploadSecrets();
|
||||
await wranglerCommands();
|
||||
await execCommands(getMultilineInput("postCommands"), "post");
|
||||
info("🏁 Wrangler Action completed", true);
|
||||
} catch (err: unknown) {
|
||||
err instanceof Error && error(err.message);
|
||||
setFailed("🚨 Action failed");
|
||||
}
|
||||
}
|
||||
|
||||
async function runProcess(
|
||||
@@ -70,42 +119,27 @@ async function runProcess(
|
||||
const result = await execAsync(command, options);
|
||||
|
||||
result.stdout && info(result.stdout.toString());
|
||||
result.stderr && error(result.stderr.toString());
|
||||
result.stderr && error(result.stderr.toString(), true);
|
||||
|
||||
return result;
|
||||
} catch (err: any) {
|
||||
err.stdout && info(err.stdout.toString());
|
||||
err.stderr && error(err.stderr.toString());
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function checkWorkingDirectory(workingDirectory = ".") {
|
||||
try {
|
||||
const normalizedPath = path.normalize(workingDirectory);
|
||||
if (existsSync(normalizedPath)) {
|
||||
return normalizedPath;
|
||||
} else {
|
||||
setFailed(`🚨 Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
} catch (error) {
|
||||
setFailed(
|
||||
`🚨 While checking/creating directory ${workingDirectory} received ${error}`,
|
||||
);
|
||||
err.stderr && error(err.stderr.toString(), true);
|
||||
throw new Error(`\`${command}\` returned non-zero exit code.`);
|
||||
}
|
||||
}
|
||||
|
||||
function installWrangler() {
|
||||
if (config["WRANGLER_VERSION"].startsWith("1")) {
|
||||
setFailed(
|
||||
`🚨 Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`,
|
||||
throw new Error(
|
||||
`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`,
|
||||
);
|
||||
}
|
||||
startGroup("📥 Installing Wrangler");
|
||||
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
const command = `${pkgManagerCmd.install} wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
info(`Running command: ${command}`);
|
||||
execSync(command, { cwd: config["workingDirectory"], env: process.env });
|
||||
info(`✅ Wrangler installed`);
|
||||
info(`✅ Wrangler installed`, true);
|
||||
endGroup();
|
||||
}
|
||||
|
||||
@@ -118,27 +152,26 @@ async function execCommands(commands: string[], cmdType: string) {
|
||||
if (!commands.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
startGroup(`🚀 Running ${cmdType}Commands`);
|
||||
try {
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${pkgManagerCmd.exec} ${command}`
|
||||
: command;
|
||||
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${getNpxCmd()} ${command}`
|
||||
: command;
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await Promise.all(arrPromises).catch((result) => {
|
||||
result.stdout && info(result.stdout.toString());
|
||||
result.stderr && error(result.stderr.toString());
|
||||
setFailed(`🚨 ${cmdType}Commands failed`);
|
||||
});
|
||||
endGroup();
|
||||
await Promise.all(arrPromises);
|
||||
} finally {
|
||||
endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,12 +179,12 @@ async function execCommands(commands: string[], cmdType: string) {
|
||||
*/
|
||||
function getSecret(secret: string) {
|
||||
if (!secret) {
|
||||
setFailed("No secret provided");
|
||||
throw new Error("Secret name cannot be blank.");
|
||||
}
|
||||
|
||||
const value = process.env[secret];
|
||||
if (!value) {
|
||||
setFailed(`Secret ${secret} not found`);
|
||||
throw new Error(`Value for secret ${secret} not found.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -162,26 +195,22 @@ async function legacyUploadSecrets(
|
||||
environment?: string,
|
||||
workingDirectory?: string,
|
||||
) {
|
||||
try {
|
||||
const arrPromises = secrets
|
||||
.map((secret) => {
|
||||
const command = `echo ${getSecret(
|
||||
secret,
|
||||
)} | ${getNpxCmd()} wrangler secret put ${secret}`;
|
||||
return environment ? command.concat(` --env ${environment}`) : command;
|
||||
})
|
||||
.map(
|
||||
async (command) =>
|
||||
await execAsync(command, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
}),
|
||||
);
|
||||
const arrPromises = secrets
|
||||
.map((secret) => {
|
||||
const command = `echo ${getSecret(secret)} | ${
|
||||
pkgManagerCmd.exec
|
||||
} wrangler secret put ${secret}`;
|
||||
return environment ? command.concat(` --env ${environment}`) : command;
|
||||
})
|
||||
.map(
|
||||
async (command) =>
|
||||
await execAsync(command, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(arrPromises);
|
||||
} catch {
|
||||
setFailed(`🚨 Error uploading secrets`);
|
||||
}
|
||||
await Promise.all(arrPromises);
|
||||
}
|
||||
|
||||
async function uploadSecrets() {
|
||||
@@ -192,9 +221,10 @@ async function uploadSecrets() {
|
||||
if (!secrets.length) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
startGroup("🔑 Uploading Secrets");
|
||||
|
||||
startGroup("🔑 Uploading secrets...");
|
||||
|
||||
try {
|
||||
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0"))
|
||||
return legacyUploadSecrets(secrets, environment, workingDirectory);
|
||||
|
||||
@@ -210,16 +240,18 @@ async function uploadSecrets() {
|
||||
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll(
|
||||
'"',
|
||||
'\\"',
|
||||
)}" | ${getNpxCmd()} wrangler secret:bulk ${environmentSuffix}`;
|
||||
)}" | ${pkgManagerCmd.exec} wrangler secret:bulk ${environmentSuffix}`;
|
||||
|
||||
execSync(secretCmd, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
stdio: "ignore",
|
||||
});
|
||||
|
||||
info(`✅ Uploaded secrets`);
|
||||
} catch {
|
||||
setFailed(`🚨 Error uploading secrets`);
|
||||
} catch (err) {
|
||||
error(`❌ Upload failed`);
|
||||
throw new Error(`Failed to upload secrets.`);
|
||||
} finally {
|
||||
endGroup();
|
||||
}
|
||||
@@ -231,7 +263,7 @@ function getVarArgs() {
|
||||
if (process.env[envVar] && process.env[envVar]?.length !== 0) {
|
||||
return `${envVar}:${process.env[envVar]!}`;
|
||||
} else {
|
||||
setFailed(`🚨 ${envVar} not found in variables.`);
|
||||
throw new Error(`Value for var ${envVar} not found in environment.`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -240,55 +272,50 @@ function getVarArgs() {
|
||||
|
||||
async function wranglerCommands() {
|
||||
startGroup("🚀 Running Wrangler Commands");
|
||||
const commands = config["COMMANDS"];
|
||||
const environment = config["ENVIRONMENT"];
|
||||
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);
|
||||
}
|
||||
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
if (environment.length > 0 && !command.includes(`--env`)) {
|
||||
command = command.concat(` --env ${environment}`);
|
||||
if (!commands.length) {
|
||||
const wranglerVersion = config["WRANGLER_VERSION"];
|
||||
const deployCommand = semverCompare("2.20.0", wranglerVersion)
|
||||
? "deploy"
|
||||
: "publish";
|
||||
commands.push(deployCommand);
|
||||
}
|
||||
|
||||
const cmd = `${getNpxCmd()} wrangler ${command} ${
|
||||
(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes(`--var`)
|
||||
? getVarArgs()
|
||||
: ""
|
||||
}`.trim();
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
if (environment.length > 0 && !command.includes(`--env`)) {
|
||||
command = command.concat(` --env ${environment}`);
|
||||
}
|
||||
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
const cmd = `${pkgManagerCmd.exec} wrangler ${command} ${
|
||||
(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes(`--var`)
|
||||
? getVarArgs()
|
||||
: ""
|
||||
}`.trim();
|
||||
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
|
||||
return await runProcess(cmd, {
|
||||
cwd: config["workingDirectory"],
|
||||
env: process.env,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await Promise.all(arrPromises).catch((result) => {
|
||||
result.stdout && info(result.stdout.toString());
|
||||
result.stderr && error(result.stderr.toString());
|
||||
setFailed(`🚨 Command failed`);
|
||||
});
|
||||
|
||||
endGroup();
|
||||
await Promise.all(arrPromises);
|
||||
} finally {
|
||||
endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(() => setFailed("🚨 Action failed"));
|
||||
main();
|
||||
|
||||
export {
|
||||
wranglerCommands,
|
||||
execCommands,
|
||||
uploadSecrets,
|
||||
authenticationSetup,
|
||||
execCommands,
|
||||
installWrangler,
|
||||
checkWorkingDirectory,
|
||||
getNpxCmd,
|
||||
semverCompare,
|
||||
uploadSecrets,
|
||||
wranglerCommands,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
checkWorkingDirectory,
|
||||
detectPackageManager,
|
||||
isValidPackageManager,
|
||||
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(
|
||||
'"Directory /does/not/exist does not exist."',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("detectPackageManager", () => {
|
||||
test("should return name of package manager for current workspace", () => {
|
||||
expect(detectPackageManager()).toBe("npm");
|
||||
});
|
||||
|
||||
test("should return npm if package-lock.json exists", () => {
|
||||
expect(detectPackageManager("test/npm")).toBe("npm");
|
||||
});
|
||||
|
||||
test("should return yarn if yarn.lock exists", () => {
|
||||
expect(detectPackageManager("test/yarn")).toBe("yarn");
|
||||
});
|
||||
|
||||
test("should return pnpm if pnpm-lock.yaml exists", () => {
|
||||
expect(detectPackageManager("test/pnpm")).toBe("pnpm");
|
||||
});
|
||||
|
||||
test("should return null if no package manager is detected", () => {
|
||||
expect(detectPackageManager("test/empty")).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
test("isValidPackageManager", () => {
|
||||
expect(isValidPackageManager("npm")).toBe(true);
|
||||
expect(isValidPackageManager("pnpm")).toBe(true);
|
||||
expect(isValidPackageManager("yarn")).toBe(true);
|
||||
|
||||
expect(isValidPackageManager("")).toBe(false);
|
||||
expect(isValidPackageManager("ppnpm")).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import * as path from "node:path";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
const version1Parts = version1.split(".");
|
||||
const version2Parts = version2.split(".");
|
||||
|
||||
for (const version1Part of version1Parts) {
|
||||
const version2Part = version2Parts.shift();
|
||||
|
||||
if (version1Part !== version2Part && version2Part) {
|
||||
return version1Part < version2Part ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkWorkingDirectory(workingDirectory = ".") {
|
||||
const normalizedPath = path.normalize(workingDirectory);
|
||||
if (existsSync(normalizedPath)) {
|
||||
return normalizedPath;
|
||||
} else {
|
||||
throw new Error(`Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
export type PackageManager = "npm" | "yarn" | "pnpm";
|
||||
|
||||
export function detectPackageManager(
|
||||
workingDirectory = ".",
|
||||
): PackageManager | 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";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isValidPackageManager(name: string): name is PackageManager {
|
||||
return name === "npm" || name === "yarn" || name === "pnpm";
|
||||
}
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "wrangler-action-detect-package-manager-test"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-environment-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-environment-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "wrangler-action-npm-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-npm-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "wrangler-action-npm-test"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1,26 @@
|
||||
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");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "wrangler-action-pnpm-test"
|
||||
}
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1,26 @@
|
||||
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");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "wrangler-action-yarn-test"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
||||
@@ -0,0 +1,4 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
+2
-2
@@ -9,12 +9,12 @@
|
||||
"isolatedModules": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"lib": ["ESNext"],
|
||||
"types": ["node", "@cloudflare/workers-types"]
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"],
|
||||
"include": ["src/index.ts"]
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user