Sync GitBook Docs #113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync GitBook Docs | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'The environment used as target' | |
type: choice | |
required: true | |
default: dev | |
options: | |
- dev | |
- uat | |
- prod | |
call_reindex: | |
description: 'Trigger reindex workflow after docs sync' | |
type: boolean | |
required: true | |
default: false | |
metadata_type: | |
description: 'Type of metadata to generate' | |
type: choice | |
required: true | |
default: all | |
options: | |
- all | |
- guides | |
- solutions | |
- release_notes | |
generate_metadata_only: | |
description: 'Generate metadata only without syncing docs' | |
type: boolean | |
required: true | |
default: false | |
incremental_mode: | |
description: 'Run sync in incremental mode by checking only file size' | |
type: boolean | |
required: true | |
default: true | |
inivalidate_opennext_cache: | |
description: 'Invalidate opennext cloufront cache' | |
type: boolean | |
required: true | |
default: false | |
schedule: | |
- cron: '0 23 * * *' # Run daily at midnight UTC | |
# Permissions needed for AWS OIDC authentication | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
sync_gitbook_docs: | |
name: Sync gitbook Docs to S3 (manual on ${{ inputs.environment }}) | |
if: github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
outputs: | |
environment: ${{ inputs.environment }} | |
environment: ${{ inputs.environment }} | |
env: | |
ENV_SHORT: ${{ fromJSON('{"dev":"d","uat":"u","prod":"p"}')[inputs.environment] }} | |
steps: | |
- name: Checkout current repository | |
uses: actions/checkout@v4 | |
- name: Checkout devportal-docs repo | |
if: inputs.generate_metadata_only == false | |
uses: actions/checkout@v4 | |
with: | |
repository: pagopa/devportal-docs | |
ref: docs/from-gitbook | |
path: devportal-docs | |
- name: Setup Node.JS | |
uses: ./.github/actions/setup-node | |
- name: Cache npm dependencies | |
id: cache-npm | |
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Install dependencies | |
run: | | |
npm config set cache ~/.npm | |
npm ci | |
- name: Compile packages | |
run: npm run compile | |
- name: Generate UrlReplace metadata | |
if: inputs.generate_metadata_only == false | |
env: | |
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || 'dev' }} | |
DOCUMENTATION_PATH: ${{ vars.DOCUMENTATION_PATH || '../../devportal-docs/docs' }} | |
URL_PARSING_METADATA_JSON_PATH: ${{ vars.URL_PARSING_METADATA_JSON_PATH || '../../url-parsing-metadata.json' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
run: npm run generate-url-parsing-metadata -w gitbook-docs | |
- name: Replace urls and include tags in docs | |
env: | |
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || 'dev' }} | |
DOCUMENTATION_PATH: ${{ vars.DOCUMENTATION_PATH || '../../devportal-docs/docs' }} | |
URL_PARSING_METADATA_JSON_PATH: ${{ vars.URL_PARSING_METADATA_JSON_PATH || '../../url-parsing-metadata.json' }} | |
if: inputs.generate_metadata_only == false | |
run: npm run parse-docs -w gitbook-docs | |
- name: Configure AWS Credentials | |
uses: ./.github/actions/configure-aws-credentials | |
with: | |
aws_region: eu-south-1 | |
role_to_assume: ${{ secrets.DEPLOY_IAM_ROLE }} | |
- name: Sync docs folder to S3 | |
if: inputs.generate_metadata_only == false | |
working-directory: ./devportal-docs | |
run: | | |
aws s3 sync docs s3://devportal-${{ env.ENV_SHORT }}-website-static-content/devportal-docs/docs --delete ${{ inputs.incremental_mode == true && ' --size-only' || '' }} | |
- name: Generate guides metadata | |
if: inputs.metadata_type == 'guides' || inputs.metadata_type == 'all' | |
env: | |
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || 'dev' }} | |
S3_BUCKET_NAME: devportal-${{ env.ENV_SHORT }}-website-static-content | |
S3_DOC_EXTRACTION_BUCKET_NAME: ${{ vars.S3_DOC_EXTRACTION_BUCKET_NAME }} | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-guides-metadata -w gitbook-docs | |
- name: Generate solutions metadata | |
if: inputs.metadata_type == 'solutions' || inputs.metadata_type == 'all' | |
env: | |
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || 'dev' }} | |
S3_BUCKET_NAME: devportal-${{ env.ENV_SHORT }}-website-static-content | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-solutions-metadata -w gitbook-docs | |
- name: Generate release notes metadata | |
if: inputs.metadata_type == 'release_notes' || inputs.metadata_type == 'all' | |
env: | |
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || 'dev' }} | |
S3_BUCKET_NAME: devportal-${{ env.ENV_SHORT }}-website-static-content | |
S3_DOC_EXTRACTION_BUCKET_NAME: ${{ vars.S3_DOC_EXTRACTION_BUCKET_NAME }} | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-release-notes-metadata -w gitbook-docs | |
- name: Invalidate CloudFront asset bucket cache | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id ${{ vars.ASSET_BUCKET_CLOUDFRONT_DISTRIBUTION_ID }} \ | |
--paths "/*" | |
- name: Invalidate CloudFront opennext cache | |
if: inputs.inivalidate_opennext_cache == true | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id ${{ vars.OPENNEXT_CLOUDFRONT_DISTRIBUTION_ID }} \ | |
--paths "/*" | |
- name: Trigger reindex workflow | |
if: inputs.call_reindex | |
run: | | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.TAG_GITHUB_PAT }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/workflows/141828151/dispatches \ | |
-d '{"ref":"main","inputs":{"environment":"${{ inputs.environment }}"}}' | |
scheduled_sync_gitbook_docs: | |
name: Sync gitbook Docs to S3 (scheduled on prod) | |
if: github.event_name == 'schedule' | |
runs-on: ubuntu-latest | |
outputs: | |
environment: 'prod' | |
environment: 'prod' | |
steps: | |
- name: Checkout current repository | |
uses: actions/checkout@v4 | |
- name: Checkout devportal-docs repo | |
uses: actions/checkout@v4 | |
with: | |
repository: pagopa/devportal-docs | |
ref: docs/from-gitbook | |
path: devportal-docs | |
- name: Setup Node.JS | |
uses: ./.github/actions/setup-node | |
- name: Cache npm dependencies | |
id: cache-npm | |
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Install dependencies | |
run: | | |
npm config set cache ~/.npm | |
npm ci | |
- name: Compile packages | |
run: npm run compile | |
- name: Generate UrlReplace metadata | |
env: | |
ENVIRONMENT: 'prod' | |
DOCUMENTATION_PATH: ${{ vars.DOCUMENTATION_PATH || '../../devportal-docs/docs' }} | |
URL_PARSING_METADATA_JSON_PATH: ${{ vars.URL_PARSING_METADATA_JSON_PATH || '../../url-parsing-metadata.json' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
run: npm run generate-url-parsing-metadata -w gitbook-docs | |
- name: Replace urls and include tags in docs | |
env: | |
ENVIRONMENT: 'prod' | |
DOCUMENTATION_PATH: ${{ vars.DOCUMENTATION_PATH || '../../devportal-docs/docs' }} | |
URL_PARSING_METADATA_JSON_PATH: ${{ vars.URL_PARSING_METADATA_JSON_PATH || '../../url-parsing-metadata.json' }} | |
run: npm run parse-docs -w gitbook-docs | |
- name: Configure AWS Credentials | |
uses: ./.github/actions/configure-aws-credentials | |
with: | |
aws_region: eu-south-1 | |
role_to_assume: ${{ secrets.DEPLOY_IAM_ROLE }} | |
- name: Sync docs folder to S3 | |
working-directory: ./devportal-docs | |
run: | | |
aws s3 sync docs s3://devportal-p-website-static-content/devportal-docs/docs --delete --size-only | |
- name: Generate guides metadata | |
env: | |
ENVIRONMENT: 'prod' | |
S3_BUCKET_NAME: devportal-p-website-static-content | |
S3_DOC_EXTRACTION_BUCKET_NAME: ${{ vars.S3_DOC_EXTRACTION_BUCKET_NAME }} | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-guides-metadata -w gitbook-docs | |
- name: Generate solutions metadata | |
env: | |
ENVIRONMENT: 'prod' | |
S3_BUCKET_NAME: devportal-p-website-static-content | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-solutions-metadata -w gitbook-docs | |
- name: Generate release notes metadata | |
env: | |
ENVIRONMENT: 'prod' | |
S3_BUCKET_NAME: devportal-p-website-static-content | |
S3_DOC_EXTRACTION_BUCKET_NAME: ${{ vars.S3_DOC_EXTRACTION_BUCKET_NAME }} | |
S3_PATH_TO_GITBOOK_DOCS: ${{ vars.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs' }} | |
STRAPI_ENDPOINT: ${{ vars.STRAPI_ENDPOINT }} | |
STRAPI_API_TOKEN: ${{ secrets.STRAPI_API_TOKEN }} | |
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }} | |
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }} | |
run: npm run generate-release-notes-metadata -w gitbook-docs | |
- name: Invalidate CloudFront asset bucket cache | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id ${{ vars.ASSET_BUCKET_CLOUDFRONT_DISTRIBUTION_ID }} \ | |
--paths "/*" | |
- name: Trigger reindex workflow | |
run: | | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.TAG_GITHUB_PAT }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/workflows/141828151/dispatches \ | |
-d '{"ref":"main","inputs":{"environment":"prod"}}' |