Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 51 additions & 17 deletions .github/workflows/nut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ on:
type: number
default: 3
description: "Number of times to attempt NUTs"
package-manager:
type: string
required: false
default: yarn
description: "Package manager to use: npm, pnpm, or yarn"
package-manager-version:
type: string
required: false
default: "10"
description: pnpm version to install when package-manager is pnpm
cache-dependency-path:
type: string
required: false
default: yarn.lock
description: Path to the package manager lockfile
install-command:
type: string
required: false
default: yarn install --network-timeout 600000
description: Command used to install repository dependencies
compile-command:
type: string
required: false
default: yarn compile
description: Command used to compile the project
oclif-manifest-command:
type: string
required: false
default: yarn oclif manifest
description: Command used to generate the oclif manifest
wireit-install-command:
type: string
required: false
default: yarn add wireit@^0.14.12
description: Command used to install the wireit workaround

jobs:
nut:
Expand All @@ -68,43 +103,42 @@ jobs:
- uses: google/wireit@setup-github-actions-caching/v2
continue-on-error: true

- uses: actions/setup-node@v4
- uses: salesforcecli/github-workflows/.github/actions/setupNodeAndInstall@main
with:
node-version: ${{ inputs.nodeVersion }}
cache: yarn

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
package-manager: ${{ inputs.package-manager }}
package-manager-version: ${{ inputs.package-manager-version }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
install-command: ${{ inputs.install-command }}

- name: add CLI as global dependency
uses: salesforcecli/github-workflows/.github/actions/retry@main
with:
max_attempts: ${{ inputs.retries }}
command: npm install @salesforce/cli@nightly -g

- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}

# This is a temporary workaround to ensure wireit is >= 0.14.12
# Once all plugins/libs that use this workflow are updated, this can be removed
# See: https://github.com/google/wireit/issues/1297#issuecomment-2794737569
- name: Install wireit
run: yarn add wireit@^0.14.12
env:
WIREIT_INSTALL_COMMAND: ${{ inputs.wireit-install-command }}
run: bash -c "$WIREIT_INSTALL_COMMAND"

- run: yarn compile
- name: Compile
env:
COMPILE_COMMAND: ${{ inputs.compile-command }}
run: bash -c "$COMPILE_COMMAND"

- name: Check that oclif config exists
id: is-oclif-plugin
run: echo "bool=$(jq 'if .oclif then true else false end' package.json)" >> "$GITHUB_OUTPUT"

- run: yarn oclif manifest
- name: Generate oclif manifest
if: ${{ steps.is-oclif-plugin.outputs.bool == 'true' }}
env:
OCLIF_MANIFEST_COMMAND: ${{ inputs.oclif-manifest-command }}
run: bash -c "$OCLIF_MANIFEST_COMMAND"

- name: Set optional sf executable path
if: inputs.sfdxExecutablePath
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/unitTest.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
on:
workflow_call:
inputs:
package-manager:
type: string
required: false
default: yarn
description: "Package manager to use: npm, pnpm, or yarn"
package-manager-version:
type: string
required: false
default: "10"
description: pnpm version to install when package-manager is pnpm
cache-dependency-path:
type: string
required: false
default: yarn.lock
description: Path to the package manager lockfile
install-command:
type: string
required: false
default: yarn install --network-timeout 600000
description: Command used to install repository dependencies
build-command:
type: string
required: false
default: yarn build
description: Command used to build the project
test-command:
type: string
required: false
default: yarn test
description: Command used to run unit tests
wireit-install-command:
type: string
required: false
default: yarn add wireit@^0.14.12
description: Command used to install the wireit workaround

