Skip to content

Commit

Permalink
Added some tests for edge functions
Browse files Browse the repository at this point in the history
Moved to 5.1.1 cli with bulk functions support baked in
  • Loading branch information
stooit committed Nov 26, 2024
1 parent 57e544a commit aed7f08
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 213 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,73 @@ 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: |
# Create directories
mkdir -p functions
mkdir -p build
# 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/function.js << 'EOL'
export default async function handler(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"
},
{
"type": "function",
"path": "./functions/function.js",
"description": "Test edge function",
"uuid": "33333333-3333-4333-a333-333333333333"
}
]
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: ./
with:
customer: quant
project: github-actions
token: ${{ secrets.QUANT_TOKEN }}
dir: build
functions: "./functions/config.json"
160 changes: 47 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -13,14 +14,25 @@ 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 |
|-------|-------------|----------|---------|
| `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` |
Expand All @@ -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
Expand Down Expand Up @@ -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 ]
Expand All @@ -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 ]
Expand All @@ -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
Expand Down
Loading

0 comments on commit aed7f08

Please sign in to comment.