Skip to content

Commit

Permalink
feat(ZCH-126): added caching for dotnet and node
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-sartori-zupit committed Nov 22, 2024
1 parent 37b1238 commit ddd88cd
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 164 deletions.
16 changes: 12 additions & 4 deletions .github/actions/dotnet/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ inputs:
SHELL:
required: false
type: string
default: 'bash'
default: "bash"
CACHE_SUFFIX:
required: false
type: string
default: ""

runs:
using: composite
steps:
- name: Create folder if not exist
shell: bash
run: mkdir -p ~/.nuget/packages${{ inputs.CACHE_SUFFIX }}

- 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${{ inputs.CACHE_SUFFIX }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}

- name: Restore dependencies
shell: ${{ inputs.SHELL }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/dotnet-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ on:
required: false
type: string
default: "all"
CACHE_SUFFIX:
required: false
type: string
default: ""

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}
Expand Down Expand Up @@ -96,10 +100,11 @@ jobs:
CSHARPIER_VERSION: ${{ inputs.CSHARPIER_VERSION }}

- name: Build
uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@v1.24.0
uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@ZCH-126/caching
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
BUILD_CONFIG: "Debug"
CACHE_SUFFIX: ${{ inputs.CACHE_SUFFIX }}

- name: Lint
uses: zupit-it/pipeline-templates/.github/actions/dotnet/[email protected]
Expand Down
59 changes: 29 additions & 30 deletions .github/workflows/node-step-format-lint-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,40 +45,39 @@ 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
- uses: actions/checkout@v4
with:
fetch-depth: 0

# 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: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.NODE_VERSION }}
cache: "npm"
cache-dependency-path: "**/*/package-lock.json"

- name: Authenticate with private NPM package
if: ${{ env.github_token }}
run: echo "//npm.pkg.github.com/:_authToken=${{ env.github_token }}" > ~/.npmrc
- name: Authenticate with private NPM package
if: ${{ env.github_token }}
run: echo "//npm.pkg.github.com/:_authToken=${{ env.github_token }}" > ~/.npmrc

- run: npm ci
- run: npm ci

# GENERIC
- run: npm run ci:format:check
if: ${{ inputs.PROJECT == '' }}
# GENERIC
- run: npm run ci:format:check
if: ${{ inputs.PROJECT == '' }}

- run: npm run ci:lint
if: ${{ inputs.PROJECT == '' }}
- run: npm run ci:lint
if: ${{ inputs.PROJECT == '' }}

- run: npm run ci:build
if: ${{ inputs.PROJECT == '' }}
- run: npm run ci:build
if: ${{ inputs.PROJECT == '' }}

# PROJECT SPECIFIC
- run: npm run ${{ inputs.PROJECT }}:ci:format:check
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:lint
if: ${{ inputs.PROJECT != '' }}

- run: npm run ${{ inputs.PROJECT }}:ci:build
if: ${{ inputs.PROJECT != '' }}
- run: npm run ${{ inputs.PROJECT }}:ci:build
if: ${{ inputs.PROJECT != '' }}
9 changes: 6 additions & 3 deletions .github/workflows/sonar-step-dotnet-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ on:
required: false
type: string
default: "all"
CACHE_SUFFIX:
required: false
type: string
default: ""

env:
CHECK_DIR: ${{ inputs.WORKING_DIRECTORY }}
Expand Down Expand Up @@ -102,8 +106,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/[email protected]
Expand Down Expand Up @@ -135,10 +137,11 @@ jobs:
"${params[@]}"
- name: Build
uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@v1.24.0
uses: zupit-it/pipeline-templates/.github/actions/dotnet/build@ZCH-126/caching
with:
WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }}
BUILD_CONFIG: "Debug"
CACHE_SUFFIX: ${{ inputs.CACHE_SUFFIX }}

- name: Run tests
uses: zupit-it/pipeline-templates/.github/actions/dotnet/[email protected]
Expand Down
Loading

0 comments on commit ddd88cd

Please sign in to comment.