serverless/.github/workflows/sync-docs.yml
Walid Elnozahy 725b18f3ea
chore: add manual trigger to sync docs action (#12650)
* throw error if sync script fails

* add manual trigger
2024-06-27 23:08:08 +03:00

121 lines
4.1 KiB
YAML

# This workflow is responsible for syncing the docs menu and content to Dev and Prod stages with Algolia and ChatGPT
name: Sync Docs
# Define when this workflow should run
on:
push:
branches: [main]
pull_request:
paths:
- 'docs/**'
# Allow manual triggering of the workflow
workflow_dispatch:
inputs:
job_to_run:
description: 'Job to run'
required: true
type: choice
options:
- all
- docs-menu
- sync-docs-prod
- sync-docs-dev
# Define the permissions for the workflow
permissions:
packages: read
contents: write
pull-requests: write
# Define the jobs in the workflow
jobs:
# Job to publish the docs menu
docs-menu:
name: Publish the docs menu
runs-on: ubuntu-latest
# Run this job on push to main, or when manually triggered for all jobs or specifically for docs-menu
if: |
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
github.event_name == 'workflow_dispatch' && (github.event.inputs.job_to_run == 'all' || github.event.inputs.job_to_run == 'docs-menu')
timeout-minutes: 3 # Set a timeout to prevent long-running jobs
# Set environment variables for AWS access
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DOCS_ASSETS_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DOCS_ASSETS_AWS_SECRET_ACCESS_KEY }}
steps:
- uses: actions/checkout@v3
# Upload menu.json to S3 with a short cache time
- run: |
set -e
aws s3 cp docs/menu.json s3://assets.public.serverless/website/framework/docs/menu.json --cache-control max-age=60 --region us-east-2
# Job to sync docs to production
sync-docs-prod:
name: Sync Docs (Prod)
runs-on: ubuntu-latest
# Run this job on push to main, or when manually triggered for all jobs or specifically for sync-docs-prod
if: |
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
github.event_name == 'workflow_dispatch' && (github.event.inputs.job_to_run == 'all' || github.event.inputs.job_to_run == 'sync-docs-prod')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: |
set -e
npm install
working-directory: scripts
- name: Run sync script
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY_PROD }}
ALGOLIA_DOCS_INDEX: ${{ secrets.ALGOLIA_DOCS_INDEX_PROD }}
run: |
set -e
node sync-docs.js
working-directory: scripts
# Job to sync docs to development
sync-docs-dev:
name: Sync Docs (Dev)
runs-on: ubuntu-latest
# Run this job on pull requests, or when manually triggered for all jobs or specifically for sync-docs-dev
if: |
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch' && (github.event.inputs.job_to_run == 'all' || github.event.inputs.job_to_run == 'sync-docs-dev')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Git
run: |
set -e
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Push changes to docs-dev
run: |
set -e
git checkout -b docs-dev
git push origin docs-dev --force
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: |
set -e
npm install
working-directory: scripts
- name: Run sync script for dev
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY_DEV }}
ALGOLIA_DOCS_INDEX: ${{ secrets.ALGOLIA_DOCS_INDEX_DEV }}
run: |
set -e
node sync-docs.js
working-directory: scripts