From f374e2b355a1811432c69558b3f9f20010b95226 Mon Sep 17 00:00:00 2001 From: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 27 Feb 2025 12:07:14 -0800 Subject: [PATCH] Try matrix build strategy Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .github/workflows/deploy.yml | 80 ++++++++++++++++++++++++++++++++--- .gitignore | 1 + docusaurus.config.ts | 1 + package.json | 1 + src/plugins/output-locales.ts | 25 +++++++++++ 5 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/plugins/output-locales.ts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7285624..3514498 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,7 +26,7 @@ concurrency: cancel-in-progress: true jobs: - build: + sync: name: Deploy to GitHub Pages runs-on: ubuntu-latest steps: @@ -41,9 +41,6 @@ jobs: with: fetch-depth: 0 - - name: Setup Pages - uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b - - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af with: node-version: 22 @@ -78,13 +75,84 @@ jobs: env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - - name: Build website - run: yarn build + - name: Get locales + run: yarn output-locales + + - name: Define matrix + id: locales + run: echo "locales=$(cat locales.json)" >> $GITHUB_ENV + + build: + runs-on: ubuntu-latest + needs: sync + strategy: + matrix: + locales: ${{ fromJson(needs.sync.outputs.locales) }} + steps: + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version: 22 + + - name: Enable Corepack + run: corepack enable + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version: 22 + cache: yarn + + - name: Install dependencies + run: yarn install --immutable + + - uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 + with: + path: | + ${{ github.workspace }}/.docusaurus + ${{ github.workspace }}/**/.cache + key: | + ${{ runner.os }}-docusaurus-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} + restore-keys: | + ${{ runner.os }}-docusaurus-${{ hashFiles('**/yarn.lock') }} + + - name: Build Locale + run: yarn build --locale ${{ matrix.locales }} + + - name: Upload artifact + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 + with: + path: build + name: ${{ matrix.locales }} + + combine: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + + - name: Setup Pages + uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b + + - name: Download artifacts + uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 + with: + path: build + + - name: Move default locale to root build + run: | + mv build/en/* build/ + rm -rf build/en - name: Upload artifact uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa with: path: build + deploy: environment: name: github-pages diff --git a/.gitignore b/.gitignore index 627f2ff..ef4d8fe 100755 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ vendor .env.development.local .env.test.local .env.production.local +locales.json npm-debug.log* yarn-debug.log* diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 918632d..633b802 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -120,6 +120,7 @@ const config: Config = { jsonKeyExclusions: [ 'providers.provider.' ] } ], + './src/plugins/output-locales.ts', './src/plugins/modify-webpack.ts', ], themes: ["docusaurus-theme-openapi-docs"], diff --git a/package.json b/package.json index 82224be..7e80465 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "gen-all": "docusaurus gen-api-docs all && docusaurus gen-api-docs:version petstore_versioned:all", "clean-all": "docusaurus clean-api-docs all && docusaurus clean-api-docs:version petstore_versioned:all", "crowdin-sync": "docusaurus crowdin-sync", + "output-locales": "docusaurus output-locales", "re-gen": "yarn clean-all && yarn gen-all", "typecheck": "tsc" }, diff --git a/src/plugins/output-locales.ts b/src/plugins/output-locales.ts new file mode 100644 index 0000000..b1c2868 --- /dev/null +++ b/src/plugins/output-locales.ts @@ -0,0 +1,25 @@ +import fs from 'fs'; +import path from 'path'; +import {LoadContext, Plugin, PluginOptions} from '@docusaurus/types'; + +const PLUGIN_NAME = 'docusaurus-plugin-output-locales'; + +const ouputLocalesPlugin = (context: LoadContext, options: PluginOptions): Plugin => { + return { + name: PLUGIN_NAME, + extendCli(cli) { + cli + .command('output-locales') + .description('Sync translations with Crowdin') + .action(async () => { + fs.writeFileSync( + path.join(context.siteDir, 'locales.json'), + JSON.stringify(context.siteConfig.i18n.locales), + 'utf-8' + ) + }); + } + }; +} + +export default ouputLocalesPlugin; \ No newline at end of file