Skip to content

Commit

Permalink
chore: parallelize
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-sartori-zupit committed Oct 6, 2024
1 parent 09f12bb commit 4f2ca2b
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 28 deletions.
9 changes: 2 additions & 7 deletions .github/actions/dotnet/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
138 changes: 120 additions & 18 deletions .github/workflows/node-step-format-lint-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint, check and build a Javascript app
name: Lint, Check, and Build a JavaScript App

on:
workflow_call:
Expand Down Expand Up @@ -33,7 +33,7 @@ on:
env: "${{ secrets }}"

jobs:
lint-check-build:
setup:
if: ${{ inputs.RUN }}
runs-on:
labels: ${{ inputs.RUN_ON }}
Expand All @@ -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
4 changes: 1 addition & 3 deletions .github/workflows/sonar-step-dotnet-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4f2ca2b

Please sign in to comment.