Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e9594b6880 | |||
| 051abafa82 | |||
| 599ff4dc4b | |||
| bdf9196cd6 |
@@ -10,36 +10,36 @@ Add `wrangler-action` to the workflow for your Workers application. The below ex
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish
|
||||
uses: signalnerve/wrangler-action@0.1.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
## 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:
|
||||
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`:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: signalnerve/wrangler-action@0.1.0
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
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:
|
||||
@@ -49,12 +49,106 @@ jobs:
|
||||
deploy:
|
||||
# ... previous configuration ...
|
||||
steps:
|
||||
uses: signalnerve/wrangler-action@0.1.0
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
# ... api key and email ...
|
||||
environment: "production"
|
||||
environment: 'production'
|
||||
```
|
||||
|
||||
## Use cases
|
||||
|
||||
### Deploying when commits are merged to master
|
||||
|
||||
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`:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
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).
|
||||
|
||||
### 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:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
schedule:
|
||||
- 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
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
repository_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
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).
|
||||
|
||||
## 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:
|
||||
@@ -75,12 +169,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Build site
|
||||
run: "npm run build"
|
||||
- name: Publish
|
||||
uses: signalnerve/wrangler-action@0.1.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CLOUDFLARE_API_KEY }}
|
||||
email: ${{ secrets.CLOUDFLARE_EMAIL }}
|
||||
- uses: actions/checkout@master
|
||||
- name: Build site
|
||||
run: 'npm run build'
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@1.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.apiKey }}
|
||||
email: ${{ secrets.email }}
|
||||
```
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
name: 'Cloudflare Workers Deploy'
|
||||
name: 'Deploy to Cloudflare Workers with Wrangler'
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
color: 'orange'
|
||||
description: 'Cloudflare Workers Deploy'
|
||||
description: 'Deploy your Cloudflare Workers applications and sites directly from GitHub, using Wrangler'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ export WRANGLER_HOME="/github/workspace"
|
||||
sanitize() {
|
||||
if [ -z "${1}" ]
|
||||
then
|
||||
>&2 echo "Unable to find ${2}. Did you set secrets.${2}?"
|
||||
>&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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user