Skip to content

Commit

Permalink
ci: simplify (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Nov 8, 2024
1 parent 4c22a10 commit a060887
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 44 deletions.
60 changes: 60 additions & 0 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: 'Setup Node.js'
description: 'Setup Node and install dependencies using cache'
inputs:
save-cache:
description: 'Save cache when needed'
required: false
default: 'false'

runs:
using: 'composite'

steps:
- name: ⚙️ Calculate `CACHE_KEY`
shell: bash
run: |
echo 'CACHE_KEY=node_modules-${{
hashFiles('.node-version', 'pnpm-lock.yaml')
}}' >> "$GITHUB_ENV"
- name: ♻️ Restore `node_modules`
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
id: node-modules-restore
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true

- name: Calculate `CACHE_HIT`
shell: bash
run: |
echo 'CACHE_HIT=${{
(steps.node-modules-restore.outputs.cache-hit == 'true') && 'true' || ''
}}' >> "$GITHUB_ENV"
- name: ⚙️ Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
standalone: true

- name: ⚙️ Setup Node.js ${{ inputs.node-version }}
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: .node-version
cache: ${{ env.CACHE_HIT != 'true' && 'pnpm' || '' }}

- name: 📥 Install dependencies
if: env.CACHE_HIT != 'true'
shell: bash
run: pnpm install --frozen-lockfile
env:
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install

- name: ♻️ Write `node_modules` cache
if: inputs.save-cache == 'true' && env.CACHE_HIT != 'true'
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
enableCrossOsArchive: true
71 changes: 28 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ concurrency:
cancel-in-progress: true

env:
NODE_VERSION: 20
RENOVATE_VERSION: 38.142.7 # renovate: datasource=docker depName=renovate packageName=ghcr.io/renovatebot/renovate

jobs:
prepare:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false

- name: 📥 Setup Node.js
uses: ./.github/actions/setup-node
with:
save-cache: true

commitlint:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }}
Expand All @@ -31,6 +44,8 @@ jobs:
continue-on-error: true

lint:
needs:
- prepare
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }}

Expand All @@ -40,24 +55,15 @@ jobs:
with:
show-progress: false

- name: enable corepack
run: corepack enable

- name: Setup node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: 📥 Setup Node.js
uses: ./.github/actions/setup-node

- name: enable corepack
run: corepack enable

- name: Install project
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint

e2e:
needs:
- prepare
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.repository_owner != github.event.pull_request.head.repo.owner.login }}

Expand All @@ -73,20 +79,8 @@ jobs:
with:
show-progress: false

- name: enable corepack
run: corepack enable

- name: Setup node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm

- name: enable corepack
run: corepack enable

- name: Install project
run: pnpm install --frozen-lockfile
- name: 📥 Setup Node.js
uses: ./.github/actions/setup-node

- name: Build
run: pnpm build
Expand Down Expand Up @@ -121,7 +115,10 @@ jobs:
docker-user: root

release:
needs: [lint, commitlint, e2e]
needs:
- lint
- commitlint
- e2e
runs-on: ubuntu-latest
steps:
- name: Setup Git user
Expand Down Expand Up @@ -150,20 +147,8 @@ jobs:
git merge --no-ff -Xtheirs -m 'skip: merge (${{ github.sha }}) [skip release]' ${{ github.sha }}
commit=$(git rev-parse HEAD)
- name: enable corepack
run: corepack enable

- name: Setup node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm

- name: enable corepack
run: corepack enable

- name: Install project
run: pnpm install --frozen-lockfile
- name: 📥 Setup Node.js
uses: ./.github/actions/setup-node

- name: Push release branch
run: git push origin release:release
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.18.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"packageManager": "pnpm@9.12.3",
"engines": {
"node": ">=20.9.0",
"node": "^20.9.0 || ^22.11.0",
"pnpm": "^9.0.0"
},
"pnpm": {
Expand Down

0 comments on commit a060887

Please sign in to comment.