forked from serverless-dns/serverless-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (112 loc) · 3.84 KB
/
cf.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: ⛅ CF
on:
# github.com/serverless-dns/blocklists/blob/6021f80f/.github/workflows/createUploadBlocklistFilter.yml#L4-L6
# schedule:
# at 7:53 on 3rd, 10th, 18th, 26th of every month
# - cron: '53 7 3,10,18,26 * *'
# docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
# docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch
# docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_dispatchinputs
workflow_dispatch:
# github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
# docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
inputs:
# docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs
environment:
description: 'wrangler env to deploy to'
required: true
default: 'dev'
type: choice
options:
- dev
- prod
- one
commit:
description: 'git tip commit to deploy'
default: 'main'
required: true
push:
# TODO: inputs.environment and inputs.commit
branches:
- "main"
tags:
- "v*"
paths-ignore:
- ".github/**"
- "!.github/workflows/cf.yml"
- ".env.example"
- ".eslintrc.cjs"
- ".prettierignore"
- "fly.toml"
- "README.md"
- "node.Dockerfile"
- "deno.Dockerfile"
- "import_map.json"
- ".vscode/*"
- ".husky/*"
- ".prettierrc.json"
- "LICENSE"
- "run"
repository_dispatch:
env:
GIT_REF: ${{ github.event.inputs.commit || github.ref }}
# default is 'dev' which is really empty/no env
WORKERS_ENV: ''
jobs:
deploy:
name: 🚀 Deploy worker
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: 🛒 Checkout
uses: actions/checkout@v3.3.0
with:
ref: ${{ env.GIT_REF }}
fetch-depth: 0
- name: 🛸 Env?
# 'dev' env deploys to default WORKERS_ENV, which is, '' (an empty string)
if: github.event.inputs.environment == 'prod' || github.event.inputs.environment == 'one'
run: |
echo "WORKERS_ENV=${WENV}" >> $GITHUB_ENV
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV
shell: bash
env:
WENV: ${{ github.event.inputs.environment }}
COMMIT_SHA: ${{ github.sha }}
- name: 🎱 Tag?
# docs.github.com/en/actions/learn-github-actions/contexts#github-context
if: github.ref_type == 'tag'
run: |
echo "WORKERS_ENV=${WENV}" >> $GITHUB_ENV
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV
shell: bash
env:
# tagged deploys always deploy to prod
WENV: 'prod'
COMMIT_SHA: ${{ github.sha }}
- name: 🌽 Cron?
if: github.event.schedule == '53 7 3,10,18,26 * *'
run: |
echo "WORKERS_ENV=${WENV}" >> $GITHUB_ENV
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_ENV
shell: bash
env:
# cron deploys always deploy to prod
WENV: 'prod'
COMMIT_SHA: ${{ github.sha }}
# npm (and node16) are installed by wrangler-action in a pre-job setup
- name: 🏗 Get dependencies
run: npm i
- name: 📚 Wrangler publish
# github.com/cloudflare/wrangler-action
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
# input overrides env-defaults, regardless
environment: ${{ env.WORKERS_ENV }}
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
GIT_COMMIT_ID: ${{ env.COMMIT_SHA }}
- name: 🎤 Notice
run: |
echo "::notice::Deployed to ${WORKERS_ENV} / ${GIT_REF} @ ${COMMIT_SHA}"