Skip to content

Commit

Permalink
Merge pull request #13 from quantcdn/feat/v5-cli
Browse files Browse the repository at this point in the history
Update deploy action to support v5.
  • Loading branch information
stooit authored Nov 25, 2024
2 parents 6841f7e + e4108bd commit db604dd
Show file tree
Hide file tree
Showing 3 changed files with 330 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare a test file
run: |
Expand All @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare a test file
run: |
Expand Down
275 changes: 205 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,228 @@
# QuantCDN Deploy
# Deploy to QuantCDN Action

Deploy projects to QuantCDN using Github Actions.
This GitHub Action deploys your static site or assets to QuantCDN using the Quant CLI v5.

## Getting Started
## Usage

To get started using the action make sure you have the standard workflow structure set up (.github/workflows) create a file called `deploy.yml` with the following contents.
```yaml
- uses: quantcdn/action-deploy@v5
with:
customer: your-customer-id
project: your-project-name
token: ${{ secrets.QUANT_TOKEN }}
dir: build
```
## 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 | - |
| `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` |
| `force` | Force the deployment of assets (skip md5 check) | No | `false` |
| `chunk-size` | Alter the concurrency of deployment | No | `10` |
| `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

```yaml
name: Deploy to QuantCDN
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build site
run: |
npm install
npm run build
- name: Deploy to QuantCDN
uses: quantcdn/action-deploy@v5
with:
customer: your-customer-id
project: your-project-name
token: ${{ secrets.QUANT_TOKEN }}
dir: build
```

### Advanced Deployment

```yaml
name: Deploy to QuantCDN
on:
push:
branches:
- master
branches: [ main ]
jobs:
build:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Build the artefact or restore a cached copy.
# - name: Build the deploy artefact
# run: npm run build
- uses: quantcdn/[email protected]
- uses: actions/checkout@v4
- name: Build site
run: |
npm install
npm run build
- name: Deploy to QuantCDN
uses: quantcdn/action-deploy@v5
with:
customer: <quant-customer-id>
project: <quant-project-id>
customer: your-customer-id
project: your-project-name
token: ${{ secrets.QUANT_TOKEN }}
dir: <build>
skip-unpublish: true
dir: build
attachments: true
skip-unpublish: false
chunk-size: 20
force: true
```

### Multiple Functions Deployment Example

```yaml
name: Deploy to QuantCDN with Multiple Functions
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build site
run: |
npm install
npm run build
- 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"
},
{
"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"
}
]
```

Replace the placeholders with values for your project, these can be found in the [Quant dashboard](https://docs.quantcdn.io/docs/dashboard).
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

## Adding secrets
Functions will automatically be deployed to `/fn/{uuid}`.

Navigate to your repositories Settings page and find **Secrets**. Once there click on new secret, enter **QUANT_TOKEN** as the secret name and paste your provided Quant API token.
### Functions Configuration

You can learn more about [secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) and [actions](https://docs.github.com/en/actions).
You can configure functions either directly in the workflow or via a JSON file:

## Inputs
#### 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"
}
]
```
customer:
description: "Your customer account name"
required: true
project:
description: "Your project name"
required: true
token:
description: "Your API token"
required: true
dir:
description: "The directory to deploy"
required: true
default: ""
attachments:
description: 'Find attachments'
required: false
default: false
skip-unpublish:
description: 'Skip automatic unpublishing of assets'
required: false
default: false
skip-unpublish-regex:
description: 'Skip automatic unpublishing of assets (by regex)'
required: false
default: ""
skip-purge:
description: 'Skip automatic purge of cached assets in CDN'
required: false
default: false
force:
description: 'Force the deployment of assets (skip md5 check)'
required: false
default: false
chunk-size:
description: 'Alter the concurrency of deployment'
required: false
default: 10
endpoint:
description: 'Specify the QuantCDN API endpoint'
required: false
default: 'https://api.quantcdn.io'
revision-log:
description: 'Specify a location for the local revision log file'
required: false
default: 'false'
enable-index-html:
description: 'Enable index.html creation in Quant (preserves 1.x functionality)'
required: false
default: false

#### 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'
```

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
- For search functionality, please use the dedicated search action
- Make sure your `QUANT_TOKEN` is stored securely in your repository secrets

## License

MIT License
Loading

0 comments on commit db604dd

Please sign in to comment.