Ver Fonte

DRY GHA workflows (#4294)

Chris Estreich há 6 meses atrás
pai
commit
314ccca1f7

+ 38 - 0
.github/actions/setup-node-pnpm/action.yml

@@ -0,0 +1,38 @@
+name: "Setup Node.js and pnpm"
+
+description: "Sets up Node.js and pnpm with caching and installs dependencies"
+
+inputs:
+    node-version:
+        description: "Node.js version to use"
+        required: false
+        default: "20.19.2"
+    pnpm-version:
+        description: "pnpm version to use"
+        required: false
+        default: "10.8.1"
+    skip-install:
+        description: "Skip dependency installation"
+        required: false
+        default: "false"
+    install-args:
+        description: "Additional arguments for pnpm install"
+        required: false
+        default: ""
+
+runs:
+    using: "composite"
+    steps:
+        - name: Install pnpm
+          uses: pnpm/action-setup@v4
+          with:
+              version: ${{ inputs.pnpm-version }}
+        - name: Setup Node.js
+          uses: actions/setup-node@v4
+          with:
+              node-version: ${{ inputs.node-version }}
+              cache: "pnpm"
+        - name: Install dependencies
+          if: ${{ inputs.skip-install != 'true' }}
+          shell: bash
+          run: pnpm install ${{ inputs.install-args }}

+ 3 - 13
.github/workflows/changeset-release.yml

@@ -9,8 +9,6 @@ on:
 env:
   REPO_PATH: ${{ github.repository }}
   GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
-  NODE_VERSION: 20.19.2
-  PNPM_VERSION: 10.8.1
 
 jobs:
   # Job 1: Create version bump PR when changesets are merged to main
@@ -31,18 +29,10 @@ jobs:
         with:
           fetch-depth: 0
           ref: ${{ env.GIT_REF }}
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
         with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-            
-      - name: Install Dependencies
-        run: pnpm install
+          skip-checkout: 'true'
 
       # Check if there are any new changesets to process
       - name: Check for changesets

+ 10 - 59
.github/workflows/code-qa.yml

@@ -8,27 +8,14 @@ on:
     types: [opened, reopened, ready_for_review, synchronize]
     branches: [main]
 
-env:
-  NODE_VERSION: 20.19.2
-  PNPM_VERSION: 10.8.1
-
 jobs:
   check-translations:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Verify all translations are complete
         run: node scripts/find-missing-translations.js
 
@@ -37,17 +24,8 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Run knip checks
         run: pnpm knip
 
@@ -56,17 +34,8 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Lint
         run: pnpm lint
       - name: Check types
@@ -80,17 +49,8 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Run unit tests
         run: pnpm test
 
@@ -116,17 +76,8 @@ jobs:
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Create .env.local file
         working-directory: apps/vscode-e2e
         run: echo "OPENROUTER_API_KEY=${{ secrets.OPENROUTER_API_KEY }}" > .env.local

+ 3 - 12
.github/workflows/marketplace-publish.yml

@@ -7,8 +7,6 @@ on:
 
 env:
   GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
-  NODE_VERSION: 20.19.2
-  PNPM_VERSION: 10.8.1
 
 jobs:
   publish-extension:
@@ -25,17 +23,10 @@ jobs:
         uses: actions/checkout@v4
         with:
           ref: ${{ env.GIT_REF }}
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
         with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install
+          skip-checkout: 'true'
       - name: Configure Git
         run: |
           git config user.name "github-actions[bot]"

+ 4 - 14
.github/workflows/nightly-publish.yml

@@ -8,10 +8,6 @@ on:
     branches: [main]
   workflow_dispatch: # Allows manual triggering.
 
-env:
-  NODE_VERSION: 20.19.2
-  PNPM_VERSION: 10.8.1
-
 jobs:
   publish-nightly:
     runs-on: ubuntu-latest
@@ -25,17 +21,11 @@ jobs:
         uses: actions/checkout@v4
         with:
           fetch-depth: 0
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
         with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
-      - name: Install dependencies
-        run: pnpm install --frozen-lockfile
+          skip-checkout: 'true'
+          install-args: '--frozen-lockfile'
       - name: Forge numeric Nightly version
         id: version
         env:

+ 5 - 18
.github/workflows/update-contributors.yml

@@ -4,36 +4,23 @@ on:
   push:
     branches:
       - main
-  workflow_dispatch:  # Allows manual triggering
-
-env:
-  NODE_VERSION: 20.19.2
-  PNPM_VERSION: 10.8.1
+  workflow_dispatch:
 
 jobs:
   update-contributors:
     runs-on: ubuntu-latest
     permissions:
-      contents: write  # Needed for pushing changes
-      pull-requests: write  # Needed for creating PRs
+      contents: write  # Needed for pushing changes.
+      pull-requests: write  # Needed for creating PRs.
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
-      - name: Install pnpm
-        uses: pnpm/action-setup@v4
-        with:
-          version: ${{ env.PNPM_VERSION }}
-      - name: Setup Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: ${{ env.NODE_VERSION }}
-          cache: 'pnpm'
+      - name: Setup Node.js and pnpm
+        uses: ./.github/actions/setup-node-pnpm
       - name: Disable Husky
         run: |
           echo "HUSKY=0" >> $GITHUB_ENV
           git config --global core.hooksPath /dev/null
-      - name: Install dependencies
-        run: pnpm install
       - name: Update contributors and format
         run: |
           pnpm update-contributors