From 74dceb9d9d129853bd0539698ac04c096e1f89f5 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 09:53:24 +1000 Subject: [PATCH 01/10] t1 --- action.yml | 70 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/action.yml b/action.yml index 9b2d2a1..74f3c9c 100644 --- a/action.yml +++ b/action.yml @@ -92,71 +92,71 @@ runs: ENDPOINT: ${{ inputs.endpoint }} with: entrypoint: /bin/bash - args: -c " - if [ ! -z '${{ inputs.functions }}' ]; then - echo '${{ inputs.functions }}' | jq -c '.[]' | while read -r fn; do - type=$(echo $fn | jq -r '.type') - path=$(echo $fn | jq -r '.path') - desc=$(echo $fn | jq -r '.description') - uuid=$(echo $fn | jq -r '.uuid') + args: >- + -c ' + if [ ! -z "${{ inputs.functions }}" ]; then + echo "${{ inputs.functions }}" | jq -c ".[]" | while read -r fn; do + type=$(echo $fn | jq -r ".type") + path=$(echo $fn | jq -r ".path") + desc=$(echo $fn | jq -r ".description") + uuid=$(echo $fn | jq -r ".uuid") - if [ ! -f \"$path\" ]; then - echo \"Error: Function file not found: $path\" + if [ ! -f "$path" ]; then + echo "Error: Function file not found: $path" exit 1 fi case $type in - 'auth') - quant auth \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "auth") + quant auth "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; - 'filter') - quant filter \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "filter") + quant filter "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; - 'edge') - quant function \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "edge") + quant function "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; *) - echo \"Error: Invalid function type: $type\" + echo "Error: Invalid function type: $type" exit 1 ;; esac done fi - if [ ! -z '${{ inputs.functions-file }}' ]; then - if [ ! -f '${{ inputs.functions-file }}' ]; then - echo 'Error: Functions file not found: ${{ inputs.functions-file }}' + if [ ! -z "${{ inputs.functions-file }}" ]; then + if [ ! -f "${{ inputs.functions-file }}" ]; then + echo "Error: Functions file not found: ${{ inputs.functions-file }}" exit 1 fi - cat '${{ inputs.functions-file }}' | jq -c '.[]' | while read -r fn; do - type=$(echo $fn | jq -r '.type') - path=$(echo $fn | jq -r '.path') - desc=$(echo $fn | jq -r '.description') - uuid=$(echo $fn | jq -r '.uuid') + cat "${{ inputs.functions-file }}" | jq -c ".[]" | while read -r fn; do + type=$(echo $fn | jq -r ".type") + path=$(echo $fn | jq -r ".path") + desc=$(echo $fn | jq -r ".description") + uuid=$(echo $fn | jq -r ".uuid") - if [ ! -f \"$path\" ]; then - echo \"Error: Function file not found: $path\" + if [ ! -f "$path" ]; then + echo "Error: Function file not found: $path" exit 1 fi case $type in - 'auth') - quant auth \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "auth") + quant auth "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; - 'filter') - quant filter \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "filter") + quant filter "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; - 'edge') - quant function \"$path\" \"$desc\" \"$uuid\" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + "edge") + quant function "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT ;; *) - echo \"Error: Invalid function type: $type\" + echo "Error: Invalid function type: $type" exit 1 ;; esac done - fi - " + fi' - name: Deploy Assets uses: "docker://quantcdn/cli:5.0.3" with: From 700bc00d0ee9fca159cc147552401fbec918a746 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 09:55:45 +1000 Subject: [PATCH 02/10] t2 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 74f3c9c..6b02eaf 100644 --- a/action.yml +++ b/action.yml @@ -91,7 +91,7 @@ runs: PROJECT: ${{ inputs.project }} ENDPOINT: ${{ inputs.endpoint }} with: - entrypoint: /bin/bash + entrypoint: /bin/sh args: >- -c ' if [ ! -z "${{ inputs.functions }}" ]; then From ed5c906b0038fc6fc7ae3c12cf05186a008ccfa4 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:00:04 +1000 Subject: [PATCH 03/10] t3 --- action.yml | 101 +++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/action.yml b/action.yml index 6b02eaf..2fe9a94 100644 --- a/action.yml +++ b/action.yml @@ -91,72 +91,73 @@ runs: PROJECT: ${{ inputs.project }} ENDPOINT: ${{ inputs.endpoint }} with: - entrypoint: /bin/sh + entrypoint: sh args: >- - -c ' - if [ ! -z "${{ inputs.functions }}" ]; then - echo "${{ inputs.functions }}" | jq -c ".[]" | while read -r fn; do - type=$(echo $fn | jq -r ".type") - path=$(echo $fn | jq -r ".path") - desc=$(echo $fn | jq -r ".description") - uuid=$(echo $fn | jq -r ".uuid") + -c " + if [ ! -z '${{ inputs.functions }}' ]; then + echo '${{ inputs.functions }}' | jq -c '.[]' | while read -r fn; do + type=$(echo \"$fn\" | jq -r '.type'); + path=$(echo \"$fn\" | jq -r '.path'); + desc=$(echo \"$fn\" | jq -r '.description'); + uuid=$(echo \"$fn\" | jq -r '.uuid'); - if [ ! -f "$path" ]; then - echo "Error: Function file not found: $path" - exit 1 - fi + if [ ! -f \"$path\" ]; then + echo 'Error: Function file not found: '$path; + exit 1; + fi; - case $type in - "auth") - quant auth "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + case \"$type\" in + 'auth') + quant auth \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; - "filter") - quant filter "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + 'filter') + quant filter \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; - "edge") - quant function "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + 'edge') + quant function \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; *) - echo "Error: Invalid function type: $type" - exit 1 + echo 'Error: Invalid function type: '$type; + exit 1; ;; - esac - done - fi + esac; + done; + fi; - if [ ! -z "${{ inputs.functions-file }}" ]; then - if [ ! -f "${{ inputs.functions-file }}" ]; then - echo "Error: Functions file not found: ${{ inputs.functions-file }}" - exit 1 - fi - cat "${{ inputs.functions-file }}" | jq -c ".[]" | while read -r fn; do - type=$(echo $fn | jq -r ".type") - path=$(echo $fn | jq -r ".path") - desc=$(echo $fn | jq -r ".description") - uuid=$(echo $fn | jq -r ".uuid") + if [ ! -z '${{ inputs.functions-file }}' ]; then + if [ ! -f '${{ inputs.functions-file }}' ]; then + echo 'Error: Functions file not found: ${{ inputs.functions-file }}'; + exit 1; + fi; + cat '${{ inputs.functions-file }}' | jq -c '.[]' | while read -r fn; do + type=$(echo \"$fn\" | jq -r '.type'); + path=$(echo \"$fn\" | jq -r '.path'); + desc=$(echo \"$fn\" | jq -r '.description'); + uuid=$(echo \"$fn\" | jq -r '.uuid'); - if [ ! -f "$path" ]; then - echo "Error: Function file not found: $path" - exit 1 - fi + if [ ! -f \"$path\" ]; then + echo 'Error: Function file not found: '$path; + exit 1; + fi; - case $type in - "auth") - quant auth "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + case \"$type\" in + 'auth') + quant auth \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; - "filter") - quant filter "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + 'filter') + quant filter \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; - "edge") - quant function "$path" "$desc" "$uuid" -c $CUSTOMER -t $TOKEN -p $PROJECT -e $ENDPOINT + 'edge') + quant function \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; ;; *) - echo "Error: Invalid function type: $type" - exit 1 + echo 'Error: Invalid function type: '$type; + exit 1; ;; - esac - done - fi' + esac; + done; + fi + " - name: Deploy Assets uses: "docker://quantcdn/cli:5.0.3" with: From 0784323d9a532bc9f1c6befe2ef07957cd087c43 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:02:50 +1000 Subject: [PATCH 04/10] Added some tests for edge functions --- .github/workflows/main.yml | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3209ce2..fb022fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -61,3 +61,92 @@ jobs: skip-purge: true force: true chunk-size: 10 + + test-functions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Create test functions + - name: Prepare test functions + run: | + mkdir -p functions + + # Create an auth function + cat > functions/auth.js << 'EOL' + export default async function auth(request) { + return { authenticated: true }; + } + EOL + + # Create a filter function + cat > functions/filter.js << 'EOL' + export default async function filter(request) { + return request; + } + EOL + + # Create an edge function + cat > functions/edge.js << 'EOL' + export default async function edge(request) { + return new Response("Hello from edge function!"); + } + EOL + + # Create functions config file + cat > functions/config.json << EOL + [ + { + "type": "auth", + "path": "./functions/auth.js", + "description": "Test auth function", + "uuid": "11111111-1111-4111-a111-111111111111" + }, + { + "type": "filter", + "path": "./functions/filter.js", + "description": "Test filter function", + "uuid": "22222222-2222-4222-a222-222222222222" + } + ] + EOL + + # Test direct JSON configuration + - name: Test edge function deployment (direct JSON) + uses: ./ + with: + customer: quant + project: github-actions + token: ${{ secrets.QUANT_TOKEN }} + dir: build + functions: | + [ + { + "type": "edge", + "path": "./functions/edge.js", + "description": "Test edge function", + "uuid": "33333333-3333-4333-a333-333333333333" + } + ] + + # Test file-based configuration + - name: Test function deployment (config file) + uses: ./ + with: + customer: quant + project: github-actions + token: ${{ secrets.QUANT_TOKEN }} + dir: build + functions-file: "./functions/config.json" + + # Test individual function deployment + - name: Test individual function deployment + uses: ./ + with: + customer: quant + project: github-actions + token: ${{ secrets.QUANT_TOKEN }} + dir: build + auth-function: "./functions/auth.js" + auth-description: "Test individual auth function" + auth-uuid: "44444444-4444-4444-a444-444444444444" From 26cabd9b7b1e17518e8355732135660f843c5d91 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:05:02 +1000 Subject: [PATCH 05/10] t5 --- action.yml | 110 +++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 59 deletions(-) diff --git a/action.yml b/action.yml index 2fe9a94..49d1d19 100644 --- a/action.yml +++ b/action.yml @@ -93,71 +93,63 @@ runs: with: entrypoint: sh args: >- - -c " - if [ ! -z '${{ inputs.functions }}' ]; then - echo '${{ inputs.functions }}' | jq -c '.[]' | while read -r fn; do - type=$(echo \"$fn\" | jq -r '.type'); - path=$(echo \"$fn\" | jq -r '.path'); - desc=$(echo \"$fn\" | jq -r '.description'); - uuid=$(echo \"$fn\" | jq -r '.uuid'); + -c ' + process_function() { + type=$1 + path=$2 + desc=$3 + uuid=$4 - if [ ! -f \"$path\" ]; then - echo 'Error: Function file not found: '$path; - exit 1; - fi; + if [ ! -f "$path" ]; then + echo "Error: Function file not found: $path" + exit 1 + fi - case \"$type\" in - 'auth') - quant auth \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - 'filter') - quant filter \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - 'edge') - quant function \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - *) - echo 'Error: Invalid function type: '$type; - exit 1; - ;; - esac; - done; - fi; + case $type in + "auth") + quant auth "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + "filter") + quant filter "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + "edge") + quant function "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + *) + echo "Error: Invalid function type: $type" + exit 1 + ;; + esac + } - if [ ! -z '${{ inputs.functions-file }}' ]; then - if [ ! -f '${{ inputs.functions-file }}' ]; then - echo 'Error: Functions file not found: ${{ inputs.functions-file }}'; - exit 1; - fi; - cat '${{ inputs.functions-file }}' | jq -c '.[]' | while read -r fn; do - type=$(echo \"$fn\" | jq -r '.type'); - path=$(echo \"$fn\" | jq -r '.path'); - desc=$(echo \"$fn\" | jq -r '.description'); - uuid=$(echo \"$fn\" | jq -r '.uuid'); + if [ ! -z "${{ inputs.functions }}" ]; then + echo "${{ inputs.functions }}" | jq -r ".[] | [.type, .path, .description, .uuid] | @tsv" | while IFS=$"\t" read -r type path desc uuid; do + process_function "$type" "$path" "$desc" "$uuid" + done + fi + + if [ ! -z "${{ inputs.functions-file }}" ]; then + if [ ! -f "${{ inputs.functions-file }}" ]; then + echo "Error: Functions file not found: ${{ inputs.functions-file }}" + exit 1 + fi + cat "${{ inputs.functions-file }}" | jq -r ".[] | [.type, .path, .description, .uuid] | @tsv" | while IFS=$"\t" read -r type path desc uuid; do + process_function "$type" "$path" "$desc" "$uuid" + done + fi - if [ ! -f \"$path\" ]; then - echo 'Error: Function file not found: '$path; - exit 1; - fi; + if [ ! -z "${{ inputs.auth-function }}" ]; then + process_function "auth" "${{ inputs.auth-function }}" "${{ inputs.auth-description }}" "${{ inputs.auth-uuid }}" + fi + + if [ ! -z "${{ inputs.filter-function }}" ]; then + process_function "filter" "${{ inputs.filter-function }}" "${{ inputs.filter-description }}" "${{ inputs.filter-uuid }}" + fi - case \"$type\" in - 'auth') - quant auth \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - 'filter') - quant filter \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - 'edge') - quant function \"$path\" \"$desc\" \"$uuid\" -c \"$CUSTOMER\" -t \"$TOKEN\" -p \"$PROJECT\" -e \"$ENDPOINT\"; - ;; - *) - echo 'Error: Invalid function type: '$type; - exit 1; - ;; - esac; - done; + if [ ! -z "${{ inputs.edge-function }}" ]; then + process_function "edge" "${{ inputs.edge-function }}" "${{ inputs.edge-description }}" "${{ inputs.edge-uuid }}" fi - " + ' - name: Deploy Assets uses: "docker://quantcdn/cli:5.0.3" with: From c609306773dcd3143955657fdae8cbfc0fbf0416 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:07:57 +1000 Subject: [PATCH 06/10] Test --- action.yml | 132 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/action.yml b/action.yml index 49d1d19..39c412d 100644 --- a/action.yml +++ b/action.yml @@ -83,6 +83,69 @@ inputs: runs: using: "composite" steps: + - name: Create deploy script + shell: sh + run: | + cat > /tmp/deploy-functions.sh << 'EOF' + #!/bin/sh + process_function() { + type=$1 + path=$2 + desc=$3 + uuid=$4 + + if [ ! -f "$path" ]; then + echo "Error: Function file not found: $path" + exit 1 + fi + + case $type in + "auth") + quant auth "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + "filter") + quant filter "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + "edge") + quant function "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" + ;; + *) + echo "Error: Invalid function type: $type" + exit 1 + ;; + esac + } + + if [ ! -z "$FUNCTIONS" ]; then + echo "$FUNCTIONS" | jq -r '.[] | [.type, .path, .description, .uuid] | @tsv' | while IFS=$'\t' read -r type path desc uuid; do + process_function "$type" "$path" "$desc" "$uuid" + done + fi + + if [ ! -z "$FUNCTIONS_FILE" ]; then + if [ ! -f "$FUNCTIONS_FILE" ]; then + echo "Error: Functions file not found: $FUNCTIONS_FILE" + exit 1 + fi + cat "$FUNCTIONS_FILE" | jq -r '.[] | [.type, .path, .description, .uuid] | @tsv' | while IFS=$'\t' read -r type path desc uuid; do + process_function "$type" "$path" "$desc" "$uuid" + done + fi + + if [ ! -z "$AUTH_FUNCTION" ]; then + process_function "auth" "$AUTH_FUNCTION" "$AUTH_DESC" "$AUTH_UUID" + fi + + if [ ! -z "$FILTER_FUNCTION" ]; then + process_function "filter" "$FILTER_FUNCTION" "$FILTER_DESC" "$FILTER_UUID" + fi + + if [ ! -z "$EDGE_FUNCTION" ]; then + process_function "edge" "$EDGE_FUNCTION" "$EDGE_DESC" "$EDGE_UUID" + fi + EOF + chmod +x /tmp/deploy-functions.sh + - name: Validate and Deploy Functions uses: "docker://quantcdn/cli:5.0.3" env: @@ -90,66 +153,21 @@ runs: TOKEN: ${{ inputs.token }} PROJECT: ${{ inputs.project }} ENDPOINT: ${{ inputs.endpoint }} + FUNCTIONS: ${{ inputs.functions }} + FUNCTIONS_FILE: ${{ inputs.functions-file }} + AUTH_FUNCTION: ${{ inputs.auth-function }} + AUTH_DESC: ${{ inputs.auth-description }} + AUTH_UUID: ${{ inputs.auth-uuid }} + FILTER_FUNCTION: ${{ inputs.filter-function }} + FILTER_DESC: ${{ inputs.filter-description }} + FILTER_UUID: ${{ inputs.filter-uuid }} + EDGE_FUNCTION: ${{ inputs.edge-function }} + EDGE_DESC: ${{ inputs.edge-description }} + EDGE_UUID: ${{ inputs.edge-uuid }} with: entrypoint: sh - args: >- - -c ' - process_function() { - type=$1 - path=$2 - desc=$3 - uuid=$4 - - if [ ! -f "$path" ]; then - echo "Error: Function file not found: $path" - exit 1 - fi - - case $type in - "auth") - quant auth "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - "filter") - quant filter "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - "edge") - quant function "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - *) - echo "Error: Invalid function type: $type" - exit 1 - ;; - esac - } - - if [ ! -z "${{ inputs.functions }}" ]; then - echo "${{ inputs.functions }}" | jq -r ".[] | [.type, .path, .description, .uuid] | @tsv" | while IFS=$"\t" read -r type path desc uuid; do - process_function "$type" "$path" "$desc" "$uuid" - done - fi - - if [ ! -z "${{ inputs.functions-file }}" ]; then - if [ ! -f "${{ inputs.functions-file }}" ]; then - echo "Error: Functions file not found: ${{ inputs.functions-file }}" - exit 1 - fi - cat "${{ inputs.functions-file }}" | jq -r ".[] | [.type, .path, .description, .uuid] | @tsv" | while IFS=$"\t" read -r type path desc uuid; do - process_function "$type" "$path" "$desc" "$uuid" - done - fi - - if [ ! -z "${{ inputs.auth-function }}" ]; then - process_function "auth" "${{ inputs.auth-function }}" "${{ inputs.auth-description }}" "${{ inputs.auth-uuid }}" - fi + args: /tmp/deploy-functions.sh - if [ ! -z "${{ inputs.filter-function }}" ]; then - process_function "filter" "${{ inputs.filter-function }}" "${{ inputs.filter-description }}" "${{ inputs.filter-uuid }}" - fi - - if [ ! -z "${{ inputs.edge-function }}" ]; then - process_function "edge" "${{ inputs.edge-function }}" "${{ inputs.edge-description }}" "${{ inputs.edge-uuid }}" - fi - ' - name: Deploy Assets uses: "docker://quantcdn/cli:5.0.3" with: From 0e31b0a129ffee4633facfe7d7f850b76c98f940 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:09:54 +1000 Subject: [PATCH 07/10] Using workspace --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 39c412d..b2ed141 100644 --- a/action.yml +++ b/action.yml @@ -86,7 +86,7 @@ runs: - name: Create deploy script shell: sh run: | - cat > /tmp/deploy-functions.sh << 'EOF' + cat > ${{ github.workspace }}/deploy-functions.sh << 'EOF' #!/bin/sh process_function() { type=$1 @@ -144,7 +144,7 @@ runs: process_function "edge" "$EDGE_FUNCTION" "$EDGE_DESC" "$EDGE_UUID" fi EOF - chmod +x /tmp/deploy-functions.sh + chmod +x ${{ github.workspace }}/deploy-functions.sh - name: Validate and Deploy Functions uses: "docker://quantcdn/cli:5.0.3" @@ -166,7 +166,7 @@ runs: EDGE_UUID: ${{ inputs.edge-uuid }} with: entrypoint: sh - args: /tmp/deploy-functions.sh + args: /github/workspace/deploy-functions.sh - name: Deploy Assets uses: "docker://quantcdn/cli:5.0.3" From a179a2e78fd60df8bf3aaf9fd0e6a53a5e902f79 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 10:57:28 +1000 Subject: [PATCH 08/10] Moved to 5.1.0 cli with bulk functions support baked in --- .github/workflows/main.yml | 46 +++-------- README.md | 160 +++++++++++-------------------------- action.yml | 124 +++------------------------- 3 files changed, 71 insertions(+), 259 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb022fe..8e6f162 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -87,8 +87,8 @@ jobs: EOL # Create an edge function - cat > functions/edge.js << 'EOL' - export default async function edge(request) { + cat > functions/function.js << 'EOL' + export default async function handler(request) { return new Response("Hello from edge function!"); } EOL @@ -107,46 +107,22 @@ jobs: "path": "./functions/filter.js", "description": "Test filter function", "uuid": "22222222-2222-4222-a222-222222222222" + }, + { + "type": "function", + "path": "./functions/function.js", + "description": "Test edge function", + "uuid": "33333333-3333-4333-a333-333333333333" } ] EOL - # Test direct JSON configuration - - name: Test edge function deployment (direct JSON) - uses: ./ - with: - customer: quant - project: github-actions - token: ${{ secrets.QUANT_TOKEN }} - dir: build - functions: | - [ - { - "type": "edge", - "path": "./functions/edge.js", - "description": "Test edge function", - "uuid": "33333333-3333-4333-a333-333333333333" - } - ] - - # Test file-based configuration - - name: Test function deployment (config file) - uses: ./ - with: - customer: quant - project: github-actions - token: ${{ secrets.QUANT_TOKEN }} - dir: build - functions-file: "./functions/config.json" - - # Test individual function deployment - - name: Test individual function deployment + # Test function deployment with config file + - name: Test function deployment uses: ./ with: customer: quant project: github-actions token: ${{ secrets.QUANT_TOKEN }} dir: build - auth-function: "./functions/auth.js" - auth-description: "Test individual auth function" - auth-uuid: "44444444-4444-4444-a444-444444444444" + functions: "./functions/config.json" diff --git a/README.md b/README.md index 9c466ba..fffd6d2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # Deploy to QuantCDN Action -This GitHub Action deploys your static site or assets to QuantCDN using the Quant CLI v5. +This GitHub Action deploys your static site and/or functions to QuantCDN using the Quant CLI v5. ## Usage +### Deploy Assets ```yaml - uses: quantcdn/action-deploy@v5 with: @@ -13,6 +14,16 @@ This GitHub Action deploys your static site or assets to QuantCDN using the Quan dir: build ``` +### Deploy Functions +```yaml +- uses: quantcdn/action-deploy@v5 + with: + customer: your-customer-id + project: your-project-name + token: ${{ secrets.QUANT_TOKEN }} + functions: './functions.json' +``` + ## Inputs | Input | Description | Required | Default | @@ -20,7 +31,8 @@ This GitHub Action deploys your static site or assets to QuantCDN using the Quan | `customer` | Your QuantCDN customer account name | Yes | - | | `project` | Your QuantCDN project name | Yes | - | | `token` | Your QuantCDN API token | Yes | - | -| `dir` | The directory to deploy | Yes | - | +| `dir` | The directory to deploy | No | - | +| `functions` | Path to JSON file containing functions configuration | No | - | | `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` | @@ -29,12 +41,10 @@ This GitHub Action deploys your static site or assets to QuantCDN using the Quan | `endpoint` | Specify the QuantCDN API endpoint | No | `https://api.quantcdn.io/v1` | | `revision-log` | Specify a location for the local revision log file | No | `false` | | `enable-index-html` | Enable index.html creation in Quant | No | `false` | -| `functions` | JSON array of functions to deploy. Each object should contain: type (auth|filter|edge), description, path, and uuid | No | - | -| `functions-file` | Path to JSON file containing functions configuration | No | - | ## Example Workflows -### Basic Deployment +### Basic Asset Deployment ```yaml name: Deploy to QuantCDN @@ -62,10 +72,35 @@ jobs: dir: build ``` -### Advanced Deployment +### Functions Deployment + +Create a functions configuration file (e.g., `functions.json`): +```json +[ + { + "type": "auth", + "path": "./functions/auth.js", + "description": "Authentication function", + "uuid": "11111111-1111-4111-a111-111111111111" + }, + { + "type": "filter", + "path": "./functions/filter.js", + "description": "Filter function", + "uuid": "22222222-2222-4222-a222-222222222222" + }, + { + "type": "function", + "path": "./functions/function.js", + "description": "Edge function", + "uuid": "33333333-3333-4333-a333-333333333333" + } +] +``` +Then deploy using: ```yaml -name: Deploy to QuantCDN +name: Deploy Functions to QuantCDN on: push: branches: [ main ] @@ -76,27 +111,19 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build site - run: | - npm install - npm run build - - - name: Deploy to QuantCDN + - name: Deploy Functions uses: quantcdn/action-deploy@v5 with: customer: your-customer-id project: your-project-name token: ${{ secrets.QUANT_TOKEN }} - dir: build - skip-unpublish: false - chunk-size: 20 - force: true + functions: './functions.json' ``` -### Multiple Functions Deployment Example +### Combined Deployment ```yaml -name: Deploy to QuantCDN with Multiple Functions +name: Deploy Everything to QuantCDN on: push: branches: [ main ] @@ -119,102 +146,9 @@ jobs: project: your-project-name token: ${{ secrets.QUANT_TOKEN }} dir: build - functions: | - [ - { - "type": "auth", - "path": "./functions/auth.js", - "description": "Custom authentication function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c34" - }, - { - "type": "edge", - "path": "./functions/edge.js", - "description": "Custom edge function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c35" - }, - { - "type": "filter", - "path": "./functions/filter.js", - "description": "Custom filter function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c36" - } - ] -``` - -The `functions` input accepts a JSON array where each object must contain: -- `type`: Either "auth", "filter", or "edge" -- `path`: Path to the function file (e.g., "./functions/auth.js") -- `description`: Description of the function -- `uuid`: Valid UUID for the function - -Functions will automatically be deployed to `/fn/{uuid}`. - -### Functions Configuration - -You can configure functions either directly in the workflow or via a JSON file: - -#### Option 1: Direct Configuration - -```yaml - - name: Deploy to QuantCDN - uses: quantcdn/action-deploy@v5 - with: - customer: your-customer-id - project: your-project-name - token: ${{ secrets.QUANT_TOKEN }} - dir: build - functions: | - [ - { - "type": "auth", - "path": "./functions/auth.js", - "description": "Custom authentication function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c34" - } - ] -``` - -#### Option 2: JSON File Configuration - -Create a JSON file (e.g., `functions.json`): -```json -[ - { - "type": "auth", - "path": "./functions/auth.js", - "description": "Custom authentication function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c34" - }, - { - "type": "edge", - "path": "./functions/edge.js", - "description": "Custom edge function", - "uuid": "019361ae-2516-788a-8f50-e803ff561c35" - } -] -``` - -Then reference it in your workflow: -```yaml - - name: Deploy to QuantCDN - uses: quantcdn/action-deploy@v5 - with: - customer: your-customer-id - project: your-project-name - token: ${{ secrets.QUANT_TOKEN }} - dir: build - functions-file: './functions.json' + functions: './functions.json' ``` -The function configuration requires: -- `type`: Either "auth", "filter", or "edge" -- `path`: Path to the function file (e.g., "./functions/auth.js") -- `description`: Description of the function -- `uuid`: Valid UUID for the function - -Functions will automatically be deployed to `/fn/{uuid}`. - ## Notes - This action uses Quant CLI v5 diff --git a/action.yml b/action.yml index b2ed141..1af78c2 100644 --- a/action.yml +++ b/action.yml @@ -13,8 +13,7 @@ inputs: required: true dir: description: "The directory to deploy" - required: true - default: "" + required: false skip-unpublish: description: "Skip automatic unpublishing of assets" required: false @@ -48,128 +47,31 @@ inputs: required: false default: false functions: - description: "JSON array of functions to deploy. Each object should contain: type (auth|filter|edge), description, and uuid" - required: false - functions-file: description: "Path to JSON file containing functions configuration" required: false - auth-function: - description: "Path to auth function file" - required: false - auth-description: - description: "Description for the auth function" - required: false - auth-uuid: - description: "UUID for the auth function" - required: false - filter-function: - description: "Path to filter function file" - required: false - filter-description: - description: "Description for the filter function" - required: false - filter-uuid: - description: "UUID for the filter function" - required: false - edge-function: - description: "Path to edge function file" - required: false - edge-description: - description: "Description for the edge function" - required: false - edge-uuid: - description: "UUID for the edge function" - required: false runs: using: "composite" steps: - - name: Create deploy script - shell: sh - run: | - cat > ${{ github.workspace }}/deploy-functions.sh << 'EOF' - #!/bin/sh - process_function() { - type=$1 - path=$2 - desc=$3 - uuid=$4 - - if [ ! -f "$path" ]; then - echo "Error: Function file not found: $path" - exit 1 - fi - - case $type in - "auth") - quant auth "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - "filter") - quant filter "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - "edge") - quant function "$path" "$desc" "$uuid" -c "$CUSTOMER" -t "$TOKEN" -p "$PROJECT" -e "$ENDPOINT" - ;; - *) - echo "Error: Invalid function type: $type" - exit 1 - ;; - esac - } - - if [ ! -z "$FUNCTIONS" ]; then - echo "$FUNCTIONS" | jq -r '.[] | [.type, .path, .description, .uuid] | @tsv' | while IFS=$'\t' read -r type path desc uuid; do - process_function "$type" "$path" "$desc" "$uuid" - done - fi - - if [ ! -z "$FUNCTIONS_FILE" ]; then - if [ ! -f "$FUNCTIONS_FILE" ]; then - echo "Error: Functions file not found: $FUNCTIONS_FILE" - exit 1 - fi - cat "$FUNCTIONS_FILE" | jq -r '.[] | [.type, .path, .description, .uuid] | @tsv' | while IFS=$'\t' read -r type path desc uuid; do - process_function "$type" "$path" "$desc" "$uuid" - done - fi - - if [ ! -z "$AUTH_FUNCTION" ]; then - process_function "auth" "$AUTH_FUNCTION" "$AUTH_DESC" "$AUTH_UUID" - fi - - if [ ! -z "$FILTER_FUNCTION" ]; then - process_function "filter" "$FILTER_FUNCTION" "$FILTER_DESC" "$FILTER_UUID" - fi - - if [ ! -z "$EDGE_FUNCTION" ]; then - process_function "edge" "$EDGE_FUNCTION" "$EDGE_DESC" "$EDGE_UUID" - fi - EOF - chmod +x ${{ github.workspace }}/deploy-functions.sh - - - name: Validate and Deploy Functions - uses: "docker://quantcdn/cli:5.0.3" + - name: Deploy Functions + if: inputs.functions != '' + uses: "docker://quantcdn/cli:5.1.0" env: CUSTOMER: ${{ inputs.customer }} TOKEN: ${{ inputs.token }} PROJECT: ${{ inputs.project }} ENDPOINT: ${{ inputs.endpoint }} - FUNCTIONS: ${{ inputs.functions }} - FUNCTIONS_FILE: ${{ inputs.functions-file }} - AUTH_FUNCTION: ${{ inputs.auth-function }} - AUTH_DESC: ${{ inputs.auth-description }} - AUTH_UUID: ${{ inputs.auth-uuid }} - FILTER_FUNCTION: ${{ inputs.filter-function }} - FILTER_DESC: ${{ inputs.filter-description }} - FILTER_UUID: ${{ inputs.filter-uuid }} - EDGE_FUNCTION: ${{ inputs.edge-function }} - EDGE_DESC: ${{ inputs.edge-description }} - EDGE_UUID: ${{ inputs.edge-uuid }} with: - entrypoint: sh - args: /github/workspace/deploy-functions.sh + args: > + functions + ${{ inputs.functions }} + -c ${{ inputs.customer }} + -t ${{ inputs.token }} + -p ${{ inputs.project }} + -e ${{ inputs.endpoint }} - name: Deploy Assets - uses: "docker://quantcdn/cli:5.0.3" + if: inputs.dir != '' + uses: "docker://quantcdn/cli:5.1.0" with: args: > deploy From e275e660ab43e7a1e6688828c079bdc1788de632 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 11:01:48 +1000 Subject: [PATCH 09/10] Fixed test --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e6f162..63713c9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,7 +70,9 @@ jobs: # Create test functions - name: Prepare test functions run: | + # Create directories mkdir -p functions + mkdir -p build # Create an auth function cat > functions/auth.js << 'EOL' @@ -117,6 +119,9 @@ jobs: ] EOL + # Create a dummy file in build directory + echo "dummy file" > build/index.html + # Test function deployment with config file - name: Test function deployment uses: ./ From 5d916fc907e2ea31c7571fb2b705310a6b15119f Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Tue, 26 Nov 2024 11:31:51 +1000 Subject: [PATCH 10/10] Use 5.1.1 CLI release. --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 1af78c2..6736c8c 100644 --- a/action.yml +++ b/action.yml @@ -54,7 +54,7 @@ runs: steps: - name: Deploy Functions if: inputs.functions != '' - uses: "docker://quantcdn/cli:5.1.0" + uses: "docker://quantcdn/cli:5.1.1" env: CUSTOMER: ${{ inputs.customer }} TOKEN: ${{ inputs.token }} @@ -71,7 +71,7 @@ runs: - name: Deploy Assets if: inputs.dir != '' - uses: "docker://quantcdn/cli:5.1.0" + uses: "docker://quantcdn/cli:5.1.1" with: args: > deploy