From 4f2ca2bb194d37a2dcaf9897dc049eabb10c21f5 Mon Sep 17 00:00:00 2001 From: luca-sartori-zupit Date: Fri, 4 Oct 2024 08:41:20 +0200 Subject: [PATCH] chore: parallelize --- .github/actions/dotnet/build/action.yml | 9 +- .../workflows/node-step-format-lint-build.yml | 138 +++++++++++++++--- .../workflows/sonar-step-dotnet-analyze.yml | 4 +- 3 files changed, 123 insertions(+), 28 deletions(-) diff --git a/.github/actions/dotnet/build/action.yml b/.github/actions/dotnet/build/action.yml index 5bf6dae..d80422f 100644 --- a/.github/actions/dotnet/build/action.yml +++ b/.github/actions/dotnet/build/action.yml @@ -18,18 +18,13 @@ runs: - name: Create folder if not exist shell: bash run: mkdir -p ~/.nuget/packages-carbon - - name: List NuGet carbon cache size - shell: bash - run: du -h ~/.nuget/packages-carbon | sort -hr | head -n 20 + - name: Restore NuGet packages cache uses: actions/cache@v3 with: - # path: ~/.nuget/packages - # key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - # restore-keys: ${{ runner.os }}-nuget- path: ~/.nuget/packages-carbon key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - restore-keys: ${{ runner.os }}-nuget- + restore-keys: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - name: Restore dependencies shell: ${{ inputs.SHELL }} diff --git a/.github/workflows/node-step-format-lint-build.yml b/.github/workflows/node-step-format-lint-build.yml index 9b55373..36082a2 100644 --- a/.github/workflows/node-step-format-lint-build.yml +++ b/.github/workflows/node-step-format-lint-build.yml @@ -1,4 +1,4 @@ -name: Lint, check and build a Javascript app +name: Lint, Check, and Build a JavaScript App on: workflow_call: @@ -33,7 +33,7 @@ on: env: "${{ secrets }}" jobs: - lint-check-build: + setup: if: ${{ inputs.RUN }} runs-on: labels: ${{ inputs.RUN_ON }} @@ -45,34 +45,136 @@ jobs: working-directory: ${{ inputs.WORKING_DIRECTORY }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.NODE_VERSION }} + cache: "npm" + cache-dependency-path: "**/*/package-lock.json" + + - run: npm ci + + # Pack the node_modules directory as an artifact + - name: Save node_modules as an artifact + run: | + tar -czf node_modules.tar.gz node_modules + ls -lart + - name: Upload artifact + uses: actions/upload-artifact@v3 + run: | + ls -lart + with: + name: node_modules + path: node_modules.tar.gz + + lint: + needs: setup + runs-on: + labels: ${{ inputs.RUN_ON }} + group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} + container: + image: ${{ inputs.IMAGE }} + defaults: + run: + working-directory: ${{ inputs.WORKING_DIRECTORY }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: ${{ inputs.NODE_VERSION }} - cache: 'npm' - cache-dependency-path: '**/*/package-lock.json' - - name: Install git + # Download the node_modules artifact + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: node_modules + - run: tar -xzf node_modules.tar.gz + + - name: Run linting run: | - apt-get update && apt-get install -y git + if [ "${{ inputs.PROJECT }}" = "" ]; then + npm run ci:lint + else + npm run ${{ inputs.PROJECT }}:ci:lint + fi - - name: Checkout repository - uses: actions/checkout@v4 + format-check: + needs: setup + runs-on: + labels: ${{ inputs.RUN_ON }} + group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} + container: + image: ${{ inputs.IMAGE }} + defaults: + run: + working-directory: ${{ inputs.WORKING_DIRECTORY }} + + steps: + - uses: actions/checkout@v4 with: fetch-depth: 0 - path: ${{ github.workspace }} - - name: Install Dependencies - env: - NODE_AUTH_TOKEN: ${{ env.github_token }} - run: npm ci - shell: bash + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.NODE_VERSION }} + + # Download the node_modules artifact + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: node_modules + - run: tar -xzf node_modules.tar.gz + + - name: Run format check + run: | + if [ "${{ inputs.PROJECT }}" = "" ]; then + npm run ci:format:check + else + npm run ${{ inputs.PROJECT }}:ci:format:check + fi - - name: Run affected lint and build - run: npx nx affected -t lint build --base=origin/main --head=HEAD + build: + needs: setup + runs-on: + labels: ${{ inputs.RUN_ON }} + group: ${{ inputs.RUNNERS_CONTAINER_GROUP }} + container: + image: ${{ inputs.IMAGE }} + defaults: + run: + working-directory: ${{ inputs.WORKING_DIRECTORY }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.NODE_VERSION }} + + # Download the node_modules artifact + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: node_modules + - run: tar -xzf node_modules.tar.gz + + - name: Run build + run: | + if [ "${{ inputs.PROJECT }}" = "" ]; then + npm run ci:build + else + npm run ${{ inputs.PROJECT }}:ci:build + fi diff --git a/.github/workflows/sonar-step-dotnet-analyze.yml b/.github/workflows/sonar-step-dotnet-analyze.yml index 2e35bfd..190f247 100644 --- a/.github/workflows/sonar-step-dotnet-analyze.yml +++ b/.github/workflows/sonar-step-dotnet-analyze.yml @@ -102,8 +102,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Install .NET uses: zupit-it/pipeline-templates/.github/actions/dotnet/install@v1.23.2 @@ -135,7 +133,7 @@ jobs: "${params[@]}" - name: Build - uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@v1.23.2 + uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@chore/better-caching with: WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }} BUILD_CONFIG: "Debug"