Skip to content

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

Create and use action to set up CI env

Dhruv Bhanushali1f37ce1c2152
diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml
new file mode 100644
index 000000000..c6668ac3f
--- /dev/null
+++ b/.github/actions/setup-env/action.yml
@@ -0,0 +1,77 @@
+name: openverse/setup-env
+description: Setup Openverse CI environment
+
+inputs:
+ setup_python:
+ default: "true"
+ description: Whether to set up Python and install dependencies
+
+ setup_nodejs:
+ default: "true"
+ description: Whether to set up Node.js and dependencies
+
+ install_deps:
+ default: "true"
+ description: Whether to install dependencies using Just
+
+ github_token:
+ required: true
+ description: The token to authenticate calls to the GitHub API
+
+ install_recipe:
+ default: "install"
+ description: The recipe to use to install dependencies
+
+runs:
+ using: "composite"
+ steps:
+ # Just
+ - name: Setup just
+ uses: extractions/setup-just@v1
+ env:
+ GITHUB_TOKEN: ${{ inputs.github_token }}
+
+ # Python
+ - name: Setup Python
+ if: inputs.setup_python == 'true'
+ uses: actions/setup-python@v4
+ with:
+ # Ensure that it matches `python_version` field in the following files:
+ # - `automations/python/Pipfile`
+ # - `dead_links/Pipfile`
+ python-version: "3.10"
+ cache: pipenv
+ cache-dependency-path: |
+ **/Pipfile.lock
+
+ - name: Setup global Python deps
+ if: inputs.setup_python == 'true'
+ shell: bash
+ run: |
+ pip install -U pip
+ pip install pipenv
+
+ # Node.js
+ - name: Setup pnpm
+ if: inputs.setup_nodejs == 'true'
+ uses: pnpm/action-setup@v2
+ # Automatically reads `packageManager` field from root `package.json`.
+
+ - name: Setup Node.js
+ if: inputs.setup_nodejs == 'true'
+ uses: actions/setup-node@v3
+ with:
+ # Ensure that it matches `engines` field in the following files:
+ # - `package.json`
+ node-version: "16"
+ cache: pnpm
+ cache-dependency-path: |
+ **/pnpm-lock.yaml
+ **/.npmrc
+
+ # Install dependencies
+ - name: Install dependencies
+ if: inputs.install_deps == 'true'
+ shell: bash
+ run: |
+ just ${{ inputs.install_recipe }}
diff --git a/.github/actions/setup-node-env/action.yml b/.github/actions/setup-node-env/action.yml
deleted file mode 100644
index b278435f4..000000000
--- a/.github/actions/setup-node-env/action.yml
+++ /dev/null
@@ -1,37 +0,0 @@
-name: openverse-frontend/setup-node-env
-description: Setup the Node.js environment including `pnpm` and dependencies
-
-inputs:
- install:
- default: true
- description: Whether to install dependencies.
-
-runs:
- using: "composite"
- steps:
- - uses: pnpm/[email protected]
-
- - name: Cache pnpm modules
- uses: actions/cache@v3
- with:
- path: ~/.local/share/pnpm/store
- key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- restore-keys: |
- ${{ runner.os }}-
-
- - uses: actions/[email protected]
- with:
- node-version: 16
- cache: pnpm
- cache-dependency-path: |
- pnpm-lock.yaml
- .npmrc
-
- - name: Install
- if: inputs.install
- shell: bash
- run: "pnpm install"
-
- - name: Copy locale files
- shell: bash
- run: "cp -r test/locales/* src/locales"
diff --git a/.github/workflows/bundle_size.yml b/.github/workflows/bundle_size.yml
index 289d784b9..cd2e6e81c 100644
--- a/.github/workflows/bundle_size.yml
+++ b/.github/workflows/bundle_size.yml
@@ -36,16 +36,23 @@ jobs:
if: github.repository == 'WordPress/openverse-frontend'
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- uses: preactjs/[email protected]
with:
- repo-token: "${{ secrets.GITHUB_TOKEN }}"
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
# Only measure changes in the client, we don't care much about the size of the server bundles (I don't think?)
- pattern: "./.nuxt/dist/client/**/*.{modern.js,js,css}"
- exclude: "{./.nuxt/dist/client/lang-*.json.js,./.nuxt/dist/client/lang-*.json.modern.js}"
+ pattern: "./frontend/.nuxt/dist/client/**/*.{modern.js,js,css}"
+ exclude: "{./frontend/.nuxt/dist/client/lang-*.json.js,./frontend/.nuxt/dist/client/lang-*.json.modern.js}"
minimum-change-threshold: 10
+
+ - name: Checkout repository # again, to enable cleaning
+ if: always()
+ uses: actions/checkout@v3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 11ea2115f..0acd2a7ff 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -22,36 +22,61 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Check types
- run: pnpm types
+ run: just frontend/run types
lint:
name: Lint files
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ # Python is not needed to run pre-commit.
+ setup_python: false
+ # Node.js is needed by lint actions.
+
+ - name: Cache pre-commit envs
+ uses: actions/cache@v3
+ with:
+ path: ~/.cache/pre-commit
+ key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- - name: Lint with ESLint and Prettier
- run: pnpm pc:lint
+ - name: Run pre-commit to lint files
+ run: |
+ just precommit
+ just lint
unit:
name: Unit tests
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run unit tests
- run: pnpm test:unit
+ run: just frontend/run test:unit
clean-playwright-failure-comment:
name: Remove previous Playwright test failure comments
@@ -81,12 +106,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run Nuxt Playwright e2e tests
- run: pnpm test:playwright e2e --workers=2
+ run: just frontend/run test:playwright e2e --workers=2
- uses: actions/upload-artifact@v3
if: failure()
@@ -99,12 +129,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run Nuxt Playwright visual regression tests
- run: pnpm test:playwright visual-regression --workers=2
+ run: just frontend/run test:playwright visual-regression --workers=2
- uses: actions/upload-artifact@v3
if: failure()
@@ -117,12 +152,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run Storybook Playwright tests
- run: pnpm test:storybook
+ run: just frontend/run test:storybook
- uses: actions/upload-artifact@v3
if: failure()
@@ -160,24 +200,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run Storybook smoke-test
- run: pnpm storybook:smoke
+ run: just frontend/run storybook:smoke
build:
name: Check Nuxt build
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - name: Checkout repository
+ uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Run build
- run: pnpm build
+ run: just frontend/run build
gh-pages:
name: PR Storybook and Tailwind Preview
@@ -208,25 +258,29 @@ jobs:
**Storybook and Tailwind configuration previews**: _Updating_
(This comment will be automatically updated with the preview URLs once they are ready)
- - name: Checkout
+ - name: Checkout repository
uses: actions/checkout@v3
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Fetch translation files
- run: pnpm i18n
+ run: just frontend/run i18n
- name: Build Storybook
- run: pnpm storybook:build
+ run: just frontend/run storybook:build
- name: Build Tailwind Config Viewer
- run: pnpm tcv:build
+ run: just frontend/run tcv:build
# This makes the TCV available at the `/tailwind` directory in the gh-pages
- name: Merge TCV and Storybook builds
run: |
- mv .tcv-export ./storybook-static/tailwind
- mv ./storybook-static /tmp/preview
+ mv frontend/.tcv-export frontend/storybook-static/tailwind
+ mv frontend/storybook-static /tmp/preview
# Otherwise we end up with `node_modules` and other things only necessary for building
# but not necessary for deploying the `gh-pages` branch
@@ -236,7 +290,8 @@ jobs:
rm -rf openverse-frontend
mkdir openverse-frontend
- - uses: actions/checkout@v3
+ - name: Checkout repository at `gh-pages` branch
+ uses: actions/checkout@v3
with:
ref: gh-pages
@@ -277,6 +332,6 @@ jobs:
You can check [the GitHub pages deployment action list](https://github.com/WordPress/openverse-frontend/actions/workflows/pages/pages-build-deployment) to see the current status of the deployments.
- - name: Checkout branch again to enable cleaning
- uses: actions/checkout@v3
+ - name: Checkout repository # again, to enable cleaning.
if: always()
+ uses: actions/checkout@v3
diff --git a/.github/workflows/generate_pot.yml b/.github/workflows/generate_pot.yml
index 79105b48e..68aea0a4f 100644
--- a/.github/workflows/generate_pot.yml
+++ b/.github/workflows/generate_pot.yml
@@ -13,22 +13,22 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- - name: Checkout
+ - name: Checkout repository
uses: actions/checkout@v3
- with:
- ref: main
- - uses: ./.github/actions/setup-node-env
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Generate PO
- run: pnpm i18n:generate-pot
+ run: just frontend/run i18n:generate-pot
- name: Copy to root
- run: cp ./openverse.pot /tmp/openverse.pot
+ run: cp frontend/openverse.pot /tmp/openverse.pot
- - name: Checkout `translations` branch
+ - name: Checkout repository at `translations` branch
uses: actions/checkout@v3
with:
ref: translations
@@ -42,7 +42,6 @@ jobs:
git commit --no-verify -am 'Update POT file'
git push --no-verify
- - name: Re-checkout `main` branch to allow for cleanup to work
+ - name: Checkout repository # again, to enable cleaning.
+ if: always()
uses: actions/checkout@v3
- with:
- ref: main
diff --git a/.github/workflows/gh-pages.yaml b/.github/workflows/gh-pages.yaml
index b0fe9e2af..27ec48e42 100644
--- a/.github/workflows/gh-pages.yaml
+++ b/.github/workflows/gh-pages.yaml
@@ -14,31 +14,31 @@ jobs:
name: Deploy GitHub pages
runs-on: ubuntu-latest
steps:
- - name: Checkout
+ - name: Checkout repository
uses: actions/checkout@v3
- with:
- ref: main
- - uses: ./.github/actions/setup-node-env
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Fetch translation files
- run: pnpm i18n
+ run: just frontend/run i18n
- name: Build Storybook
- run: pnpm storybook:build
+ run: just frontend/run storybook:build
- name: Build Tailwind Config Viewer
- run: pnpm tcv:build
+ run: just frontend/run tcv:build
# This makes the TCV available at the `/tailwind` directory in the gh-pages
- name: Merge TCV and Storybook builds
run: |
- mv .tcv-export ./storybook-static/tailwind
- mv storybook-static /tmp/gh-pages
+ mv frontend/.tcv-export frontend/storybook-static/tailwind
+ mv frontend/storybook-static /tmp/gh-pages
- - name: Checkout
+ - name: Checkout repository at `gh-pages` branch
uses: actions/checkout@v3
with:
ref: gh-pages
@@ -53,8 +53,6 @@ jobs:
publish_dir: /tmp/gh-pages
force_orphan: true
- - name: Checkout branch again to enable cleaning
+ - name: Checkout repository # again, to enable cleaning.
if: always()
uses: actions/checkout@v3
- with:
- ref: main
diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml
index a72cb417d..46af4657a 100644
--- a/.github/workflows/ghcr.yml
+++ b/.github/workflows/ghcr.yml
@@ -38,10 +38,14 @@ jobs:
with:
ref: ${{ github.event.release.tag_name }}
- - uses: ./.github/actions/setup-node-env
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ setup_python: false
- name: Download translation strings
- run: pnpm i18n
+ run: just frontend/run i18n
env:
GLOTPRESS_USERNAME: ${{ secrets.MAKE_USERNAME }}
GLOTPRESS_PASSWORD: ${{ secrets.MAKE_LOGIN_PASSWORD }}
@@ -83,7 +87,7 @@ jobs:
- uses: docker/build-push-action@v4
with:
- context: .
+ context: frontend/
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
push: true
diff --git a/package.json b/package.json
index cff776b26..ba162e267 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,9 @@
"url": "https://github.com/WordPress/openverse/issues"
},
"author": "Openverse <[email protected]>",
+ "scripts": {
+ "build": "just frontend/run build"
+ },
"packageManager": "[email protected]",
"engines": {
"node": ">= 16.0.0 <17",