Skip to content

Commit 5be2bc7

Browse files
committed
♻️(actions) create a reusable workflow to install front dependencies
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
1 parent e46ba4f commit 5be2bc7

File tree

4 files changed

+69
-66
lines changed

4 files changed

+69
-66
lines changed

.github/workflows/crowdin_download.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
- 'release/**'
88

99
jobs:
10+
install-front:
11+
uses: ./.github/workflows/front-dependencies-installation.yml
12+
with:
13+
node_version: '20.x'
14+
1015
synchronize-with-crowdin:
1116
runs-on: ubuntu-latest
1217
permissions:
@@ -41,25 +46,12 @@ jobs:
4146

4247
CROWDIN_BASE_PATH: "../src/"
4348
# frontend i18n
44-
- name: Setup Node.js
45-
uses: actions/setup-node@v4
46-
with:
47-
node-version: "20.x"
4849
- name: Restore the frontend cache
49-
uses: actions/cache@v4
50-
id: front-node_modules
51-
with:
52-
path: "src/frontend/**/node_modules"
53-
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
54-
- name: Install dependencies
55-
if: steps.front-node_modules.outputs.cache-hit != 'true'
56-
run: cd src/frontend/ && yarn install --frozen-lockfile
57-
- name: Cache install frontend
58-
if: steps.front-node_modules.outputs.cache-hit != 'true'
5950
uses: actions/cache@v4
6051
with:
6152
path: "src/frontend/**/node_modules"
6253
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
54+
fail-on-cache-miss: true
6355
- name: generate translations files
6456
working-directory: src/frontend
6557
run: yarn i18n:deploy

.github/workflows/crowdin_upload.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ on:
77
- main
88

99
jobs:
10+
install-front:
11+
uses: ./.github/workflows/front-dependencies-installation.yml
12+
with:
13+
node_version: '20.x'
14+
1015
synchronize-with-crowdin:
16+
needs: install-front
1117
runs-on: ubuntu-latest
1218

1319
steps:
@@ -32,25 +38,12 @@ jobs:
3238
run: |
3339
DJANGO_CONFIGURATION=Build python manage.py makemessages -a --keep-pot
3440
# frontend i18n
35-
- name: Setup Node.js
36-
uses: actions/setup-node@v4
37-
with:
38-
node-version: "20.x"
3941
- name: Restore the frontend cache
40-
uses: actions/cache@v4
41-
id: front-node_modules
42-
with:
43-
path: "src/frontend/**/node_modules"
44-
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
45-
- name: Install dependencies
46-
if: steps.front-node_modules.outputs.cache-hit != 'true'
47-
run: cd src/frontend/ && yarn install --frozen-lockfile
48-
- name: Cache install frontend
49-
if: steps.front-node_modules.outputs.cache-hit != 'true'
5042
uses: actions/cache@v4
5143
with:
5244
path: "src/frontend/**/node_modules"
5345
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
46+
fail-on-cache-miss: true
5447
- name: generate source translation file
5548
working-directory: src/frontend
5649
run: yarn i18n:extract
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Install frontend installation reusable workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node_version:
7+
required: false
8+
default: '20.x'
9+
type: string
10+
11+
jobs:
12+
front-dependencies-installation:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Restore the frontend cache
18+
uses: actions/cache@v4
19+
id: front-node_modules
20+
with:
21+
path: "src/frontend/**/node_modules"
22+
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
23+
- name: Setup Node.js
24+
if: steps.front-node_modules.outputs.cache-hit != 'true'
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ inputs.node_version }}
28+
- name: Install dependencies
29+
if: steps.front-node_modules.outputs.cache-hit != 'true'
30+
run: cd src/frontend/ && yarn install --frozen-lockfile
31+
- name: Cache install frontend
32+
if: steps.front-node_modules.outputs.cache-hit != 'true'
33+
uses: actions/cache@v4
34+
with:
35+
path: "src/frontend/**/node_modules"
36+
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}

.github/workflows/impress-frontend.yml

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,15 @@ on:
99
- "*"
1010

1111
jobs:
12-
install-front:
13-
runs-on: ubuntu-latest
14-
15-
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v4
18-
19-
- name: Setup Node.js
20-
uses: actions/setup-node@v4
21-
with:
22-
node-version: "20.x"
23-
24-
- name: Restore the frontend cache
25-
uses: actions/cache@v4
26-
id: front-node_modules
27-
with:
28-
path: "src/frontend/**/node_modules"
29-
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
30-
31-
- name: Install dependencies
32-
if: steps.front-node_modules.outputs.cache-hit != 'true'
33-
run: cd src/frontend/ && yarn install --frozen-lockfile
3412

35-
- name: Cache install frontend
36-
if: steps.front-node_modules.outputs.cache-hit != 'true'
37-
uses: actions/cache@v4
38-
with:
39-
path: "src/frontend/**/node_modules"
40-
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
13+
install-front:
14+
uses: ./.github/workflows/front-dependencies-installation.yml
15+
with:
16+
node_version: '20.x'
4117

4218
test-front:
43-
runs-on: ubuntu-latest
4419
needs: install-front
20+
runs-on: ubuntu-latest
4521
steps:
4622
- name: Checkout repository
4723
uses: actions/checkout@v4
@@ -53,10 +29,10 @@ jobs:
5329

5430
- name: Restore the frontend cache
5531
uses: actions/cache@v4
56-
id: front-node_modules
5732
with:
5833
path: "src/frontend/**/node_modules"
5934
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
35+
fail-on-cache-miss: true
6036

6137
- name: Test App
6238
run: cd src/frontend/ && yarn test
@@ -68,29 +44,39 @@ jobs:
6844
- name: Checkout repository
6945
uses: actions/checkout@v4
7046

47+
- name: Setup Node.js
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: "20.x"
7151
- name: Restore the frontend cache
7252
uses: actions/cache@v4
73-
id: front-node_modules
7453
with:
7554
path: "src/frontend/**/node_modules"
7655
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
56+
fail-on-cache-miss: true
7757

7858
- name: Check linting
7959
run: cd src/frontend/ && yarn lint
8060

8161
test-e2e-chromium:
8262
runs-on: ubuntu-latest
63+
needs: install-front
8364
timeout-minutes: 20
8465
steps:
8566
- name: Checkout repository
8667
uses: actions/checkout@v4
8768

69+
- name: Setup Node.js
70+
uses: actions/setup-node@v4
71+
with:
72+
node-version: "20.x"
73+
8874
- name: Restore the frontend cache
8975
uses: actions/cache@v4
90-
id: front-node_modules
9176
with:
9277
path: "src/frontend/**/node_modules"
9378
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
79+
fail-on-cache-miss: true
9480

9581
- name: Set e2e env variables
9682
run: cat env.d/development/common.e2e.dist >> env.d/development/common.dist
@@ -141,12 +127,8 @@ jobs:
141127
- name: Checkout repository
142128
uses: actions/checkout@v4
143129

144-
- name: Restore the frontend cache
145-
uses: actions/cache@v4
146-
id: front-node_modules
147-
with:
148-
path: "src/frontend/**/node_modules"
149-
key: front-node_modules-${{ hashFiles('src/frontend/**/yarn.lock') }}
130+
- name: Install frontend dependencies
131+
uses: ./.github/workflows/front-dependencies-installation.yml
150132

151133
- name: Set e2e env variables
152134
run: cat env.d/development/common.e2e.dist >> env.d/development/common.dist

0 commit comments

Comments
 (0)