diff --git a/.github/workflows/nut.yml b/.github/workflows/nut.yml index cfe837a..517daf8 100644 --- a/.github/workflows/nut.yml +++ b/.github/workflows/nut.yml @@ -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: @@ -68,19 +103,13 @@ 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 @@ -88,23 +117,28 @@ jobs: 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 diff --git a/.github/workflows/unitTest.yml b/.github/workflows/unitTest.yml index 2103393..51eac05 100644 --- a/.github/workflows/unitTest.yml +++ b/.github/workflows/unitTest.yml @@ -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 }} diff --git a/.github/workflows/unitTestsLinux.yml b/.github/workflows/unitTestsLinux.yml index 169818f..4b1d867 100644 --- a/.github/workflows/unitTestsLinux.yml +++ b/.github/workflows/unitTestsLinux.yml @@ -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: @@ -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 diff --git a/.github/workflows/unitTestsWindows.yml b/.github/workflows/unitTestsWindows.yml index 4021897..2e042d9 100644 --- a/.github/workflows/unitTestsWindows.yml +++ b/.github/workflows/unitTestsWindows.yml @@ -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 + description: Command used to install the wireit workaround jobs: determine-node-versions: @@ -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 diff --git a/README.md b/README.md index a6c88be..f92d382 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,57 @@ jobs: os: ${{ matrix.os }} ``` +Yarn is the default for these CLI testing workflows, so existing callers do not need new inputs. npm and pnpm callers pass package-manager setup and the commands that replaced hard-coded Yarn steps. + +```yml +jobs: + unit-tests: + uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main + with: + package-manager: npm + cache-dependency-path: package-lock.json + install-command: npm ci + build-command: npm run build + test-command: npm test + wireit-install-command: npm install wireit@^0.14.12 + nuts: + needs: unit-tests + uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main + secrets: inherit + with: + os: ubuntu-latest + package-manager: npm + cache-dependency-path: package-lock.json + install-command: npm ci + compile-command: npm run compile + oclif-manifest-command: npm run oclif -- manifest + command: npm run test:nuts + wireit-install-command: npm install wireit@^0.14.12 +``` + +```yml +jobs: + unit-tests: + uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main + with: + package-manager: pnpm + package-manager-version: '10' + cache-dependency-path: pnpm-lock.yaml + install-command: pnpm install --frozen-lockfile + build-command: pnpm run build + test-command: pnpm test + wireit-install-command: pnpm add wireit@^0.14.12 +``` + +Shared inputs for `unitTest.yml`, `unitTestsLinux.yml`, `unitTestsWindows.yml`, and `nut.yml`: + +- `package-manager` (optional) - `npm`, `pnpm`, or `yarn` (default: `yarn`) +- `package-manager-version` (optional) - pnpm version to install when `package-manager` is `pnpm` (default: `10`) +- `cache-dependency-path` (optional) - lockfile path (default: `yarn.lock`) +- `install-command` (optional) - dependency install command (default: `yarn install --network-timeout 600000`) + +Workflow-specific command inputs keep the previous Yarn defaults (`yarn build`, `yarn test`, `yarn test:nuts`). Node setup, caching, and installs go through `.github/actions/setupNodeAndInstall`. + ## Other Tooling ### nut conditional on commit message