From 025ca59e820c020606a90d7f3fed063203a113e1 Mon Sep 17 00:00:00 2001 From: netanelC Date: Sun, 4 May 2025 15:17:49 +0300 Subject: [PATCH 1/5] feat: add init-npm action --- .github/workflows/test-init-npm.yaml | 22 ++++++++++++++++++++++ actions/init-npm/README.md | 21 +++++++++++++++++++++ actions/init-npm/action.yaml | 28 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .github/workflows/test-init-npm.yaml create mode 100644 actions/init-npm/README.md create mode 100644 actions/init-npm/action.yaml diff --git a/.github/workflows/test-init-npm.yaml b/.github/workflows/test-init-npm.yaml new file mode 100644 index 0000000..1bb9d0c --- /dev/null +++ b/.github/workflows/test-init-npm.yaml @@ -0,0 +1,22 @@ +name: Init-npm repository + +on: + pull_request: + push: + branches: + - master + paths: + - "actions/init-npm/**" + +jobs: + test-init-npm: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Test init-npm action + uses: ./actions/init-npm + with: + node-version: '20.x' + path: ./test diff --git a/actions/init-npm/README.md b/actions/init-npm/README.md new file mode 100644 index 0000000..61a51d4 --- /dev/null +++ b/actions/init-npm/README.md @@ -0,0 +1,21 @@ +# Initialize NPM Action + +This GitHub Action sets up Node.js, installs dependencies using npm, and builds the project. + +## 🛠 Inputs + +| Name | Description | Default | Required | +|----------------|---------------------------------------|---------|----------| +| `node_version` | Node.js version to set up | `20.x` | false | +| `path` | Path to the directory containing your Node.js project | `.` | false | + +## 🚀 Usage + + +```yaml +- name: Initialize NPM Project + uses: MapColonies/shared-workflows/actions/init-npm@init-npm-v0.0.0 + with: + node-version: '20.x' +``` + diff --git a/actions/init-npm/action.yaml b/actions/init-npm/action.yaml new file mode 100644 index 0000000..11949cd --- /dev/null +++ b/actions/init-npm/action.yaml @@ -0,0 +1,28 @@ +name: init-npm +description: 'Initialize the repo with npm and install all the dependencies' +inputs: + node-version: + description: 'Node.js version' + required: true + default: '20.x' + path: + description: "Path to the Node.js dir " + default: "." + required: false +runs: + using: composite + steps: + - name: Set up Node.js + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4 + with: + node-version: ${{ inputs.node-version }} + + - name: Install TS Project dependencies + shell: bash + run: npm ci + working-directory: ${{ inputs.path }} + + - name: build + shell: bash + run: npm run build + working-directory: ${{ inputs.path }} From 803e5c5b434185df5c151af1da18621342a0232c Mon Sep 17 00:00:00 2001 From: netanelC Date: Sun, 4 May 2025 15:22:09 +0300 Subject: [PATCH 2/5] feat: add init-npm action to repo README --- README.md | 2 ++ release-please-config.json | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 1ff6a22..26dc4c0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This repository contains GitHub Actions used across the MapColonies organization │ ├── build-docker/ │ ├── build-and-push-helm/ │ ├── helm-lint/ +│ ├── init-npm/ │ ├── eslint/ │ ├── openapi-lint/ │ ├── push-docker/ @@ -51,6 +52,7 @@ Each action has a dedicated folder with: | `helm-lint` | Lints and tests Helm charts | | `eslint` | Runs ESLint to check JavaScript/TypeScript code | | `openapi-lint` | Validates OpenAPI specs using Redocly CLI | +| `init-npm` | Initializes the repo with npm | | `update-artifacts-file` | Updates `artifacts.json` metadata | --- diff --git a/release-please-config.json b/release-please-config.json index 53333f1..d176a8d 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -93,6 +93,11 @@ "release-type": "simple", "package-name": "update-artifacts-file", "extra-files": ["README.md"] + }, + "actions/init-npm": { + "release-type": "simple", + "package-name": "init-npm", + "extra-files": ["README.md"] } } } From ab18e917d8aced67f336ecf4a530c04bdb3bdcb9 Mon Sep 17 00:00:00 2001 From: netanelC Date: Sun, 4 May 2025 15:40:00 +0300 Subject: [PATCH 3/5] feat: add cache npm to setup-node --- actions/init-npm/action.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/actions/init-npm/action.yaml b/actions/init-npm/action.yaml index 11949cd..45252f6 100644 --- a/actions/init-npm/action.yaml +++ b/actions/init-npm/action.yaml @@ -6,7 +6,7 @@ inputs: required: true default: '20.x' path: - description: "Path to the Node.js dir " + description: "Path to the Node.js directory" default: "." required: false runs: @@ -16,7 +16,8 @@ runs: uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4 with: node-version: ${{ inputs.node-version }} - + cache: 'npm' + - name: Install TS Project dependencies shell: bash run: npm ci From 67a3c68be55a7116de26977161cf53731e84e1e7 Mon Sep 17 00:00:00 2001 From: netanelC Date: Sun, 4 May 2025 15:40:26 +0300 Subject: [PATCH 4/5] docs: add link to setup node supported version --- actions/init-npm/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/init-npm/README.md b/actions/init-npm/README.md index 61a51d4..d04ab97 100644 --- a/actions/init-npm/README.md +++ b/actions/init-npm/README.md @@ -6,7 +6,7 @@ This GitHub Action sets up Node.js, installs dependencies using npm, and builds | Name | Description | Default | Required | |----------------|---------------------------------------|---------|----------| -| `node_version` | Node.js version to set up | `20.x` | false | +| `node_version` | Node.js version to set up ([supported versions](https://github.com/actions/setup-node#supported-version-syntax)) | `20.x` | false | | `path` | Path to the directory containing your Node.js project | `.` | false | ## 🚀 Usage From badbad7ba50e3abc17055f6035f4e48e154c2539 Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 6 May 2025 17:26:00 +0300 Subject: [PATCH 5/5] fix: set cache dependency path --- actions/init-npm/action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/init-npm/action.yaml b/actions/init-npm/action.yaml index 45252f6..309514e 100644 --- a/actions/init-npm/action.yaml +++ b/actions/init-npm/action.yaml @@ -17,6 +17,7 @@ runs: with: node-version: ${{ inputs.node-version }} cache: 'npm' + cache-dependency-path: ${{ inputs.path }}/package-lock.json - name: Install TS Project dependencies shell: bash