Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1b8977e
Add optimized GitBook sync workflow and metadata synchronization script
github-user-name Sep 30, 2025
e6a384e
autolaunch
github-user-name Sep 30, 2025
5f02245
remove trigger
github-user-name Sep 30, 2025
3ccea38
Add Strapi response interfaces for guide and solution list pages
github-user-name Oct 8, 2025
c20a346
Refactor metadata synchronization script: remove unused S3 caching, i…
github-user-name Oct 8, 2025
7a8f642
Add query parameters for Strapi data fetching: enhance population for…
github-user-name Oct 20, 2025
f6751a3
Add Strapi product and API data interfaces: enhance data fetching and…
github-user-name Oct 20, 2025
f7a1c04
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 Oct 22, 2025
2a7deeb
Refactor S3 sync step in GitBook docs workflow: move sync command to …
github-user-name Oct 23, 2025
34a62d7
Refactor S3_PRODUCTS_METADATA_JSON_PATH declaration: streamline forma…
github-user-name Oct 23, 2025
cef00e0
Resolve merge conflicts in package.json and guidesMetadataHelper.ts
github-user-name Oct 28, 2025
1ede24d
Refactor GitBook sync workflow to enhance metadata generation and AWS…
github-user-name Oct 28, 2025
08f01ee
Fix import issues in syncAllMetadata.ts and optimize workflow
github-user-name Oct 28, 2025
332a95a
Merge branch 'main' into optimize-gitbook-sync
tommaso1 Oct 28, 2025
d2e291f
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 Oct 30, 2025
a501550
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 Oct 30, 2025
c0a7cc9
Merge branch 'main' into optimize-gitbook-sync
marcobottaro Oct 30, 2025
233f658
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 Oct 30, 2025
27f7d87
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 Oct 30, 2025
379baa9
Merge branch 'main' into optimize-gitbook-sync
tommaso1 Oct 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-ears-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gitbook-docs": patch
---

Optimize GitBook sync workflow to reduce API calls and improve performance
220 changes: 220 additions & 0 deletions .github/workflows/sync_gitbook_docs_optimized.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tommaso1 i added a step in [CAI-612] which generates and saves on the s3 bucket two files (response from fetchFromStrapi for products and api-datas) and the sitemap.xml. Please don't forget to add the same step here (or in sync all metadata, where is more fitting)

Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
name: Sync GitBook Docs (Optimized)

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
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:
id-token: write
contents: read

jobs:
manual_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
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: Configure AWS Credentials
uses: ./.github/actions/configure-aws-credentials
with:
aws_region: eu-south-1
role_to_assume: ${{ secrets.DEPLOY_IAM_ROLE }}

- name: Generate all metadata
env:
ENVIRONMENT: ${{ inputs.environment }}
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 }}
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' }}
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }}
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }}
GENERATE_URL_METADATA: 'true'
GENERATE_SITEMAP_METADATA: 'true'
SAVE_STRAPI_RESPONSES: 'true'
METADATA_TYPE: ${{ inputs.metadata_type }}
run: npm run sync-all-metadata -w gitbook-docs

- name: Replace urls and include tags in docs
if: inputs.generate_metadata_only == false
env:
ENVIRONMENT: ${{ inputs.environment }}
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: 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: 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 "/*"

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: Configure AWS Credentials
uses: ./.github/actions/configure-aws-credentials
with:
aws_region: eu-south-1
role_to_assume: ${{ secrets.DEPLOY_IAM_ROLE }}

- name: Generate all 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 }}
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' }}
NEXT_PUBLIC_COGNITO_REGION: ${{ vars.NEXT_PUBLIC_COGNITO_REGION || 'eu-south-1' }}
FETCH_FROM_STRAPI: ${{ vars.FETCH_FROM_STRAPI || 'true' }}
GENERATE_URL_METADATA: 'true'
GENERATE_SITEMAP_METADATA: 'true'
SAVE_STRAPI_RESPONSES: 'true'
METADATA_TYPE: 'all'
run: npm run sync-all-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: 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: Invalidate CloudFront asset bucket cache
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ vars.ASSET_BUCKET_CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/*"
3 changes: 2 additions & 1 deletion packages/gitbook-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"fetch-soap-api-from-strapi": "ts-node src/scripts/generateSoapApiRepositoriesList.ts",
"generate-url-parsing-metadata": "ts-node src/scripts/generateUrlParsingMetadata.ts",
"generate-strapi-response-files": "ts-node src/scripts/generateStrapiResponseFiles.ts",
"parse-docs": "ts-node src/scripts/parseDocUrlsAndIncludes.ts"
"parse-docs": "ts-node src/scripts/parseDocUrlsAndIncludes.ts",
"sync-all-metadata": "ts-node src/scripts/syncAllMetadata.ts"
},
"dependencies": {
"@markdoc/markdoc": "0.3.0",
Expand Down
Loading
Loading