Skip to content

Commit

Permalink
feat: Add cache bust to action
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon authored Feb 13, 2025
2 parents 8c2fae5 + 6c884df commit 2fc9451
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
# salmon-sync

This is a Github Action that syncs a folder to a Google Cloud bucket using `rclone`.
This is a Github Action that syncs a folder to a Google Cloud bucket using `rclone` and then send an authenticated request to the doc site to invalidate the cache for the doc version.
This action is only meant to work for Deephaven's documentation. It could be used in a more general purpose way to sync a folder into any Google cloud bucket (with the proper credentials), but that is subject to change and may break in any version.

## Parameters
```

```yml
inputs:
source:
required: true
type: string
description: 'The source directory to sync.'
description: "The source directory to sync."
destination:
required: true
type: string
description: 'The destination directory to sync. Relative to the bucket. It is recommended to use the GitHub repo path (such as deephaven/salmon-sync) as the minimum base to prevent collisions.'
project_number:
required: true
type: string
description: 'The Google Cloud project number.'
description: "The destination directory to sync. Relative to the bucket. It is recommended to use the GitHub repo path (such as deephaven/salmon-sync) as the minimum base to prevent collisions."
bucket:
required: true
type: string
description: 'The Google Cloud bucket to sync to.'
description: "The Google Cloud bucket to sync to."
credentials:
required: true
type: string
description: 'The Google Cloud credentials. Should be base64 encoded.'
description: "The Google Cloud credentials. Should be base64 encoded."
cache-bust-token:
required: true
type: string
description: "The cache-bust token"
docs-url:
required: true
type: string
description: "The doc site URL"
```
## Example
The action can be used as a step in a workflow
Here is an example that syncs from the local path `temp/blog` to the blog section of the bucket.
```

```yml
- name: Sync to the blog
uses: deephaven/salmon-sync@v1
with:
source: temp/blog
destination: deephaven/deephaven.io/blog
project_number: ${{ secrets.DOCS_GOOGLE_CLOUD_PROJECT_NUMBER}}
bucket: ${{ vars.DOCS_GOOGLE_CLOUD_BUCKET }}
bucket: ${{ vars.DOCS_PROD_BUCKET }} # or ${{ vars.DOCS_PREVIEW_BUCKET }}
credentials: ${{ secrets.DOCS_GOOGLE_CLOUD_CREDENTIALS }}
cache-bust-token: ${{ secrets.DOCS_CACHE_BUST_TOKEN }}
docs-url: ${{ vars.DOCS_PROD_URL }} # or ${{ vars.DOCS_PREVIEW_URL }}
```
37 changes: 25 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
name: Sync Salmon Directory
description: Syncs a directory to a Google Cloud bucket using rclone.
author: 'deephaven'
author: "deephaven"
inputs:
source:
required: true
type: string
description: 'The source directory to sync.'
description: "The source directory to sync."
destination:
required: true
type: string
description: 'The destination directory to sync. Relative to the bucket. It is recommended to use the GitHub repo path (such as deephaven/salmon-sync) as the minimum base to prevent collisions.'
project_number:
required: true
type: string
description: 'The Google Cloud project number.'
description: "The destination directory to sync. Relative to the bucket. It is recommended to use the GitHub repo path (such as deephaven/salmon-sync) as the minimum base to prevent collisions."
bucket:
required: true
type: string
description: 'The Google Cloud bucket to sync to.'
description: "The Google Cloud bucket to sync to."
credentials:
required: true
type: string
description: 'The Google Cloud credentials. Should be base64 encoded.'
description: "The Google Cloud credentials. Should be base64 encoded."
cache-bust-token:
required: true
type: string
description: "The cache-bust token"
docs-url:
required: true
type: string
description: "The doc site URL"

runs:
using: "composite"
Expand All @@ -37,13 +41,22 @@ runs:
echo $RCLONE_GCS_SERVICE_ACCOUNT_CREDENTIALS_ENCODED | base64 --decode > $HOME/credentials.json
env:
RCLONE_GCS_SERVICE_ACCOUNT_CREDENTIALS_ENCODED: ${{ inputs.credentials }}


- name: Sync source to destination
shell: bash
env:
RCLONE_CONFIG_GCS_TYPE: "google cloud storage"
RCLONE_GCS_SERVICE_ACCOUNT_FILE: $HOME/credentials.json
RCLONE_GCS_PROJECT_NUMBER: ${{ inputs.project_number }}
RCLONE_GCS_BUCKET_POLICY_ONLY: "true"
run: rclone sync ${{ inputs.source }} gcs:${{ inputs.bucket }}/${{ inputs.destination }}
run: rclone sync ${{ inputs.source }} gcs:${{ inputs.bucket }}/${{ inputs.destination }}

- name: Bust cache
shell: bash
env:
CACHE_BUST_TOKEN: ${{ inputs.cache-bust-token }}
run: |
curl --fail-with-body --show-error --silent \
--request POST \
--header "authorization: Bearer $CACHE_BUST_TOKEN" \
--data "{ \"tags\": [ \"${{ inputs.destination }}\" ]}" \
--url ${{ inputs.docs-url }}/api/cache-bust/

0 comments on commit 2fc9451

Please sign in to comment.