├── entrypoint.sh
├── serverless.yml
├── .github
└── workflows
│ └── semgrep.yml
├── Dockerfile
├── LICENSE
└── README.md
/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ACTION_WORKSPACE=/root/worker-deploy
4 |
5 | if [ -e $GITHUB_WORKSPACE/serverless.yml ]
6 | then
7 | echo 'Custom serverless.yml found.'
8 | mv $GITHUB_WORKSPACE/serverless.yml $ACTION_WORKSPACE
9 | fi
10 |
11 | mv $GITHUB_WORKSPACE/*.js $ACTION_WORKSPACE
12 |
13 | cd $ACTION_WORKSPACE && sls deploy
--------------------------------------------------------------------------------
/serverless.yml:
--------------------------------------------------------------------------------
1 | service:
2 | name: deploy-worker-github-action
3 | config:
4 | accountId: ${env:CLOUDFLARE_ACCOUNT_ID}
5 | zoneId: ${env:CLOUDFLARE_ZONE_ID}
6 |
7 | provider:
8 | name: cloudflare
9 |
10 | plugins:
11 | - serverless-cloudflare-workers
12 |
13 | functions:
14 | worker-deploy:
15 | name: ${env:CLOUDFLARE_SCRIPT_NAME}
16 | script: ${env:CLOUDFLARE_SCRIPT_NAME}
--------------------------------------------------------------------------------
/.github/workflows/semgrep.yml:
--------------------------------------------------------------------------------
1 |
2 | on:
3 | pull_request: {}
4 | workflow_dispatch: {}
5 | push:
6 | branches:
7 | - main
8 | - master
9 | schedule:
10 | - cron: '0 0 * * *'
11 | name: Semgrep config
12 | jobs:
13 | semgrep:
14 | name: semgrep/ci
15 | runs-on: ubuntu-20.04
16 | env:
17 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
18 | SEMGREP_URL: https://cloudflare.semgrep.dev
19 | SEMGREP_APP_URL: https://cloudflare.semgrep.dev
20 | SEMGREP_VERSION_CHECK_URL: https://cloudflare.semgrep.dev/api/check-version
21 | container:
22 | image: returntocorp/semgrep
23 | steps:
24 | - uses: actions/checkout@v3
25 | - run: semgrep ci
26 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:10-slim
2 |
3 | LABEL "com.github.actions.name"="GitHub Action for Cloudflare Workers"
4 | LABEL "com.github.actions.description"="Deploy a Cloudflare Worker with the Serverless Framework"
5 | LABEL "com.github.actions.icon"="cloud"
6 | LABEL "com.github.actions.color"="orange"
7 |
8 | RUN yarn global add serverless &&\
9 | mkdir -p /$HOME/worker-deploy &&\
10 | cd $HOME/worker-deploy &&\
11 | serverless create --template cloudflare-workers &&\
12 | serverless plugin install --name serverless-cloudflare-workers &&\
13 | rm -f *.{yml,js}
14 |
15 | ADD serverless.yml /root/worker-deploy/serverless.yml
16 |
17 | ADD entrypoint.sh /entrypoint.sh
18 |
19 | ENTRYPOINT ["/entrypoint.sh"]
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Tom Brightbill
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Github Action to Deploy a Cloudflare Worker with the Serverless Framework
2 |
3 | If you are new to GitHub actions please see the official guide [here](https://help.github.com/articles/creating-a-workflow-with-github-actions/).
4 |
5 | To use this action you must provide a Worker script (i.e. `worker-script.js`) in your repo attached to this action as well as the appropriate environmental variables.
6 |
7 | File Structure
8 |
9 | Your repo must include the CF Worker script to be deployed and an optional `serverless.yml file`. If you do not include a `serverless.yml` file then the action will assume some smart defaults to deploy the worker based on the ENV variables you pass. Any included `serverless.yml` must exist in the root of your repo along with your worker script.
10 |
11 | Environmental Variables
12 |
13 | This action will expect the following environmental variables to be passed:
14 |
15 | ```
16 | CLOUDFLARE_AUTH_EMAIL #the email associated with the accout
17 | CLOUDFLARE_ACCOUNT_ID #your account ID
18 | CLOUDFLARE_ZONE_ID #your Cloudflare zone ID
19 | CLOUDFLARE_AUTH_KEY #your global API key; use the secret variable type available within GitHub Actions for this variable
20 | CLOUDFLARE_SCRIPT_NAME #the name of your worker-script.js file with .js ommited. NOTE: Worker names can contain lowercase letters, numbers, underscores, and dashes. They cannot start with dashes or contain uppercase letters.
21 | ```
22 | Using a Custom Serverless.yml
23 |
24 | The Serverless framework expects a ```serverless.yml``` file which allows us to use our existing Serverless integration to deploy Workers for this GitHub action. By default we provide one to deploy your worker. If you'd like to bring your own, please see [here]( https://developers.cloudflare.com/workers/deploying-workers/serverless/) for getting started.
25 |
26 | You may pass in other environmental variables to your custom ```serverless.yml``` if needed just make sure to refer to them by using ```${env:YOUR_VARIABLE}``` syntax.
27 |
28 | In a multiscript (Enterprise) environment the ```name``` will be seen in the UI where all your scripts are listed. In a single script environment the ```name``` will not be shown in the UI (as there is only one script).
29 |
30 | main.workflow
31 |
32 | The ```main.workflow``` output could look something like:
33 |
34 | ```
35 | workflow "Depkoy Worker {
36 | on = "push"
37 | resolves = ["cloudflare/serverless-action@master"]
38 | }
39 |
40 | action "Deploy Worker" {
41 | uses = "cloudflare/serverless-action@master"
42 | env = {
43 | CLOUDFLARE_ACCOUNT_ID = "ACCOUNT_ID"
44 | CLOUDFLARE_ZONE_ID = "ZONE_ID"
45 | CLOUDFLARE_AUTH_EMAIL = "hello@example.com"
46 | CLOUDFLARE_SCRIPT_NAME = "worker-script"
47 | }
48 | secrets = ["CLOUDFLARE_AUTH_KEY"]
49 | }
50 | ```
51 |
52 | License
53 |
54 | The Dockerfile and associated scripts and documentation in this project are released under the [MIT](https://github.com/tombrightbill/serverless-action/blob/master/LICENSE) License.
55 |
--------------------------------------------------------------------------------