Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 80501a7b4d | |||
| 3252711404 | |||
| 2faabf36a2 | |||
| b734d85d74 | |||
| 8ca2ff1612 | |||
| 7d08a8657e | |||
| e193627f19 | |||
| 55b80c5f62 | |||
| f61dc4d5a9 | |||
| 58f274b9f7 | |||
| ef7686b259 | |||
| d63b9dc486 | |||
| 88ccce72e0 | |||
| 554eea134a | |||
| a584cc5606 | |||
| 0f5076c3e7 | |||
| c7d1bd35bf | |||
| 3c728e1d5d | |||
| a333df3c9e | |||
| bb0133dcfc | |||
| 88466ea5ae | |||
| 74433eb31e | |||
| 559dd40fe6 | |||
| 9930080b73 | |||
| 43bbbb16ab | |||
| 598c6b4043 | |||
| 0c094f5307 | |||
| 6ea2e616f2 | |||
| 1b4a61cee9 | |||
| 8e3876a0c9 | |||
| 8fab856f8d | |||
| ce1ea4e7c3 | |||
| e420d29d0a | |||
| 311d514d9d | |||
| d05a65f82b | |||
| c9da75b82e | |||
| 29cef5effc | |||
| ee60b7bd5e | |||
| 0ab3500d54 | |||
| dfa59a861f | |||
| 342e6243b7 | |||
| d6590f86f4 | |||
| 97e54f3396 | |||
| f85e1acfa7 | |||
| e18e1dfc82 | |||
| 20ea506049 | |||
| 45c57ae013 | |||
| a5fd4fdd34 | |||
| 002bb083fa | |||
| 42c609b2d6 | |||
| c8f756bccf | |||
| 81fb6a9681 | |||
| 6231e31709 | |||
| 0c419bee6c | |||
| 74a9b9885f | |||
| 3dd57ff2bb | |||
| edb2a58814 |
@@ -1,91 +0,0 @@
|
||||
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,23 +0,0 @@
|
||||
# 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`.
|
||||
@@ -1,7 +0,0 @@
|
||||
FROM node:16
|
||||
ENV XDG_CONFIG_HOME /github/workspace
|
||||
ENV WRANGLER_HOME /github/workspace
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
Copyright (c) 2019 Kristian Freeman <kristian@kristianfreeman.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,252 +0,0 @@
|
||||
# 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.
|
||||
|
||||
[Refer to Changelog for more information](CHANGELOG.md).
|
||||
|
||||
## Usage
|
||||
|
||||
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
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
You'll need to configure Wrangler using GitHub's Secrets feature - go to "Settings -> Secrets" and add your Cloudflare API token (for help finding this, see the [Workers documentation](https://developers.cloudflare.com/workers/quickstart/#api-token)). Your API token is encrypted by GitHub, and the action won't print it into logs, so it should be safe!
|
||||
|
||||
With your API token set as a secret for your repository, pass it to the action in the `with` block of your workflow. Below, I've set the secret name to `CF_API_TOKEN`:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
```
|
||||
|
||||
`wrangler-action` also supports using your [global API key and email](https://developers.cloudflare.com/workers/quickstart/#global-api-key) as an authentication method, although API tokens are preferred. Pass in `apiKey` and `email` to the GitHub Action to use this method:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
steps:
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiKey: ${{ secrets.CF_API_KEY }}
|
||||
email: ${{ secrets.CF_EMAIL }}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
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@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
wranglerVersion: '1.6.0'
|
||||
```
|
||||
|
||||
Optionally, you can also pass a `workingDirectory` key to the action. This will allow you to specify a subdirectory of the repo to run the Wrangler command from.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
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
|
||||
|
||||
### 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 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:
|
||||
- main
|
||||
|
||||
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 }}
|
||||
```
|
||||
|
||||
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 would like to deploy your Workers application on a recurring basis – for example, every hour, or daily – the `schedule` trigger allows you to use cron syntax to define a workflow schedule. The below example will deploy at the beginning of every hour:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 * * * *'
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish app
|
||||
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.
|
||||
|
||||
### Manually triggering a deployment
|
||||
|
||||
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:
|
||||
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@v3
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
command: publish --env ${{ github.event.inputs.environment }}
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
### "I just started using Workers/Wrangler and I don't know what this is!"
|
||||
|
||||
Refer to the [Quick Start guide](https://developers.cloudflare.com/workers/quickstart) to get started. Once you have a Workers application, you may want to set it up to automatically deploy from GitHub whenever you change your project.
|
||||
|
||||
### "[ERROR] No account id found, quitting.."
|
||||
|
||||
You will need to add `account_id = ""` in your `wrangler.toml` file or set `accountId` in this GitHub Action.
|
||||
|
||||
```yaml
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Publish app
|
||||
uses: cloudflare/wrangler-action@2.0.0
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
```
|
||||
+13
-16
@@ -2,17 +2,11 @@ name: "Deploy to Cloudflare Workers with Wrangler"
|
||||
branding:
|
||||
icon: "upload-cloud"
|
||||
color: "orange"
|
||||
description: "Deploy your Cloudflare Workers and Pages projects from GitHub using Wrangler"
|
||||
description: "Deploy your Cloudflare projects from GitHub using Wrangler"
|
||||
runs:
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
using: "node16"
|
||||
main: "dist/index.mjs"
|
||||
inputs:
|
||||
apiKey:
|
||||
description: "(Legacy) Your Cloudflare API Key"
|
||||
required: false
|
||||
email:
|
||||
description: "(Legacy) Your Cloudflare Email"
|
||||
required: false
|
||||
apiToken:
|
||||
description: "Your Cloudflare API Token"
|
||||
required: false
|
||||
@@ -21,22 +15,25 @@ inputs:
|
||||
required: false
|
||||
|
||||
environment:
|
||||
description: "The environment you'd like to publish your Workers project to - must be defined in wrangler.toml"
|
||||
description: "The environment you'd like to deploy your Workers project to - must be defined in wrangler.toml"
|
||||
workingDirectory:
|
||||
description: "The relative path which Wrangler commands should be run from"
|
||||
required: false
|
||||
wranglerVersion:
|
||||
description: "The version of Wrangler you'd like to use to publish your Workers project"
|
||||
description: "The version of Wrangler you'd like to use to deploy your Workers project"
|
||||
required: false
|
||||
secrets:
|
||||
description: "A new line deliminated string of environment variable names that should be configured as Worker secrets"
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker as Secrets and must match the names of environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
preCommands:
|
||||
description: "Commands to execute before publishing the Workers project"
|
||||
description: "Commands to execute before deploying the Workers project"
|
||||
required: false
|
||||
postCommands:
|
||||
description: "Commands to execute after publishing the Workers project"
|
||||
description: "Commands to execute after deploying the Workers project"
|
||||
required: false
|
||||
command:
|
||||
description: "The Wrangler command you wish to run. For example: \"publish\" - this will publish your Worker"
|
||||
required: false
|
||||
description: 'The Wrangler command (along with any arguments) you wish to run. Multiple Wrangler commands can be run by separating each command with a newline. Defaults to `"deploy"`.'
|
||||
required: false
|
||||
vars:
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
|
||||
Vendored
+3070
File diff suppressed because it is too large
Load Diff
-161
@@ -1,161 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
export HOME="/github/workspace"
|
||||
export WRANGLER_HOME="/github/workspace"
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
# 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."
|
||||
fi
|
||||
|
||||
if [ -z "$INPUT_APIKEY" ] && [ -n "$INPUT_EMAIL" ]
|
||||
then
|
||||
echo "Provided an email without an API key for authentication. Please pass in 'apiKey' and 'email' to the action."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$API_CREDENTIALS" ]
|
||||
then
|
||||
>&2 echo "Unable to find authentication details. Please pass in an 'apiToken' as an input to the action, or a legacy 'apiKey' and 'email'."
|
||||
exit 1
|
||||
else
|
||||
echo "Using $API_CREDENTIALS authentication"
|
||||
fi
|
||||
|
||||
# If a working directory is detected as input
|
||||
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
||||
then
|
||||
cd "$INPUT_WORKINGDIRECTORY"
|
||||
fi
|
||||
|
||||
# If precommands is detected as input
|
||||
if [ -n "$INPUT_PRECOMMANDS" ]
|
||||
then
|
||||
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
|
||||
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
|
||||
# original directory before continuing with the workflow
|
||||
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
||||
then
|
||||
cd $HOME
|
||||
fi
|
||||
@@ -1 +0,0 @@
|
||||
dist
|
||||
@@ -1,6 +0,0 @@
|
||||
<h1>My Static Site Test</h1>
|
||||
<p>This is the content of my site</p>
|
||||
|
||||
<footer>
|
||||
And this is my footer
|
||||
</footer>
|
||||
@@ -1,88 +0,0 @@
|
||||
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
|
||||
* than the default 404.html page.
|
||||
*/
|
||||
const DEBUG = false
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
try {
|
||||
event.respondWith(handleEvent(event))
|
||||
} catch (e) {
|
||||
if (DEBUG) {
|
||||
return event.respondWith(
|
||||
new Response(e.message || e.toString(), {
|
||||
status: 500,
|
||||
}),
|
||||
)
|
||||
}
|
||||
event.respondWith(new Response('Internal Error', { status: 500 }))
|
||||
}
|
||||
})
|
||||
|
||||
async function handleEvent(event) {
|
||||
const url = new URL(event.request.url)
|
||||
let options = {}
|
||||
|
||||
/**
|
||||
* You can add custom logic to how we fetch your assets
|
||||
* by configuring the function `mapRequestToAsset`
|
||||
*/
|
||||
// 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
|
||||
options.cacheControl = {
|
||||
bypassCache: true,
|
||||
}
|
||||
}
|
||||
return await getAssetFromKV(event, options)
|
||||
} catch (e) {
|
||||
// if an error is thrown try to serve the asset at 404.html
|
||||
if (!DEBUG) {
|
||||
try {
|
||||
let notFoundResponse = await getAssetFromKV(event, {
|
||||
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
|
||||
})
|
||||
|
||||
return new Response(notFoundResponse.body, { ...notFoundResponse, status: 404 })
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return new Response(e.message || e.toString(), { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Here's one example of how to modify a request to
|
||||
* remove a specific prefix, in this case `/docs` from
|
||||
* the url. This can be useful if you are deploying to a
|
||||
* route on a zone, or if you only want your static content
|
||||
* to exist at a specific path.
|
||||
*/
|
||||
function handlePrefix(prefix) {
|
||||
return request => {
|
||||
// compute the default (e.g. / -> index.html)
|
||||
let defaultAssetKey = mapRequestToAsset(request)
|
||||
let url = new URL(defaultAssetKey.url)
|
||||
|
||||
// strip the prefix from the path for lookup
|
||||
url.pathname = url.pathname.replace(prefix, '/')
|
||||
|
||||
// inherit all other props from the default request
|
||||
return new Request(url.toString(), defaultAssetKey)
|
||||
}
|
||||
}
|
||||
Generated
-21
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "worker",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@cloudflare/kv-asset-handler": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.0.5.tgz",
|
||||
"integrity": "sha512-7yLMAUZD1XQNKzmktYCcUUPB+wXmQENv1MMi8QEMs0rzL01e0XEyCUUDauRXHzxi7dBbSUGA5RS23h890ncKog==",
|
||||
"requires": {
|
||||
"mime": "^2.4.4"
|
||||
}
|
||||
},
|
||||
"mime": {
|
||||
"version": "2.4.4",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz",
|
||||
"integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "worker",
|
||||
"version": "1.0.0",
|
||||
"description": "A template for kick starting a Cloudflare Workers project",
|
||||
"main": "index.js",
|
||||
"author": "Ashley Lewis <ashleymichal@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cloudflare/kv-asset-handler": "^0.0.5"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
name = "static-test"
|
||||
type = "webpack"
|
||||
workers_dev = true
|
||||
account_id = "dc56444c4c955a1653106ccf997c1067"
|
||||
|
||||
[env.production]
|
||||
name = "static-test-prod"
|
||||
|
||||
[site]
|
||||
bucket = "./public"
|
||||
entry-point = "workers-site"
|
||||
Reference in New Issue
Block a user