diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 874a741..3209ce2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: | @@ -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: | diff --git a/README.md b/README.md index 0f54845..3c5e5f5 100644 --- a/README.md +++ b/README.md @@ -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/deploy-action@v4.0.0 + - uses: actions/checkout@v4 + + - name: Build site + run: | + npm install + npm run build + + - name: Deploy to QuantCDN + uses: quantcdn/action-deploy@v5 with: - customer: - project: + customer: your-customer-id + project: your-project-name token: ${{ secrets.QUANT_TOKEN }} - dir: - 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 diff --git a/action.yml b/action.yml index b1c8b2a..02218fc 100644 --- a/action.yml +++ b/action.yml @@ -15,61 +15,152 @@ inputs: description: "The directory to deploy" required: true default: "" - attachments: - description: 'Find attachments' - required: false - default: false skip-unpublish: - description: 'Skip automatic unpublishing of assets' + description: "Skip automatic unpublishing of assets" required: false default: false skip-unpublish-regex: - description: 'Skip automatic unpublishing of assets (by regex)' + description: "Skip automatic unpublishing of assets (by regex)" required: false default: "" skip-purge: - description: 'Skip automatic purge of cached assets in CDN' + description: "Skip automatic purge of cached assets in CDN" required: false default: false force: - description: 'Force the deployment of assets (skip md5 check)' + description: "Force the deployment of assets (skip md5 check)" required: false default: false chunk-size: - description: 'Alter the concurrency of deployment' + description: "Alter the concurrency of deployment" required: false default: 10 endpoint: - description: 'Specify the QuantCDN API endpoint' + description: "Specify the QuantCDN API endpoint" required: false - default: 'https://api.quantcdn.io' + default: "https://api.quantcdn.io/v1" revision-log: - description: 'Specify a location for the local revision log file' + description: "Specify a location for the local revision log file" required: false - default: 'false' + default: "false" enable-index-html: - description: 'Enable index.html creation in Quant (preserves 1.x functionality)' + description: "Enable index.html creation in Quant" 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: "docker" - image: "docker://quantcdn/cli:4.0.0" - entrypoint: quant - args: - - deploy - - /github/workspace/${{ inputs.dir }} - - -c ${{ inputs.customer }} - - -t ${{ inputs.token }} - - -p ${{ inputs.project }} - - -a ${{ inputs.attachments }} - - --skip-unpublish=${{ inputs.skip-unpublish }} - - --skip-unpublish-regex="${{ inputs.skip-unpublish-regex }}" - - --skip-purge=${{ inputs.skip-purge }} - - --force=${{ inputs.force }} - - --chunk-size=${{ inputs.chunk-size }} - - --endpoint=${{ inputs.endpoint }} - - --revision-log=${{ inputs.revision-log }} - - --enable-index-html=${{ inputs.enable-index-html }} + 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 + + # 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" + exit 1 + ;; + esac + done + } + + # 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 + fi + deploy_functions "$(cat ${{ inputs.functions-file }})" + fi + - name: Deploy Assets + uses: "docker://quantcdn/cli:5.0.3" + with: + args: > + deploy + /github/workspace/${{ inputs.dir }} + -c ${{ inputs.customer }} + -t ${{ inputs.token }} + -p ${{ inputs.project }} + --skip-unpublish=${{ inputs.skip-unpublish }} + --skip-unpublish-regex="${{ inputs.skip-unpublish-regex }}" + --skip-purge=${{ inputs.skip-purge }} + --force=${{ inputs.force }} + --chunk-size=${{ inputs.chunk-size }} + --endpoint=${{ inputs.endpoint }} + --revision-log=${{ inputs.revision-log }} + --enable-index-html=${{ inputs.enable-index-html }} branding: icon: "upload-cloud" color: "blue"