Compare commits

...

17 Commits

Author SHA1 Message Date
Adam Janiš 6f62debcf8 Merge pull request #56 from ItalyPaleAle/patch-1
Update Node.js to 16
2022-03-15 12:30:29 +01:00
Kristian Freeman 006366c1ae Merge pull request #46 from whoabuddy/patch-1
Update README.md release version
2021-07-19 10:19:25 -05:00
Alessandro (Ale) Segala 95ac136231 Update Node.js to 16 2021-05-12 22:21:56 -07:00
Jason Schrader a33b48c9fe Update README.md release version
This change updates the release version for cloudflare/wrangler-action in all examples from `1.2.0` to `1.3.0`.

It also corrects a typo on the last example changing `TOML` to `YAML` based on the code below it.
2020-11-13 07:56:23 -07:00
Kristian Freeman 60c377d0bf Merge pull request #42 from Indigenuity/master
Suggest workflow_dispatch for manual deploys
2020-09-16 12:46:23 -05:00
Kristian Freeman 39c3d279a1 Merge pull request #43 from chromy/patch-1
Update Readme to reference v1.3.0
2020-09-16 12:45:29 -05:00
Hector Dearman 8df5ab90b3 Update Readme to reference v1.3.0
The readme mentions v1.2.0 but some of the commands (for example publish)
are only present in v1.3.0. Update readme to use v1.3.0 instead.
2020-09-11 22:05:51 +01:00
JD Kemsley f4e53e2753 Suggest workflow_dispatch for manual deploys 2020-09-11 12:53:43 -05:00
Kristian Freeman 3424d15af2 Merge pull request #35 from bradyjoslin/pre-post-commands
Add support for running pre and post commands
2020-08-21 11:31:16 -05:00
Brady Joslin 212d5a5125 eval the input command 2020-08-13 00:12:47 -05:00
Joslin, Brady W (Brady) bc7b76075d update explanation of publish option 2020-08-11 22:53:34 -05:00
Joslin, Brady W (Brady) 176cda2c0e add ability to skip publish 2020-08-11 22:46:42 -05:00
Joslin, Brady W (Brady) 93b9408aec pre-post-commands 2020-08-07 16:36:37 -05:00
Avery Harnish 6531840e6e Merge pull request #32 from jbampton/fix-word-case
Fix word case
2020-07-02 10:07:55 -05:00
John Bampton f871e6782e Fix word case 2020-07-02 17:17:05 +10:00
Kristian Freeman aab79315b4 Merge pull request #30 from bradyjoslin/patch-1
update secrets example in readme
2020-06-29 09:29:28 -05:00
Brady Joslin c511ea2eb5 Update README.md 2020-06-27 10:38:37 -05:00
6 changed files with 137 additions and 57 deletions
+27 -1
View File
@@ -10,6 +10,28 @@ jobs:
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
@@ -60,6 +82,10 @@ jobs:
secrets: |
SECRET1
SECRET2
preCommands: echo "*** pre command ***"
postCommands: |
echo "*** post commands ***"
echo "******"
env:
SECRET1: ${{ secrets.SECRET1 }}
SECRET2: ${{ secrets.SECRET2 }}
SECRET2: ${{ secrets.SECRET2 }}
+1 -1
View File
@@ -1,4 +1,4 @@
FROM node:12
FROM node:16
ENV XDG_CONFIG_HOME /github/workspace
ENV WRANGLER_HOME /github/workspace
COPY entrypoint.sh /entrypoint.sh
+50 -37
View File
@@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Publish
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
```
@@ -37,7 +37,7 @@ jobs:
deploy:
name: Deploy
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
```
@@ -49,7 +49,7 @@ jobs:
deploy:
name: Deploy
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiKey: ${{ secrets.CF_API_KEY }}
email: ${{ secrets.CF_EMAIL }}
@@ -63,7 +63,7 @@ If you're using Wrangler's [environments](https://developers.cloudflare.com/work
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
environment: 'production'
@@ -75,7 +75,7 @@ If you need to install a specific version of Wrangler to use for deployment, you
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
wranglerVersion: '1.6.0'
@@ -87,7 +87,7 @@ Optionally, you can also pass a `workingDirectory` key to the action. This will
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: 'subfoldername'
@@ -99,10 +99,9 @@ jobs:
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: 'subfoldername'
secrets: |
SECRET1
SECRET2
@@ -111,6 +110,35 @@ jobs:
SECRET2: ${{ secrets.SECRET2 }}
```
If you need to run additional shell commands before or after `wrangler publish`, you can specify them as input to `preCommands` (before publish) or `postCommands` (after publish). These can include additional `wrangler` commands (i.e. `build`, `kv:key put`) or any other commands available inside the `wrangler-action` context.
```yaml
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.3.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 "******"
```
Set the optional `publish` input to false to skip publishing your Worker project and secrets. Useful in conjunction with pre and post commands. For example, if you only wanted to run `wrangler build` against your project:
```yaml
jobs:
deploy:
steps:
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
publish: false
preCommands: wrangler build
```
## Use cases
### Deploying when commits are merged to master
@@ -130,7 +158,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Publish
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
```
@@ -153,7 +181,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Publish app
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
```
@@ -162,12 +190,16 @@ If you need help defining the correct cron syntax, check out [crontab.guru](http
### Deploying on a "dispatched" event
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'll 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
@@ -175,32 +207,13 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Publish app
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
environment: ${{ 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, check out [the docs](https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event) for making API calls
## Troubleshooting
@@ -214,7 +227,7 @@ No problem! Check out the [Quick Start guide](https://developers.cloudflare.com/
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:
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 YAML might resemble the following:
```yaml
jobs:
@@ -226,7 +239,7 @@ jobs:
- name: Build site
run: 'npm run build'
- name: Publish
uses: cloudflare/wrangler-action@1.2.0
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
```
+9
View File
@@ -22,3 +22,12 @@ inputs:
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
publish:
description: "Set to false to skip publishing your Worker project and secrets. Defaults to true."
required: false
+49 -17
View File
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e
@@ -10,6 +10,27 @@ chmod -R 770 "$HOME/.wrangler"
export API_CREDENTIALS=""
# Used to execute any specified pre and post commands
execute_commands() {
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
}
# If an API token is detected as input
if [ -n "$INPUT_APITOKEN" ]
then
@@ -58,28 +79,39 @@ then
cd "$INPUT_WORKINGDIRECTORY"
fi
secret_not_found() {
echo "::error::Specified secret \"$1\" not found in environment variables."
exit 1
}
# If precommands is detected as input
if [ -n "$INPUT_PRECOMMANDS" ]
then
execute_commands "$INPUT_PRECOMMANDS"
fi
# If an environment is detected as input, for each secret specified get the value of
# the matching named environment variable then configure using wrangler secret put.
if [ -z "$INPUT_ENVIRONMENT" ]
# Skip if publish is set to false.
if [ "$INPUT_PUBLISH" != "false" ]
then
wrangler publish
if [ -z "$INPUT_ENVIRONMENT" ]
then
wrangler publish
for SECRET in $INPUT_SECRETS; do
VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
echo "$VALUE" | wrangler secret put "$SECRET"
done
else
wrangler publish -e "$INPUT_ENVIRONMENT"
for SECRET in $INPUT_SECRETS; do
VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
echo "$VALUE" | wrangler secret put "$SECRET"
done
else
wrangler publish -e "$INPUT_ENVIRONMENT"
for SECRET in $INPUT_SECRETS; do
VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
echo "$VALUE" | wrangler secret put "$SECRET" --env "$INPUT_ENVIRONMENT"
done
for SECRET in $INPUT_SECRETS; do
VALUE=$(printenv "$SECRET") || secret_not_found "$SECRET"
echo "$VALUE" | wrangler secret put "$SECRET" --env "$INPUT_ENVIRONMENT"
done
fi
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
+1 -1
View File
@@ -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