Skip to content

Commit

Permalink
Try matrix build strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle committed Feb 27, 2025
1 parent 163a667 commit f374e2b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 6 deletions.
80 changes: 74 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ concurrency:
cancel-in-progress: true

jobs:
build:
sync:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ vendor
.env.development.local
.env.test.local
.env.production.local
locales.json

npm-debug.log*
yarn-debug.log*
Expand Down
1 change: 1 addition & 0 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
25 changes: 25 additions & 0 deletions src/plugins/output-locales.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit f374e2b

Please sign in to comment.