-
Notifications
You must be signed in to change notification settings - Fork 1
[DEV-2583] Add optimized GitBook sync workflow and metadata synchronization script #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tommaso1
wants to merge
20
commits into
main
Choose a base branch
from
optimize-gitbook-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,651
−1
Open
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 e6a384e
autolaunch
github-user-name 5f02245
remove trigger
github-user-name 3ccea38
Add Strapi response interfaces for guide and solution list pages
github-user-name c20a346
Refactor metadata synchronization script: remove unused S3 caching, i…
github-user-name 7a8f642
Add query parameters for Strapi data fetching: enhance population for…
github-user-name f6751a3
Add Strapi product and API data interfaces: enhance data fetching and…
github-user-name f7a1c04
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 2a7deeb
Refactor S3 sync step in GitBook docs workflow: move sync command to …
github-user-name 34a62d7
Refactor S3_PRODUCTS_METADATA_JSON_PATH declaration: streamline forma…
github-user-name cef00e0
Resolve merge conflicts in package.json and guidesMetadataHelper.ts
github-user-name 1ede24d
Refactor GitBook sync workflow to enhance metadata generation and AWS…
github-user-name 08f01ee
Fix import issues in syncAllMetadata.ts and optimize workflow
github-user-name 332a95a
Merge branch 'main' into optimize-gitbook-sync
tommaso1 d2e291f
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 a501550
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 c0a7cc9
Merge branch 'main' into optimize-gitbook-sync
marcobottaro 233f658
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 27f7d87
Update .github/workflows/sync_gitbook_docs_optimized.yaml
tommaso1 379baa9
Merge branch 'main' into optimize-gitbook-sync
tommaso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 |
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
| 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 "/*" |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)