Skip to content

deploy_to_cf_workers #1

deploy_to_cf_workers

deploy_to_cf_workers #1

Workflow file for this run

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 }}
WRANGLER_VER: '3.56.0'
# 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/[email protected]
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 }}
wranglerVersion: ${{ env.WRANGLER_VER }}
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}"