Skip to content

Commit

Permalink
build(workflow): same node version on all stages (#1319)
Browse files Browse the repository at this point in the history
Motivation
----------
We have completely different `node --version`s on local development,
build server (even in different jobs) and production.

My suggestion is that we configure the node version in a central file in
the root folder and reference it from everywhere.

For me, any version manager is fine. If I have the choice, I suggest
[asdf-vm]](https://github.com/asdf-vm/asdf).

How to test
-----------
1. Check status checks
  • Loading branch information
roschaefer authored Jul 9, 2024
1 parent ba2d51c commit 149db22
Show file tree
Hide file tree
Showing 21 changed files with 400 additions and 258 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/admin.deploy.chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
runs-on: ubuntu-latest
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN_ADMIN }}
WORKING_DIRECTORY: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Admin | Build
run: npm install && npm run chromatic -- --exit-zero-on-changes
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./admin
52 changes: 22 additions & 30 deletions .github/workflows/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@ jobs:
name: Build - Admin
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Admin | Build
run: npm install && npm run build
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./admin

docker-production:
if: needs.files-changed.outputs.admin == 'true'
name: Build Docker Production - Admin
needs: files-changed
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: Admin | Build Docker Production
run: docker compose -f docker-compose.yml build admin

Expand All @@ -50,9 +47,7 @@ jobs:
needs: files-changed
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: Admin | Build Docker Development
run: docker compose build admin admin-storybook

Expand All @@ -61,42 +56,39 @@ jobs:
name: Build Storybook - Admin
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Admin | Build Storybook
run: npm install && npm run storybook:build
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./admin

lint:
if: needs.files-changed.outputs.admin == 'true'
name: Lint - Admin
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Admin | Lint
run: npm install && npm run test:lint
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./admin

unit:
if: needs.files-changed.outputs.admin == 'true'
name: Unit - Admin
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./admin
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Admin | Unit
run: npm install && npm run test:unit
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./admin
50 changes: 14 additions & 36 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,22 @@ jobs:
name: Build - Backend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./backend
steps:
- name: Set Node version
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '>=21'

- name: Checkout code
uses: actions/checkout@v4

node-version-file: './.tool-versions'
- name: Backend | Build
run: npm install && npm run build
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./backend

docker-production:
if: needs.files-changed.outputs.backend == 'true'
name: Build Docker Production - Backend
needs: files-changed
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: Backend | Build Docker Production
run: docker compose -f docker-compose.yml build backend

Expand All @@ -56,9 +48,7 @@ jobs:
needs: files-changed
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: Backend | Build Docker Development
run: docker compose build backend

Expand All @@ -67,41 +57,29 @@ jobs:
name: Lint - Backend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./backend
steps:
- name: Set Node version
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '>=21'

- name: Checkout code
uses: actions/checkout@v4

node-version-file: './.tool-versions'
- name: Backend | Lint
run: npm install && npm run test:lint
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./backend

unit:
if: needs.files-changed.outputs.backend == 'true'
name: Unit - Backend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./backend
DATABASE_URL: mysql://root:@localhost:3306/dreammall.earth
steps:
- name: Set Node version
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '>=21'

- name: Checkout code
uses: actions/checkout@v4

node-version-file: './.tool-versions'
- name: Backend | docker-compose database
run: docker-compose -f docker-compose.yml up --detach --no-deps database

- name: Backend | Unit
run: npm install && cp src/auth/public.pem . && npm run db:migrate && npm run test:unit
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./backend
12 changes: 4 additions & 8 deletions .github/workflows/deploy.docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Set Node version
uses: actions/setup-node@v4
- uses: actions/checkout@master
- uses: actions/setup-node@v4
with:
node-version: '>=21'

- name: Checkout
uses: actions/checkout@master

node-version-file: './.tool-versions'
- name: vuepress-deploy
uses: IT4Change/vuepress-build-and-deploy@master
env:
Expand All @@ -28,4 +24,4 @@ jobs:
#TARGET_BRANCH: master
BUILD_SCRIPT: npm install && npm run docs:build
BUILD_DIR: build/docs/
VUEPRESS_BASE: "dreammall.earth"
VUEPRESS_BASE: "dreammall.earth"
10 changes: 4 additions & 6 deletions .github/workflows/e2e.run.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ jobs:
name: Run all E2E tests
runs-on: ubuntu-latest
steps:
- name: Set Node version
uses: actions/setup-node@v4
with:
node-version: 21
- uses: actions/checkout@master

- name: Checkout
uses: actions/checkout@master
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'

- name: E2E | Boot up test system
run: |
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ jobs:
name: Lint - E2E files
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./tests
steps:
- name: Set Node version
uses: actions/setup-node@v4
with:
node-version: '>=21'
- uses: actions/checkout@master

- name: Checkout code
uses: actions/checkout@master
- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'

- name: E2E files | Lint
run: npm install && npm run test:lint
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./tests
10 changes: 5 additions & 5 deletions .github/workflows/frontend.deploy.chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
runs-on: ubuntu-latest
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN_FRONTEND }}
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: './.tool-versions'
- name: Frontend | Build
run: npm install && npm run chromatic -- --exit-zero-on-changes
working-directory: ${{env.WORKING_DIRECTORY}}
working-directory: ./frontend
Loading

0 comments on commit 149db22

Please sign in to comment.