.github/workflows/deploy-worker.yml #96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
inputs: | |
dispatchNamespace: | |
description: 'Cloudflare Workers for Platforms dispatch namespace' | |
required: true | |
appId: | |
description: 'Worker App ID' | |
required: true | |
repo: | |
description: 'GitHub repository name' | |
required: true | |
commit: | |
description: 'Git commit hash' | |
required: true | |
directory: | |
description: 'Directory to deploy' | |
required: false | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: ${{github.event.inputs.appId}} | |
run: echo run identifier ${{ github.run_id }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.event.inputs.repo }} | |
ref: ${{ github.event.inputs.commit }} | |
- name: Check for pnpm-lock.yaml | |
id: check_pnpm_lock | |
run: | | |
directory=${{ inputs.directory }} | |
file_path="${directory:+${directory}/}pnpm-lock.yaml" | |
if [ -f "$file_path" ]; then | |
echo "PNPM lock file found" | |
echo "::set-output name=setup_pnpm::true" | |
fi | |
- name: Setup Node.js | |
if: ${{ steps.check_pnpm_lock.outputs.setup_pnpm == 'true' }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Setup PNPM | |
if: ${{ steps.check_pnpm_lock.outputs.setup_pnpm == 'true' }} | |
uses: pnpm/action-setup@v4 | |
- name: Pull go-toml Docker image | |
run: docker pull ghcr.io/pelletier/go-toml:v2 | |
- name: Sanitize wrangler.toml | |
working-directory: ${{ github.event.inputs.directory }} | |
run: | | |
mv wrangler.toml wrangler.toml.orig | |
docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml.orig | \ | |
jq 'del(.build, .d1_databases)' | \ | |
docker run -i ghcr.io/pelletier/go-toml:v2 jsontoml > wrangler.toml | |
- name: Deploy Worker | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
wranglerVersion: "3.64.0" | |
workingDirectory: ${{ github.event.inputs.directory }} | |
command: deploy --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} |