From 5be2bc73604a2aafebc8642098bb24acd55cf00f Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 17 Jan 2025 14:39:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(actions)=20create=20a=20reus?= =?UTF-8?q?able=20workflow=20to=20install=20front=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In more than one workflow we need to install frontend dependencies and this 3 workflows we are copy/pasting the same code. We want to refactor this by creating a reusable workflow https://docs.github.com/en/actions/sharing-automations/reusing-workflows --- .github/workflows/crowdin_download.yml | 20 ++----- .github/workflows/crowdin_upload.yml | 21 +++---- .../front-dependencies-installation.yml | 36 ++++++++++++ .github/workflows/impress-frontend.yml | 58 +++++++------------ 4 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/front-dependencies-installation.yml diff --git a/.github/workflows/crowdin_download.yml b/.github/workflows/crowdin_download.yml index 85d8c65a..6d9355cb 100644 --- a/.github/workflows/crowdin_download.yml +++ b/.github/workflows/crowdin_download.yml @@ -7,6 +7,11 @@ on: - 'release/**' jobs: + install-front: + uses: ./.github/workflows/front-dependencies-installation.yml + with: + node_version: '20.x' + synchronize-with-crowdin: runs-on: ubuntu-latest permissions: @@ -41,25 +46,12 @@ jobs: CROWDIN_BASE_PATH: "../src/" # frontend i18n - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.x" - name: Restore the frontend cache - uses: actions/cache@v4 - id: front-node_modules - with: - path: "src/frontend/**/node_modules" - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} - - name: Install dependencies - if: steps.front-node_modules.outputs.cache-hit != 'true' - run: cd src/frontend/ && yarn install --frozen-lockfile - - name: Cache install frontend - if: steps.front-node_modules.outputs.cache-hit != 'true' uses: actions/cache@v4 with: path: "src/frontend/**/node_modules" key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + fail-on-cache-miss: true - name: generate translations files working-directory: src/frontend run: yarn i18n:deploy diff --git a/.github/workflows/crowdin_upload.yml b/.github/workflows/crowdin_upload.yml index c004c2f1..e35731f2 100644 --- a/.github/workflows/crowdin_upload.yml +++ b/.github/workflows/crowdin_upload.yml @@ -7,7 +7,13 @@ on: - main jobs: + install-front: + uses: ./.github/workflows/front-dependencies-installation.yml + with: + node_version: '20.x' + synchronize-with-crowdin: + needs: install-front runs-on: ubuntu-latest steps: @@ -32,25 +38,12 @@ jobs: run: | DJANGO_CONFIGURATION=Build python manage.py makemessages -a --keep-pot # frontend i18n - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.x" - name: Restore the frontend cache - uses: actions/cache@v4 - id: front-node_modules - with: - path: "src/frontend/**/node_modules" - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} - - name: Install dependencies - if: steps.front-node_modules.outputs.cache-hit != 'true' - run: cd src/frontend/ && yarn install --frozen-lockfile - - name: Cache install frontend - if: steps.front-node_modules.outputs.cache-hit != 'true' uses: actions/cache@v4 with: path: "src/frontend/**/node_modules" key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + fail-on-cache-miss: true - name: generate source translation file working-directory: src/frontend run: yarn i18n:extract diff --git a/.github/workflows/front-dependencies-installation.yml b/.github/workflows/front-dependencies-installation.yml new file mode 100644 index 00000000..33bb3c43 --- /dev/null +++ b/.github/workflows/front-dependencies-installation.yml @@ -0,0 +1,36 @@ +name: Install frontend installation reusable workflow + +on: + workflow_call: + inputs: + node_version: + required: false + default: '20.x' + type: string + +jobs: + front-dependencies-installation: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Restore the frontend cache + uses: actions/cache@v4 + id: front-node_modules + with: + path: "src/frontend/**/node_modules" + key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + - name: Setup Node.js + if: steps.front-node_modules.outputs.cache-hit != 'true' + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + - name: Install dependencies + if: steps.front-node_modules.outputs.cache-hit != 'true' + run: cd src/frontend/ && yarn install --frozen-lockfile + - name: Cache install frontend + if: steps.front-node_modules.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: "src/frontend/**/node_modules" + key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} diff --git a/.github/workflows/impress-frontend.yml b/.github/workflows/impress-frontend.yml index 8bc32e68..ae07bf2b 100644 --- a/.github/workflows/impress-frontend.yml +++ b/.github/workflows/impress-frontend.yml @@ -9,39 +9,15 @@ on: - "*" jobs: + install-front: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.x" - - - name: Restore the frontend cache - uses: actions/cache@v4 - id: front-node_modules - with: - path: "src/frontend/**/node_modules" - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} - - - name: Install dependencies - if: steps.front-node_modules.outputs.cache-hit != 'true' - run: cd src/frontend/ && yarn install --frozen-lockfile - - - name: Cache install frontend - if: steps.front-node_modules.outputs.cache-hit != 'true' - uses: actions/cache@v4 - with: - path: "src/frontend/**/node_modules" - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + uses: ./.github/workflows/front-dependencies-installation.yml + with: + node_version: '20.x' test-front: - runs-on: ubuntu-latest needs: install-front + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 @@ -53,10 +29,10 @@ jobs: - name: Restore the frontend cache uses: actions/cache@v4 - id: front-node_modules with: path: "src/frontend/**/node_modules" key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + fail-on-cache-miss: true - name: Test App run: cd src/frontend/ && yarn test @@ -68,29 +44,39 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" - name: Restore the frontend cache uses: actions/cache@v4 - id: front-node_modules with: path: "src/frontend/**/node_modules" key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + fail-on-cache-miss: true - name: Check linting run: cd src/frontend/ && yarn lint test-e2e-chromium: runs-on: ubuntu-latest + needs: install-front timeout-minutes: 20 steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + - name: Restore the frontend cache uses: actions/cache@v4 - id: front-node_modules with: path: "src/frontend/**/node_modules" key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + fail-on-cache-miss: true - name: Set e2e env variables run: cat env.d/development/common.e2e.dist >> env.d/development/common.dist @@ -141,12 +127,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Restore the frontend cache - uses: actions/cache@v4 - id: front-node_modules - with: - path: "src/frontend/**/node_modules" - key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }} + - name: Install frontend dependencies + uses: ./.github/workflows/front-dependencies-installation.yml - name: Set e2e env variables run: cat env.d/development/common.e2e.dist >> env.d/development/common.dist