mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-21 17:43:23 +01:00
pre-post-commands
This commit is contained in:
parent
6531840e6e
commit
93b9408aec
4 changed files with 62 additions and 7 deletions
7
.github/workflows/deploy.yml
vendored
7
.github/workflows/deploy.yml
vendored
|
@ -60,6 +60,11 @@ jobs:
|
||||||
secrets: |
|
secrets: |
|
||||||
SECRET1
|
SECRET1
|
||||||
SECRET2
|
SECRET2
|
||||||
|
preCommands: echo "*** pre command ***"
|
||||||
|
postCommands: |
|
||||||
|
echo "*** post commands ***"
|
||||||
|
wrangler build
|
||||||
|
echo "******"
|
||||||
env:
|
env:
|
||||||
SECRET1: ${{ secrets.SECRET1 }}
|
SECRET1: ${{ secrets.SECRET1 }}
|
||||||
SECRET2: ${{ secrets.SECRET2 }}
|
SECRET2: ${{ secrets.SECRET2 }}
|
18
README.md
18
README.md
|
@ -110,6 +110,22 @@ jobs:
|
||||||
SECRET2: ${{ secrets.SECRET2 }}
|
SECRET2: ${{ secrets.SECRET2 }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you need to run additional shell commands before or after `wrangler publish`, you can specify them as input to `preCommands` (before publish) or `postCommands` (after publish). These can include additional `wrangler` commands (i.e. `build`, `kv:key put`) or any other commands available inside the `wrangler-action` context.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
steps:
|
||||||
|
uses: cloudflare/wrangler-action@1.2.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 "******"
|
||||||
|
```
|
||||||
|
|
||||||
## Use cases
|
## Use cases
|
||||||
|
|
||||||
### Deploying when commits are merged to master
|
### Deploying when commits are merged to master
|
||||||
|
@ -228,4 +244,4 @@ jobs:
|
||||||
uses: cloudflare/wrangler-action@1.2.0
|
uses: cloudflare/wrangler-action@1.2.0
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||||
```
|
```
|
|
@ -22,3 +22,9 @@ inputs:
|
||||||
secrets:
|
secrets:
|
||||||
description: "A new line deliminated string of environment variable names that should be configured as Worker secrets"
|
description: "A new line deliminated string of environment variable names that should be configured as Worker secrets"
|
||||||
required: false
|
required: false
|
||||||
|
preCommands:
|
||||||
|
description: "Commands to execute before publishing the Workers project"
|
||||||
|
required: false
|
||||||
|
postCommands:
|
||||||
|
description: "Commands to execute after publishing the Workers project"
|
||||||
|
required: false
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
@ -10,6 +10,27 @@ chmod -R 770 "$HOME/.wrangler"
|
||||||
|
|
||||||
export API_CREDENTIALS=""
|
export API_CREDENTIALS=""
|
||||||
|
|
||||||
|
# Used to execute any specified pre and post commands
|
||||||
|
execute_commands() {
|
||||||
|
COMMANDS=$1
|
||||||
|
while IFS= read -r COMMAND; do
|
||||||
|
CHUNKS=()
|
||||||
|
|
||||||
|
for CHUNK in $COMMAND; do
|
||||||
|
CHUNKS+=("$CHUNK")
|
||||||
|
done
|
||||||
|
|
||||||
|
"${CHUNKS[@]}"
|
||||||
|
|
||||||
|
CHUNKS=()
|
||||||
|
done <<< "$COMMANDS"
|
||||||
|
}
|
||||||
|
|
||||||
|
secret_not_found() {
|
||||||
|
echo "::error::Specified secret \"$1\" not found in environment variables."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# If an API token is detected as input
|
# If an API token is detected as input
|
||||||
if [ -n "$INPUT_APITOKEN" ]
|
if [ -n "$INPUT_APITOKEN" ]
|
||||||
then
|
then
|
||||||
|
@ -58,10 +79,11 @@ then
|
||||||
cd "$INPUT_WORKINGDIRECTORY"
|
cd "$INPUT_WORKINGDIRECTORY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
secret_not_found() {
|
# If precommands is detected as input
|
||||||
echo "::error::Specified secret \"$1\" not found in environment variables."
|
if [ -n "$INPUT_PRECOMMANDS" ]
|
||||||
exit 1
|
then
|
||||||
}
|
execute_commands "$INPUT_PRECOMMANDS"
|
||||||
|
fi
|
||||||
|
|
||||||
# If an environment is detected as input, for each secret specified get the value of
|
# If an environment is detected as input, for each secret specified get the value of
|
||||||
# the matching named environment variable then configure using wrangler secret put.
|
# the matching named environment variable then configure using wrangler secret put.
|
||||||
|
@ -82,6 +104,12 @@ else
|
||||||
done
|
done
|
||||||
fi
|
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
|
# If a working directory is detected as input, revert to the
|
||||||
# original directory before continuing with the workflow
|
# original directory before continuing with the workflow
|
||||||
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
||||||
|
|
Loading…
Reference in a new issue