Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -0,0 +1,91 @@
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
name: Lint
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Lint shell script
|
||||
uses: azohra/shell-linter@v0.3.0
|
||||
with:
|
||||
path: "entrypoint.sh"
|
||||
build-only:
|
||||
runs-on: ubuntu-latest
|
||||
name: Only build the app
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build app
|
||||
uses: ./
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
workingDirectory: "test"
|
||||
publish: false
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
preCommands: echo "*** pre commands ***"
|
||||
postCommands: |
|
||||
echo "*** post commands ***"
|
||||
wrangler build
|
||||
echo "******"
|
||||
env:
|
||||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish app
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish app
|
||||
uses: ./
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
environment: "production"
|
||||
workingDirectory: 'test'
|
||||
publish_legacy_credentials:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish app with legacy credentials
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish app
|
||||
uses: ./
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
environment: "production"
|
||||
workingDirectory: 'test'
|
||||
publish_hardcoded_wrangler_version:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish app with hardcoded Wrangler version
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish app
|
||||
uses: ./
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
environment: "production"
|
||||
wranglerVersion: '1.5.0'
|
||||
workingDirectory: 'test'
|
||||
publish_secrets:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish app with secrets
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish app
|
||||
uses: ./
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
environment: "production"
|
||||
workingDirectory: "test"
|
||||
secrets: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
preCommands: echo "*** pre command ***"
|
||||
postCommands: |
|
||||
echo "*** post commands ***"
|
||||
echo "******"
|
||||
env:
|
||||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
@@ -1,33 +0,0 @@
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Lint shell script
|
||||
uses: azohra/shell-linter@v0.1.0
|
||||
with:
|
||||
path: "entrypoint.sh"
|
||||
- name: Publish app with api token
|
||||
uses: signalnerve/wrangler-action@1.1.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
environment: "production"
|
||||
workingDirectory: 'test'
|
||||
- name: Publish app with legacy credentials
|
||||
uses: signalnerve/wrangler-action@1.1.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
environment: "production"
|
||||
workingDirectory: 'test'
|
||||
- name: Publish app with hardcoded Wrangler version
|
||||
uses: signalnerve/wrangler-action@1.1.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
environment: "production"
|
||||
wranglerVersion: '1.5.0'
|
||||
workingDirectory: 'test'
|
||||
@@ -0,0 +1,23 @@
|
||||
# 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: publish`.
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
FROM node:12
|
||||
FROM node:16
|
||||
ENV XDG_CONFIG_HOME /github/workspace
|
||||
ENV WRANGLER_HOME /github/workspace
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
# 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, Pages or modifying R2 easy to do.
|
||||
|
||||
[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 publish a Worker on a `git push` to the `main` branch:
|
||||
|
||||
```yaml
|
||||
name: Deploy
|
||||
@@ -12,16 +14,16 @@ name: Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -37,7 +39,7 @@ jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
@@ -49,7 +51,7 @@ jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CF_API_KEY }}
|
||||
email: ${{ secrets.CF_EMAIL }}
|
||||
@@ -57,25 +59,13 @@ jobs:
|
||||
|
||||
## Configuration
|
||||
|
||||
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 an `environment` in the `with` block of your workflow:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
environment: 'production'
|
||||
```
|
||||
|
||||
If you need to install a specific version of Wrangler to use for deployment, you can also pass the input `wranglerVersion` to install a specific version of Wrangler from NPM. This should be a [SemVer](https://semver.org/)-style version number, such as `1.6.0`:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
wranglerVersion: '1.6.0'
|
||||
@@ -87,41 +77,107 @@ Optionally, you can also pass a `workingDirectory` key to the action. This will
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
workingDirectory: 'subfoldername'
|
||||
```
|
||||
|
||||
[Worker secrets](https://developers.cloudflare.com/workers/tooling/wrangler/secrets/) can be optionally passed as a new line deliminated string of names in `secrets`. Each secret name must match an environment variable name specified in the `env` attribute. Creates or replaces the value for the Worker secret using the `wrangler secret put` command.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
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 `publish`) or `postCommands` (after `publish`). 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@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_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@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
command: whoami
|
||||
```
|
||||
|
||||
## 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
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_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 publish as a preview deployment:
|
||||
|
||||
```yaml
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
command: pages publish --project-name=example
|
||||
```
|
||||
|
||||
### 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:
|
||||
@@ -133,82 +189,64 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_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
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@1.1.0
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
command: publish --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:
|
||||
|
||||
```js
|
||||
const headers = {
|
||||
Accept: 'application/vnd.github.everest-preview+json',
|
||||
Authorization: 'Bearer $token',
|
||||
}
|
||||
|
||||
const body = JSON.stringify({ event_type: 'repository_dispatch' })
|
||||
|
||||
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)
|
||||
```
|
||||
|
||||
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).
|
||||
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.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
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:
|
||||
|
||||
### "I just started using Workers/Wrangler and I don't know what this is!"
|
||||
|
||||
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!
|
||||
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.
|
||||
|
||||
### "I'm trying to deploy my static site but it isn't working!"
|
||||
### "[ERROR] No account id found, quitting.."
|
||||
|
||||
To deploy static sites and frontend applications to Workers, check out the documentation for [Workers Sites](https://developers.cloudflare.com/workers/sites).
|
||||
|
||||
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:
|
||||
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.1.0
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
```
|
||||
+29
-8
@@ -1,21 +1,42 @@
|
||||
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 Workers and Pages projects from GitHub using Wrangler"
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
inputs:
|
||||
apiKey:
|
||||
description: "(Legacy) Your Cloudflare API Key"
|
||||
apiToken:
|
||||
description: "Your Cloudflare API Token"
|
||||
required: false
|
||||
email:
|
||||
description: "(Legacy) Your Cloudflare Email"
|
||||
required: false
|
||||
apiToken:
|
||||
description: "Your Cloudflare API Token"
|
||||
required: false
|
||||
accountId:
|
||||
description: "Your Cloudflare Account ID"
|
||||
required: false
|
||||
|
||||
environment:
|
||||
description: "The environment you'd like to publish 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 publish your Workers project"
|
||||
required: false
|
||||
secrets:
|
||||
description: "A new line deliminated string of environment variable names that should be configured as Worker secrets"
|
||||
required: false
|
||||
preCommands:
|
||||
description: "Commands to execute before publishing the Workers project"
|
||||
required: false
|
||||
postCommands:
|
||||
description: "Commands to execute after publishing the Workers project"
|
||||
required: false
|
||||
command:
|
||||
description: "The Wrangler command you wish to run. For example: \"publish\" - this will publish your Worker"
|
||||
required: false
|
||||
+107
-32
@@ -1,42 +1,92 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
export HOME="/github/workspace"
|
||||
export NVM_DIR="/github/workspace/nvm"
|
||||
export WRANGLER_HOME="/github/workspace"
|
||||
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
|
||||
|
||||
# Comments beginning with "shellcheck" use shellcheck, a shell script linter.
|
||||
# The below comments ignore shellcheck linting on the instructions provided
|
||||
# by NVM.
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
# shellcheck source=/dev/null
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||
|
||||
mkdir -p "$HOME/.wrangler"
|
||||
chmod -R 770 "$HOME/.wrangler"
|
||||
|
||||
export API_CREDENTIALS=""
|
||||
|
||||
# Used to execute any specified pre and post commands
|
||||
execute_commands() {
|
||||
echo "$ Running: $1"
|
||||
COMMANDS=$1
|
||||
while IFS= read -r COMMAND; do
|
||||
CHUNKS=()
|
||||
|
||||
for CHUNK in $COMMAND; do
|
||||
CHUNKS+=("$CHUNK")
|
||||
done
|
||||
|
||||
eval "${CHUNKS[@]}"
|
||||
|
||||
CHUNKS=()
|
||||
done <<< "$COMMANDS"
|
||||
}
|
||||
|
||||
secret_not_found() {
|
||||
echo "::error::Specified secret \"$1\" not found in environment variables."
|
||||
exit 1
|
||||
}
|
||||
|
||||
WRANGLER_VERSION=2
|
||||
|
||||
# If no Wrangler version is specified install v2.
|
||||
if [ -z "$INPUT_WRANGLERVERSION" ]; then
|
||||
npm i -g wrangler
|
||||
|
||||
# If Wrangler version starts with 1 then install wrangler v1
|
||||
elif [[ "$INPUT_WRANGLERVERSION" == 1* ]]; then
|
||||
npm i -g "@cloudflare/wrangler@$INPUT_WRANGLERVERSION"
|
||||
WRANGLER_VERSION=1
|
||||
|
||||
# Else install Wrangler 2
|
||||
else
|
||||
npm i -g "wrangler@$INPUT_WRANGLERVERSION"
|
||||
WRANGLER_VERSION=2
|
||||
fi
|
||||
|
||||
# If an API token is detected as input
|
||||
if [ -n "$INPUT_APITOKEN" ]
|
||||
then
|
||||
export CF_API_TOKEN="$INPUT_APITOKEN"
|
||||
if [ -n "$INPUT_APITOKEN" ]; then
|
||||
|
||||
# Wrangler v1 uses CF_API_TOKEN but v2 uses CLOUDFLARE_API_TOKEN
|
||||
if [ $WRANGLER_VERSION == 1 ]; then
|
||||
export CF_API_TOKEN="$INPUT_APITOKEN"
|
||||
else
|
||||
export CLOUDFLARE_API_TOKEN="$INPUT_APITOKEN"
|
||||
fi
|
||||
|
||||
export API_CREDENTIALS="API Token"
|
||||
fi
|
||||
|
||||
# If an API key and email are detected as input
|
||||
if [ -n "$INPUT_APIKEY" ] && [ -n "$INPUT_EMAIL" ]
|
||||
then
|
||||
export CF_EMAIL="$INPUT_EMAIL"
|
||||
export CF_API_KEY="$INPUT_APIKEY"
|
||||
if [ -n "$INPUT_APIKEY" ] && [ -n "$INPUT_EMAIL" ]; then
|
||||
|
||||
# Wrangler v1 uses CF_ but v2 uses CLOUDFLARE_
|
||||
if [ $WRANGLER_VERSION == 1 ]; then
|
||||
export CF_EMAIL="$INPUT_EMAIL"
|
||||
export CF_API_KEY="$INPUT_APIKEY"
|
||||
else
|
||||
echo "::error::Wrangler v2 does not support using the API Key. You should instead use an API token."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export API_CREDENTIALS="Email and API Key"
|
||||
fi
|
||||
|
||||
if [ -n "$INPUT_ACCOUNTID" ]; then
|
||||
|
||||
if [ $WRANGLER_VERSION == 1 ]; then
|
||||
export CF_ACCOUNT_ID="$INPUT_ACCOUNTID"
|
||||
else
|
||||
export CLOUDFLARE_ACCOUNT_ID="$INPUT_ACCOUNTID"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "$INPUT_APIKEY" ] && [ -z "$INPUT_EMAIL" ]
|
||||
then
|
||||
echo "Provided an API key without an email for authentication. Please pass in 'apiKey' and 'email' to the action."
|
||||
@@ -56,26 +106,51 @@ else
|
||||
echo "Using $API_CREDENTIALS authentication"
|
||||
fi
|
||||
|
||||
# If a Wrangler version is detected as input
|
||||
if [ -z "$INPUT_WRANGLERVERSION" ]
|
||||
then
|
||||
npm i @cloudflare/wrangler -g
|
||||
else
|
||||
npm i "@cloudflare/wrangler@$INPUT_WRANGLERVERSION" -g
|
||||
fi
|
||||
|
||||
# If a working directory is detected as input
|
||||
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
||||
then
|
||||
cd "$INPUT_WORKINGDIRECTORY"
|
||||
fi
|
||||
|
||||
# If an environment is detected as input
|
||||
if [ -z "$INPUT_ENVIRONMENT" ]
|
||||
# If precommands is detected as input
|
||||
if [ -n "$INPUT_PRECOMMANDS" ]
|
||||
then
|
||||
wrangler publish
|
||||
execute_commands "$INPUT_PRECOMMANDS"
|
||||
fi
|
||||
|
||||
# If we have secrets, set them
|
||||
for SECRET in $INPUT_SECRETS; do
|
||||
VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
|
||||
|
||||
if [ -z "$INPUT_ENVIRONMENT" ]; then
|
||||
echo "$VALUE" | wrangler secret put "$SECRET"
|
||||
else
|
||||
echo "$VALUE" | wrangler secret put "$SECRET" --env "$INPUT_ENVIRONMENT"
|
||||
fi
|
||||
done
|
||||
|
||||
# If there's no input command then default to publish otherwise run it
|
||||
if [ -z "$INPUT_COMMAND" ]; then
|
||||
echo "::notice:: No command was provided, defaulting to 'publish'"
|
||||
|
||||
if [ -z "$INPUT_ENVIRONMENT" ]; then
|
||||
wrangler publish
|
||||
else
|
||||
wrangler publish --env "$INPUT_ENVIRONMENT"
|
||||
fi
|
||||
|
||||
else
|
||||
wrangler publish -e "$INPUT_ENVIRONMENT"
|
||||
if [ -n "$INPUT_ENVIRONMENT" ]; then
|
||||
echo "::notice::Since you have specified an environment you need to make sure to pass in '--env $INPUT_ENVIRONMENT' to your command."
|
||||
fi
|
||||
|
||||
execute_commands "wrangler $INPUT_COMMAND"
|
||||
fi
|
||||
|
||||
# If postcommands is detected as input
|
||||
if [ -n "$INPUT_POSTCOMMANDS" ]
|
||||
then
|
||||
execute_commands "$INPUT_POSTCOMMANDS"
|
||||
fi
|
||||
|
||||
# If a working directory is detected as input, revert to the
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
|
||||
* The DEBUG flag will do two things that help during development:
|
||||
* 1. we will skip caching on the edge, which makes it easier to
|
||||
* debug.
|
||||
* 2. we will return an error message on exception in your Response rather
|
||||
* 2. we will return an error message on exception in your response rather
|
||||
* than the default 404.html page.
|
||||
*/
|
||||
const DEBUG = false
|
||||
@@ -34,6 +34,14 @@ async function handleEvent(event) {
|
||||
*/
|
||||
// options.mapRequestToAsset = handlePrefix(/^\/docs/)
|
||||
|
||||
// Path to test secrets passed through Wrangler Action. Create SECRET1 and SECRET2 secrets
|
||||
// in the Action repo to something innocuous like "Hello" and "World!".
|
||||
if (url.pathname === "/secret") {
|
||||
let sec1 = (typeof SECRET1 !== 'undefined') ? SECRET1 : ""
|
||||
let sec2 = (typeof SECRET2 !== 'undefined') ? SECRET2 : ""
|
||||
return new Response(`${sec1} ${sec2}`)
|
||||
}
|
||||
|
||||
try {
|
||||
if (DEBUG) {
|
||||
// customize caching
|
||||
|
||||
Reference in New Issue
Block a user