jobs:
linux-unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTestsLinux.yml@main
with:
package-manager: ${{ inputs.package-manager }}
package-manager-version: ${{ inputs.package-manager-version }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
install-command: ${{ inputs.install-command }}
build-command: ${{ inputs.build-command }}
test-command: ${{ inputs.test-command }}
wireit-install-command: ${{ inputs.wireit-install-command }}
windows-unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTestsWindows.yml@main
with:
package-manager: ${{ inputs.package-manager }}
package-manager-version: ${{ inputs.package-manager-version }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
install-command: ${{ inputs.install-command }}
build-command: ${{ inputs.build-command }}
test-command: ${{ inputs.test-command }}
wireit-install-command: ${{ inputs.wireit-install-command }}
69 changes: 50 additions & 19 deletions .github/workflows/unitTestsLinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@ on:
required: false
default: false
description: skip `prevent-typescript-dependency`. Use it for devDeps that ship TS
package-manager:
type: string
required: false
default: yarn
description: "Package manager to use: npm, pnpm, or yarn"
package-manager-version:
type: string
required: false
default: "10"
description: pnpm version to install when package-manager is pnpm
cache-dependency-path:
type: string
required: false
default: yarn.lock
description: Path to the package manager lockfile
install-command:
type: string
required: false
default: yarn install --network-timeout 600000
description: Command used to install repository dependencies
build-command:
type: string
required: false
default: yarn build
description: Command used to build the project
test-command:
type: string
required: false
default: yarn test
description: Command used to run unit tests
wireit-install-command:
type: string
required: false
default: yarn add wireit@^0.14.12
description: Command used to install the wireit workaround

jobs:
determine-node-versions:
Expand Down Expand Up @@ -33,37 +68,33 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
cache: yarn

- uses: google/wireit@setup-github-actions-caching/v2
continue-on-error: true

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
- uses: salesforcecli/github-workflows/.github/actions/setupNodeAndInstall@main
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}

- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
node-version: ${{ matrix.node_version }}
package-manager: ${{ inputs.package-manager }}
package-manager-version: ${{ inputs.package-manager-version }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
install-command: ${{ inputs.install-command }}

# This is a temporary workaround to ensure wireit is >= 0.14.12
# Once all plugins/libraries that use this workflow are updated, this can be removed
# See: https://github.com/google/wireit/issues/1297#issuecomment-2794737569
- name: Install wireit
run: yarn add wireit@^0.14.12
env:
WIREIT_INSTALL_COMMAND: ${{ inputs.wireit-install-command }}
run: bash -c "$WIREIT_INSTALL_COMMAND"

- run: yarn build
- name: Build
env:
BUILD_COMMAND: ${{ inputs.build-command }}
run: bash -c "$BUILD_COMMAND"

- name: yarn test
- name: Test
uses: salesforcecli/github-workflows/.github/actions/retry@main
with:
command: yarn test
command: ${{ inputs.test-command }}
env:
SF_DISABLE_TELEMETRY: true
68 changes: 50 additions & 18 deletions .github/workflows/unitTestsWindows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
on:
workflow_call:
inputs:
package-manager:
type: string
required: false
default: yarn
description: "Package manager to use: npm, pnpm, or yarn"
package-manager-version:
type: string
required: false
default: "10"
description: pnpm version to install when package-manager is pnpm
cache-dependency-path:
type: string
required: false
default: yarn.lock
description: Path to the package manager lockfile
install-command:
type: string
required: false
default: yarn install --network-timeout 600000
description: Command used to install repository dependencies
build-command:
type: string
required: false
default: yarn build
description: Command used to build the project
test-command:
type: string
required: false
default: yarn test
description: Command used to run unit tests
wireit-install-command:
type: string
required: false
default: yarn add wireit@^0.14.12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why yarn as default and not npm ci? The shared composite action setupNodeAndInstall has smart auto-substitution logic but it only fires when the incoming install-command is exactly "npm ci", so if someone chooses npm/pnpm but misses passing the install command then yarn would still run.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yarn is the default on that input because unitTestsWindows.yml still always installs with Yarn. setupNodeAndInstall only rewrites an install command when it is exactly npm ci, so a Yarn default does not get rewritten when package-manager is npm or pnpm.

The reviewed default: yarn / default: yarn install --network-timeout 600000 inputs are on PR head 5468051, not in this checkout. This worktree is cd2eafc. Here the workflow has no install-command input and hardcodes Yarn:

      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node_version }}
          cache: yarn
      # ...
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}

      - uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
        if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
      # ...
        run: yarn add wireit@^0.14.12

      - run: yarn build
      # ...
          command: yarn test

Current callers pass no package-manager inputs. A workflow default of npm ci would change those runs. The Yarn default keeps that behavior.

