Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Remove unnecessary locales downloads from CI (#4627)

Olga Bulat6a700504123c
diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml
index e00f58f38..8d3b39ec9 100644
--- a/.github/actions/build-docs/action.yml
+++ b/.github/actions/build-docs/action.yml
@@ -17,11 +17,6 @@ runs:
# Pass -W to fail CI if warnings exist
just documentation/build -W
- - name: Install translations
- shell: bash
- run: |
- just frontend/run i18n
-
- name: Build Storybook
shell: bash
run: |
diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml
index bdd74252f..febd1f4b8 100644
--- a/.github/actions/setup-env/action.yml
+++ b/.github/actions/setup-env/action.yml
@@ -10,6 +10,10 @@ inputs:
default: "true"
description: Whether to set up Node.js and dependencies
+ locales:
+ default: ""
+ description: The locales to set up. "test" for copying from `frontend/test/locales`, "production" for downloading from GlotPress.
+
install_recipe:
default: "install"
description: The recipe to use to install dependencies
@@ -62,3 +66,10 @@ runs:
shell: bash
run: |
just ${{ inputs.install_recipe }}
+
+ # Set up locales
+ - name: Setup locales
+ if: inputs.locales != ''
+ shell: bash
+ run: |
+ just locales ${{ inputs.locales }}
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 5a7aeb378..b3b7f5782 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -165,6 +165,7 @@ jobs:
setup_python: false
setup_nodejs: ${{ matrix.image == 'frontend' && 'true' || 'false' }}
install_recipe: ${{ matrix.image == 'frontend' && 'node-install' || '' }}
+ locales: ${{ matrix.image == 'frontend' && 'production' || '' }}
# Sets build args specifying versions needed to build Docker image.
- name: Prepare build args
@@ -172,15 +173,6 @@ jobs:
run: |
just versions | tee "$GITHUB_OUTPUT"
- # ℹ️Step only applies for frontend image.
- # This step
- # - downloads translation strings from GlotPress so that they can be
- # bundled inside the Docker image
- - name: Prepare frontend for building
- if: matrix.image == 'frontend'
- run: |
- just frontend/run i18n
-
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
@@ -669,9 +661,12 @@ jobs:
with:
setup_python: false
install_recipe: node-install
+ locales: "production"
- name: Run build
run: just frontend/run build
+ env:
+ DEPLOYMENT_ENV: production
nuxt-checks:
name: Run Nuxt checks
@@ -706,6 +701,7 @@ jobs:
with:
setup_python: false
install_recipe: node-install
+ locales: "test"
- name: Run check recipe
run: just ${{ matrix.recipe }}
@@ -818,6 +814,7 @@ jobs:
with:
setup_python: false
install_recipe: node-install
+ locales: "test"
- name: Run Playwright tests
run: just frontend/run ${{ matrix.script }} --workers=2
diff --git a/frontend/Dockerfile b/frontend/Dockerfile
index 592e2ef15..6520bde24 100644
--- a/frontend/Dockerfile
+++ b/frontend/Dockerfile
@@ -35,7 +35,7 @@ ENV SKIP_PRE_COMMIT=true
# Get rid of the lockfile as it won't be accurate for the build without workspace.
# Then install dependencies, and in the process:
# - fix the missing lockfile by writing a new one
-RUN pnpm install
+RUN pnpm install && pnpm i18n
# disable telemetry when building the app
ENV NUXT_TELEMETRY_DISABLED=1
@@ -44,7 +44,7 @@ ENV SENTRY_DSN=https://[email protected]
ARG API_URL
-RUN pnpm build:only
+RUN pnpm build
############
# Nuxt app #
diff --git a/frontend/bin/playwright.sh b/frontend/bin/playwright.sh
index 8a69edda3..cdfa8a6b6 100755
--- a/frontend/bin/playwright.sh
+++ b/frontend/bin/playwright.sh
@@ -11,8 +11,6 @@ PLAYWRIGHT_VERSION=$(version)
export PLAYWRIGHT_VERSION
export TEST_COMMAND="${TEST_COMMAND:-test:playwright:local}"
-pnpm i18n:get-translations --en-only
-
echo Running Playwright v"$PLAYWRIGHT_VERSION" as "$USER_ID" with Playwright arguments "$PLAYWRIGHT_ARGS"
docker compose -f docker-compose.playwright.yml up --build --force-recreate --exit-code-from playwright --remove-orphans
diff --git a/frontend/package.json b/frontend/package.json
index bae1ab02d..5b90f9849 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -9,20 +9,18 @@
"dev": "run-p dev:only 'i18n:en --watch'",
"dev:only": "nuxt --hostname 0.0.0.0",
"dev:secure": "LOCAL_SSL=enabled pnpm dev",
- "prebuild": "pnpm install && pnpm i18n",
- "build": "pnpm build:only",
- "build:only": "nuxt build",
+ "build": "nuxt build",
"build:clean": "rm -rf .nuxt",
"docker:build": "docker build . -t openverse-frontend:latest",
"docker:run": "docker run --rm -it -p 127.0.0.1:8443:8443/tcp openverse-frontend:latest",
"generate": "nuxt generate",
"start": "nuxt start",
"start:playwright": "pnpm i18n:copy-test-locales && pnpm start",
- "prod": "pnpm build:only && pnpm start",
+ "prod": "pnpm build && pnpm start",
"prod:playwright": "pnpm i18n:copy-test-locales && pnpm prod",
"storybook": "NODE_OPTIONS=--openssl-legacy-provider nuxt storybook --port=54000",
- "storybook:build": "nuxt storybook build",
- "storybook:build-for-docs": "NODE_OPTIONS=--openssl-legacy-provider nuxt storybook build",
+ "storybook:build": "pnpm i18n:copy-test-locales && NODE_OPTIONS=--openssl-legacy-provider nuxt storybook build",
+ "storybook:build-for-docs": "pnpm install & pnpm i18n:en && NODE_OPTIONS=--openssl-legacy-provider nuxt storybook build",
"talkback": "node ./test/proxy.js",
"pretest": "pnpm install",
"test": "pnpm test:unit && pnpm test:playwright",
diff --git a/frontend/src/locales/scripts/get-translations.js b/frontend/src/locales/scripts/get-translations.js
index b1faf01d3..627406585 100644
--- a/frontend/src/locales/scripts/get-translations.js
+++ b/frontend/src/locales/scripts/get-translations.js
@@ -3,7 +3,7 @@
* convert to our JSON format, and save in the correct folder.
*/
-const { writeFileSync } = require("fs")
+const { writeFileSync, existsSync } = require("fs")
const os = require("os")
const chokidar = require("chokidar")
@@ -43,4 +43,12 @@ if (!process.argv.includes("--en-only")) {
process.exitCode = 1
}
})
+} else {
+ // Create valid-locales.json if it doesn't exist. It is required for Nuxt to build the app.
+ const validLocalesFilePath =
+ process.cwd() + "/src/locales/scripts/valid-locales.json"
+ if (!existsSync(validLocalesFilePath)) {
+ writeFileSync(validLocalesFilePath, "[]")
+ console.log("Created empty valid-locales.json.")
+ }
}
diff --git a/justfile b/justfile
index a83c05f96..786fa49c4 100644
--- a/justfile
+++ b/justfile
@@ -51,7 +51,18 @@ DC_USER := env_var_or_default("DC_USER", "opener")
node-install:
pnpm i
just frontend/run i18n:en
- just frontend/run i18n:copy-test-locales
+
+
+# Set up locales for the frontend
+locales mode="test":
+ #! /usr/bin/env bash
+ if [ "{{ mode }}" = "production" ]; then
+ just frontend/run i18n
+ elif [ "{{ mode }}" = "test" ]; then
+ just frontend/run i18n:copy-test-locales
+ else
+ echo "Invalid mode {{ mode }}. Using only the `en` locale. To set up more locales, use 'production' or 'test'."
+ fi
# Install Python dependences for the monorepo
py-install: