Skip to content

Commit

Permalink
Ensure functions deployment runs in cli image.
Browse files Browse the repository at this point in the history
  • Loading branch information
stooit committed Nov 25, 2024
1 parent db604dd commit a696913
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This GitHub Action deploys your static site or assets to QuantCDN using the Quan
| `project` | Your QuantCDN project name | Yes | - |
| `token` | Your QuantCDN API token | Yes | - |
| `dir` | The directory to deploy | Yes | - |
| `attachments` | Find and process attachments | No | `false` |
| `skip-unpublish` | Skip automatic unpublishing of assets | No | `false` |
| `skip-unpublish-regex` | Skip automatic unpublishing of assets matching regex pattern | No | - |
| `skip-purge` | Skip automatic purge of cached assets in CDN | No | `false` |
Expand Down Expand Up @@ -89,7 +88,6 @@ jobs:
project: your-project-name
token: ${{ secrets.QUANT_TOKEN }}
dir: build
attachments: true
skip-unpublish: false
chunk-size: 20
force: true
Expand Down
113 changes: 58 additions & 55 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,66 +84,69 @@ runs:
using: "composite"
steps:
- name: Validate and Deploy Functions
shell: bash
run: |
deploy_functions() {
local json_input="$1"
echo "$json_input" | jq -c '.[]' | while read -r function; do
type=$(echo $function | jq -r '.type')
path=$(echo $function | jq -r '.path')
desc=$(echo $function | jq -r '.description')
uuid=$(echo $function | jq -r '.uuid')
# Validate required fields
if [ -z "$path" ] || [ -z "$desc" ] || [ -z "$uuid" ]; then
echo "Error: Each function must have path, description and UUID"
exit 1
fi
uses: "docker://quantcdn/cli:5.0.3"
with:
args: |
/bin/bash -c '
deploy_functions() {
local json_input="$1"
echo "$json_input" | jq -c ".[]" | while read -r function; do
type=$(echo $function | jq -r ".type")
path=$(echo $function | jq -r ".path")
desc=$(echo $function | jq -r ".description")
uuid=$(echo $function | jq -r ".uuid")
# Validate required fields
if [ -z "$path" ] || [ -z "$desc" ] || [ -z "$uuid" ]; then
echo "Error: Each function must have path, description and UUID"
exit 1
fi
# Check if file exists
if [ ! -f "$path" ]; then
echo "Error: Function file not found: $path"
exit 1
fi
# Validate UUID format - support v4-v7
if [[ ! $uuid =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[4-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ]]; then
echo "Error: Invalid UUID format (must be UUID v4-v7): $uuid"
exit 1
fi
# Deploy based on type
case $type in
"auth")
quant auth "$path" "$desc" "$uuid"
;;
"filter")
quant filter "$path" "$desc" "$uuid"
;;
"edge")
quant function "$path" "$desc" "$uuid"
;;
*)
echo "Error: Invalid function type: $type"
# Check if file exists
if [ ! -f "$path" ]; then
echo "Error: Function file not found: $path"
exit 1
fi
# Validate UUID format - support v4-v7
if [[ ! $uuid =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[4-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ]]; then
echo "Error: Invalid UUID format (must be UUID v4-v7): $uuid"
exit 1
;;
esac
done
}
fi
# Deploy based on type
case $type in
"auth")
quant auth "$path" "$desc" "$uuid"
;;
"filter")
quant filter "$path" "$desc" "$uuid"
;;
"edge")
quant function "$path" "$desc" "$uuid"
;;
*)
echo "Error: Invalid function type: $type"
exit 1
;;
esac
done
}
# Deploy from JSON string if provided
if [ ! -z "${{ inputs.functions }}" ]; then
deploy_functions '${{ inputs.functions }}'
fi
# Deploy from JSON string if provided
if [ ! -z "${{ inputs.functions }}" ]; then
deploy_functions "${{ inputs.functions }}"
fi
# Deploy from JSON file if provided
if [ ! -z "${{ inputs.functions-file }}" ]; then
if [ ! -f "${{ inputs.functions-file }}" ]; then
echo "Error: Functions file not found: ${{ inputs.functions-file }}"
exit 1
# Deploy from JSON file if provided
if [ ! -z "${{ inputs.functions-file }}" ]; then
if [ ! -f "${{ inputs.functions-file }}" ]; then
echo "Error: Functions file not found: ${{ inputs.functions-file }}"
exit 1
fi
deploy_functions "$(cat ${{ inputs.functions-file }})"
fi
deploy_functions "$(cat ${{ inputs.functions-file }})"
fi
'
- name: Deploy Assets
uses: "docker://quantcdn/cli:5.0.3"
with:
Expand Down

0 comments on commit a696913

Please sign in to comment.