The substitution claim matches the composite action in this tree. Its own defaults are npm and npm ci, and the rewrite runs only for that exact command:

    description: 'Package manager to use: npm, pnpm, or yarn.'
    required: false
    default: npm
  # ...
  install-command:
    description: 'Command used to install repository dependencies.'
    required: false
    default: npm ci
        if [ "$INSTALL_COMMAND" = "npm ci" ]; then
          case "$PACKAGE_MANAGER" in
            pnpm) INSTALL_COMMAND="pnpm install --frozen-lockfile" ;;
            yarn) INSTALL_COMMAND="yarn install --network-timeout 600000" ;;
          esac
        fi

There is no reverse case. yarn install --network-timeout 600000 is passed through. Setting package-manager to npm or pnpm and leaving install-command at the workflow default still runs Yarn.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahgot it. It would be nice add something like below to avoid the case of mismatching package-manager and install command:

    - name: Validate package manager
      shell: bash
      env:
        PACKAGE_MANAGER: ${{ inputs.package-manager }}
      run: |
        if [ "$PACKAGE_MANAGER" != "npm" ] && [ "$PACKAGE_MANAGER" != "pnpm" ] && [ "$PACKAGE_MANAGER" != "yarn" ]; then
          echo "::error::Unsupported package manager: $PACKAGE_MANAGER. Expected npm, pnpm, or yarn."
          exit 1
        fi

    - name: Validate cache-dependency-path and install-command match package-manager
      shell: bash
      env:
        PACKAGE_MANAGER: ${{ inputs.package-manager }}
        CACHE_DEPENDENCY_PATH: ${{ inputs.cache-dependency-path }}
        INSTALL_COMMAND: ${{ inputs.install-command }}
      run: |
        case "$PACKAGE_MANAGER" in
          npm)  expected_lockfile="package-lock.json"; expected_bin="npm" ;;
          yarn) expected_lockfile="yarn.lock";          expected_bin="yarn" ;;
          pnpm) expected_lockfile="pnpm-lock.yaml";     expected_bin="pnpm" ;;
        esac

        actual_lockfile=$(basename "$CACHE_DEPENDENCY_PATH")
        if [ "$actual_lockfile" != "$expected_lockfile" ]; then
          echo "::error::package-manager is '$PACKAGE_MANAGER' but cache-dependency-path points at '$CACHE_DEPENDENCY_PATH' (expected a '$expected_lockfile' file). Pass a matching cache-dependency-path for '$PACKAGE_MANAGER'."
          exit 1
        fi

        install_bin=$(echo "$INSTALL_COMMAND" | awk '{print $1}')
        if [ "$install_bin" != "$expected_bin" ]; then
          echo "::error::package-manager is '$PACKAGE_MANAGER' but install-command '$INSTALL_COMMAND' runs '$install_bin'. Pass an install-command that starts with '$expected_bin' (or leave it unset to use the default)."
          exit 1
        fi

description: Command used to install the wireit workaround

jobs:
determine-node-versions:
Expand Down Expand Up @@ -28,34 +64,30 @@ jobs:
- uses: google/wireit@setup-github-actions-caching/v2
continue-on-error: true

- uses: actions/setup-node@v4
- uses: salesforcecli/github-workflows/.github/actions/setupNodeAndInstall@main
with:
node-version: ${{ matrix.node_version }}
cache: yarn

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}

- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
package-manager: ${{ inputs.package-manager }}
package-manager-version: ${{ inputs.package-manager-version }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
install-command: ${{ inputs.install-command }}

# This is a temporary workaround to ensure wireit is >= 0.14.12
# Once all plugins/libraries that use this workflow are updated, this can be removed
# See: https://github.com/google/wireit/issues/1297#issuecomment-2794737569
- name: Install wireit
run: yarn add wireit@^0.14.12
env:
WIREIT_INSTALL_COMMAND: ${{ inputs.wireit-install-command }}
run: bash -c "$WIREIT_INSTALL_COMMAND"

- run: yarn build
- name: Build
env:
BUILD_COMMAND: ${{ inputs.build-command }}
run: bash -c "$BUILD_COMMAND"

- name: yarn test
- name: Test
uses: salesforcecli/github-workflows/.github/actions/retry@main
with:
command: yarn test
command: ${{ inputs.test-command }}
env:
SF_DISABLE_TELEMETRY: true
Loading