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 Bhanushalice9b7c7448a7
diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml
new file mode 100644
index 000000000..dc1634436
--- /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/workflows/lint.yml b/.github/workflows/lint.yml
index 1403bf0a9..f89592d42 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -21,27 +21,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- - name: Setup just
- uses: extractions/setup-just@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
- - name: Setup Python
- uses: actions/setup-python@v4
- with:
- python-version: "3.10"
-
- - name: Setup pnpm
- uses: pnpm/[email protected]
-
- - name: Setup Node.js
- uses: actions/setup-node@v3
+ - name: Setup CI env
+ uses: ./.github/actions/setup-env
with:
- node-version: 16
- cache: pnpm
- cache-dependency-path: |
- pnpm-lock.yaml
- .npmrc
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ # Python is not needed to run pre-commit.
+ setup_python: false
+ # Node.js is needed to check rendered templates.
+ install_recipe: automations/js/install
- name: Cache pre-commit envs
uses: actions/cache@v3
@@ -51,6 +38,5 @@ jobs:
- name: Run pre-commit to lint files
run: |
- just automations/js/install
just precommit
just lint