diff --git a/.github/actions/setup-node/action.yaml b/.github/actions/setup-node/action.yaml new file mode 100644 index 0000000..df432c4 --- /dev/null +++ b/.github/actions/setup-node/action.yaml @@ -0,0 +1,145 @@ +name: Setup Node +description: > + Setup Node.js using an explicit version override, or version files (.tool-versions, .nvmrc, .node-version) if available. + Falls back to the latest LTS version if no version is specified and no version files are found. + Requires the repository to be checked out before using this action. + For more details on available inputs and outputs, see: https://github.com/actions/setup-node + +inputs: + node-version: + description: Node version specifier override (e.g., 22.17.1, 22.x, lts/*, latest). + required: false + default: "" + + fallback-node-version: + description: > + Fallback Node version specifier to use if no version is specified and no version files are found. + Defaults to latest LTS version. + required: false + default: "lts/*" + + cache: + description: > + Specify a package manager for caching in the default directory. + Supported values are 'npm', 'yarn', and 'pnpm'. + Package manager should be pre-installed. + required: false + default: "" + + cache-dependency-path: + description: > + Path to the dependency file (e.g., package-lock.json, yarn.lock, pnpm-lock.yaml) for caching. + Useful for monorepos, multi-workspaces, and non-conventional project structures. + required: false + default: "" + + package-manager-cache: + description: Controls setup-node automatic npm caching (passed through). Set to "false" to disable auto caching. + required: false + default: "true" + + check-latest: + description: > + Check for the latest Node version that satisfies the specified version range, instead of using a cached version. + It will only affect version ranges, such as "16.x", "18.x", "lts/*", etc. + Exact versions will not be affected. + required: false + default: "false" + + log-resolution: + description: Prints a brief summary of how the Node version was resolved. + required: false + default: "false" + + registry-url: + description: Optional registry URL for auth (passed through to actions/setup-node). + required: false + default: "" + + scope: + description: Optional npm scope for auth (passed through to actions/setup-node). + required: false + default: "" + +outputs: + resolved-source: + description: Where the Node version was resolved from (override, .tool-versions, .nvmrc, .node-version, fallback) + value: ${{ steps.resolve.outputs.source }} + + resolved-node-version: + description: Resolved Node version specifier that was used (override or fallback), if applicable. + value: ${{ steps.resolve.outputs.node_version }} + + resolved-node-version-file: + description: Resolved version file that was used (.tool-versions, .nvmrc, .node-version), if applicable. + value: ${{ steps.resolve.outputs.node_version_file }} + +runs: + using: "composite" + steps: + - name: Resolve Node version source + id: resolve + shell: bash + run: | + set -euo pipefail + + if [[ -n "${{ inputs.node-version }}" ]]; then + echo "source=override" >> "$GITHUB_OUTPUT" + echo "node_version=${{ inputs.node-version }}" >> "$GITHUB_OUTPUT" + echo "node_version_file=" >> "$GITHUB_OUTPUT" + + elif [[ -f ".tool-versions" ]]; then + echo "source=.tool-versions" >> "$GITHUB_OUTPUT" + echo "node_version=" >> "$GITHUB_OUTPUT" + echo "node_version_file=.tool-versions" >> "$GITHUB_OUTPUT" + + elif [[ -f ".nvmrc" ]]; then + echo "source=.nvmrc" >> "$GITHUB_OUTPUT" + echo "node_version=" >> "$GITHUB_OUTPUT" + echo "node_version_file=.nvmrc" >> "$GITHUB_OUTPUT" + + elif [[ -f ".node-version" ]]; then + echo "source=.node-version" >> "$GITHUB_OUTPUT" + echo "node_version=" >> "$GITHUB_OUTPUT" + echo "node_version_file=.node-version" >> "$GITHUB_OUTPUT" + + else + echo "source=fallback" >> "$GITHUB_OUTPUT" + echo "node_version=${{ inputs.fallback-node-version }}" >> "$GITHUB_OUTPUT" + echo "node_version_file=" >> "$GITHUB_OUTPUT" + fi + + - name: Node resolution summary + if: ${{ inputs.log-resolution == 'true' }} + shell: bash + run: | + echo "Node resolution source: ${{ steps.resolve.outputs.source }}" + if [[ -n "${{ steps.resolve.outputs.node_version_file }}" ]]; then + echo "Node version file: ${{ steps.resolve.outputs.node_version_file }}" + else + echo "Node version: ${{ steps.resolve.outputs.node_version }}" + fi + + - name: Setup Node (from version file) + if: ${{ steps.resolve.outputs.node_version_file != '' }} + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + with: + node-version-file: ${{ steps.resolve.outputs.node_version_file }} + cache: ${{ inputs.cache }} + cache-dependency-path: ${{ inputs.cache-dependency-path }} + package-manager-cache: ${{ inputs.package-manager-cache }} + check-latest: ${{ inputs.check-latest }} + registry-url: ${{ inputs.registry-url }} + scope: ${{ inputs.scope }} + + - name: Setup Node (from specified version) + if: ${{ steps.resolve.outputs.node_version_file == '' }} + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + with: + node-version: ${{ steps.resolve.outputs.node_version }} + cache: ${{ inputs.cache }} + cache-dependency-path: ${{ inputs.cache-dependency-path }} + package-manager-cache: ${{ inputs.package-manager-cache }} + check-latest: ${{ inputs.check-latest }} + registry-url: ${{ inputs.registry-url }} + scope: ${{ inputs.scope }} diff --git a/.github/workflows/eslint-lint-check.yaml b/.github/workflows/eslint-lint-check.yaml index f102770..2de3fee 100644 --- a/.github/workflows/eslint-lint-check.yaml +++ b/.github/workflows/eslint-lint-check.yaml @@ -3,6 +3,10 @@ name: ESlint Lint Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" eslint-version: required: false type: string @@ -29,9 +33,9 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} - name: Install Dependencies diff --git a/.github/workflows/markdown-lint-check.yaml b/.github/workflows/markdown-lint-check.yaml index 320fae7..2865ae7 100644 --- a/.github/workflows/markdown-lint-check.yaml +++ b/.github/workflows/markdown-lint-check.yaml @@ -3,6 +3,10 @@ name: Markdown Lint Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" markdownlint-version: required: false type: string @@ -25,9 +29,9 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} - name: Lint Check diff --git a/.github/workflows/npm-publish-package.yaml b/.github/workflows/npm-publish-package.yaml index e5cf5ec..784c310 100644 --- a/.github/workflows/npm-publish-package.yaml +++ b/.github/workflows/npm-publish-package.yaml @@ -6,7 +6,7 @@ on: node-version: required: false type: string - default: "latest" + default: "" cache-dependency-manager: required: false type: string @@ -42,7 +42,7 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} diff --git a/.github/workflows/npm-semantic-release.yaml b/.github/workflows/npm-semantic-release.yaml index 6ef562f..06cc967 100644 --- a/.github/workflows/npm-semantic-release.yaml +++ b/.github/workflows/npm-semantic-release.yaml @@ -6,7 +6,7 @@ on: node-version: required: false type: string - default: "latest" + default: "" cache-dependency-manager: required: false type: string @@ -43,7 +43,7 @@ jobs: fetch-depth: 0 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} diff --git a/.github/workflows/npm-test.yaml b/.github/workflows/npm-test.yaml index f74af31..e748454 100644 --- a/.github/workflows/npm-test.yaml +++ b/.github/workflows/npm-test.yaml @@ -6,7 +6,7 @@ on: node-version: required: false type: string - default: "latest" + default: "" cache-dependency-manager: required: false type: string @@ -32,7 +32,7 @@ jobs: - name: Checkout Source uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - - name: Set up Node.js + - name: Setup Node.js uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 with: node-version: ${{ inputs.node-version }} diff --git a/.github/workflows/prettier-format-check.yaml b/.github/workflows/prettier-format-check.yaml index d8ab4aa..3fc1ddd 100644 --- a/.github/workflows/prettier-format-check.yaml +++ b/.github/workflows/prettier-format-check.yaml @@ -3,6 +3,10 @@ name: Prettier Format Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" prettier-version: required: false type: string @@ -29,10 +33,11 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} + log-resolution: true - name: Check Formatting run: npx prettier@${{ inputs.prettier-version }} --check ${{ inputs.check-path }} diff --git a/.github/workflows/redocly-bundle-lint-check.yaml b/.github/workflows/redocly-bundle-lint-check.yaml index 95a56e5..97793cf 100644 --- a/.github/workflows/redocly-bundle-lint-check.yaml +++ b/.github/workflows/redocly-bundle-lint-check.yaml @@ -3,6 +3,10 @@ name: Redocly Bundle Lint Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" redocly-version: required: false type: string @@ -29,9 +33,9 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} - name: Bundle APIs diff --git a/.github/workflows/redocly-lint-check.yaml b/.github/workflows/redocly-lint-check.yaml index e75ce3a..e0cae8e 100644 --- a/.github/workflows/redocly-lint-check.yaml +++ b/.github/workflows/redocly-lint-check.yaml @@ -3,6 +3,10 @@ name: Redocly Lint Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" redocly-version: required: false type: string @@ -29,9 +33,9 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} - name: Lint Check diff --git a/.github/workflows/spectral-lint-check.yaml b/.github/workflows/spectral-lint-check.yaml index cb970e3..aa21970 100644 --- a/.github/workflows/spectral-lint-check.yaml +++ b/.github/workflows/spectral-lint-check.yaml @@ -3,6 +3,10 @@ name: Spectral Lint Check on: workflow_call: inputs: + node-version: + required: false + type: string + default: "" spectral-version: required: false type: string @@ -29,9 +33,9 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Setup Node.js - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 + uses: ./.github/actions/setup-node@main with: - node-version: latest + node-version: ${{ inputs.node-version }} cache: ${{ inputs.cache-dependency-manager }} - name: Lint Check