From d57cdae115fe0155fe1229dcceb649081e416855 Mon Sep 17 00:00:00 2001 From: literat Date: Thu, 19 Sep 2024 18:29:45 +0200 Subject: [PATCH] Refactor(ci): Move Node.js setup and deps installation into separate action * it also includes a better caching of node_modules --- .github/actions/action.yaml | 27 +++++++++++++++++++++++ .github/workflows/commitlint.yaml | 13 ++--------- .github/workflows/component-analysis.yaml | 13 ++--------- .github/workflows/e2e.yml | 13 ++--------- .github/workflows/publish.yaml | 13 ++--------- .github/workflows/test-web-twig.yaml | 13 ++--------- .github/workflows/test.yaml | 16 ++------------ 7 files changed, 39 insertions(+), 69 deletions(-) create mode 100644 .github/actions/action.yaml diff --git a/.github/actions/action.yaml b/.github/actions/action.yaml new file mode 100644 index 0000000000..65b871eb32 --- /dev/null +++ b/.github/actions/action.yaml @@ -0,0 +1,27 @@ +name: 'setup and install' +description: 'Setup Node and Install Dependencies' +runs: + using: 'composite' + steps: + - name: Enable Corepack + shell: bash + run: corepack enable + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + cache-dependency-path: yarn.lock + + - name: Restore cached node_modules + uses: actions/cache@v4 + with: + path: '**/node_modules' + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + shell: bash + run: yarn --immutable --inline-builds diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml index 509693cc86..7f5f1f24d5 100644 --- a/.github/workflows/commitlint.yaml +++ b/.github/workflows/commitlint.yaml @@ -13,17 +13,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install - name: Run Commitlint run: yarn lint:commit diff --git a/.github/workflows/component-analysis.yaml b/.github/workflows/component-analysis.yaml index 9d046da1a4..383ff68282 100644 --- a/.github/workflows/component-analysis.yaml +++ b/.github/workflows/component-analysis.yaml @@ -15,17 +15,8 @@ jobs: # Omlet.dev uses Git History for analysis; Disable shallow clone fetch-depth: 0 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install - name: Analyze run: npx omlet analyze diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 820057b8b8..e5a0a0c73c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -41,17 +41,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install # Wait for the Netlify preview URL to be ready - name: Wait for Netlify Deploy diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3373ecd038..fc116ae674 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -16,17 +16,8 @@ jobs: - name: Clone repository uses: actions/checkout@v4 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node.js - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install - name: Build run: yarn build diff --git a/.github/workflows/test-web-twig.yaml b/.github/workflows/test-web-twig.yaml index 1bde5be70c..e7385143cb 100644 --- a/.github/workflows/test-web-twig.yaml +++ b/.github/workflows/test-web-twig.yaml @@ -21,17 +21,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install - name: Build Icons working-directory: ./packages/icons diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f9551d0f17..4fd4379e8e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -20,20 +20,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Enable Corepack - run: corepack enable - - - name: Configure Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Fetch Git history - run: git fetch --no-tags --depth=50 origin main - - - name: Install dependencies - run: yarn --immutable --inline-builds + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-install - name: Build run: yarn build