From 8861b7f50f7cdfbe0d38641d1b982deea6566f2e Mon Sep 17 00:00:00 2001 From: Luca Sartori Date: Tue, 1 Oct 2024 23:49:35 +0200 Subject: [PATCH] fix: better caching --- .github/actions/dotnet/build/action.yml | 18 +++--- .../workflows/node-step-format-lint-build.yml | 62 ++++++++----------- 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/.github/actions/dotnet/build/action.yml b/.github/actions/dotnet/build/action.yml index aac2bb3a..5bf6dae6 100644 --- a/.github/actions/dotnet/build/action.yml +++ b/.github/actions/dotnet/build/action.yml @@ -15,19 +15,21 @@ inputs: runs: using: composite steps: - - name: List NuGet cache size - run: | - du -h ~/.nuget/packages | sort -hr | head -n 20 + - 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 - # key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + # key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} # restore-keys: ${{ runner.os }}-nuget- - # retention-days: 30 + path: ~/.nuget/packages-carbon + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: ${{ runner.os }}-nuget- - 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 4c06db61..b0b215a0 100644 --- a/.github/workflows/node-step-format-lint-build.yml +++ b/.github/workflows/node-step-format-lint-build.yml @@ -6,11 +6,11 @@ on: RUN_ON: required: false type: string - default: 'zupit-agents' + default: "zupit-agents" RUNNERS_CONTAINER_GROUP: required: false type: string - default: 'Container' + default: "Container" NODE_VERSION: required: true type: string @@ -30,7 +30,7 @@ on: type: string default: "ubuntu:23.04" -env: "${{secrets}}" +env: "${{ secrets }}" jobs: lint-check-build: @@ -45,40 +45,32 @@ jobs: working-directory: ${{ inputs.WORKING_DIRECTORY }} steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ inputs.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ inputs.NODE_VERSION }} -# cache: 'npm' -# cache-dependency-path: ${{ inputs.WORKING_DIRECTORY }}/package-lock.json + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history - # Set NPM cache directory to a new clean directory to avoid sharing with other runners - - name: Set NPM cache directory - run: echo "NPM_CONFIG_CACHE=~/.npm$(npm -v)" >> $GITHUB_ENV + - name: Ensure necessary packages are installed + run: | + apt-get update + apt-get install -y unzip git + git config --global --add safe.directory "$GITHUB_WORKSPACE" + shell: bash - - name: Authenticate with private NPM package - if: ${{ env.github_token }} - run: echo "//npm.pkg.github.com/:_authToken=${{ env.github_token }}" > ~/.npmrc + - name: Checkout repository again + uses: actions/checkout@v4 + with: + fetch-depth: 0 - - run: npm ci + - name: Use bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: v1.1.29 - # GENERIC - - run: npm run ci:format:check - if: ${{ inputs.PROJECT == '' }} + - name: Install Dependencies + env: + BUN_AUTH_TOKEN: ${{ env.github_token }} + run: bun install --frozen-lockfile - - run: npm run ci:lint - if: ${{ inputs.PROJECT == '' }} - - - run: npm run ci:build - if: ${{ inputs.PROJECT == '' }} - - # PROJECT SPECIFIC - - run: npm run ${{ inputs.PROJECT }}:ci:format:check - if: ${{ inputs.PROJECT != '' }} - - - run: npm run ${{ inputs.PROJECT }}:ci:lint - if: ${{ inputs.PROJECT != '' }} - - - run: npm run ${{ inputs.PROJECT }}:ci:build - if: ${{ inputs.PROJECT != '' }} + - name: Run affected lint and build + run: bun nx affected -t lint build --base=origin/main --head=HEAD