From 7a830fa196ca2e6f9b49d2f6a4089491f9d8184a Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 12 Nov 2022 10:09:53 +0800 Subject: [PATCH] Add `working-directory` input option --- .github/workflows/test.yml | 12 ++++++++---- README.md | 1 + action.yml | 3 +++ dist/index.js | 15 +++++++++++++-- src/index.ts | 17 +++++++++++++++-- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ea0864..02d839f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,12 +50,14 @@ jobs: uses: ./ with: rust-toolchain: ${{ matrix.toolchain }} - args: -m maturin/test-crates/pyo3-mixed/Cargo.toml -o dist + args: -o dist + working-directory: maturin/test-crates/pyo3-mixed - name: maturin build universal2 if: matrix.os == 'macos-latest' uses: ./ with: - args: -m maturin/test-crates/pyo3-mixed/Cargo.toml --universal2 + args: --universal2 + working-directory: maturin/test-crates/pyo3-mixed - name: maturin build arm64 if: matrix.os == 'macos-latest' uses: ./ @@ -68,7 +70,8 @@ jobs: if: matrix.os == 'ubuntu-latest' uses: ./ with: - args: -m maturin/test-crates/pyo3-mixed/Cargo.toml -i python3.10 --out dist + args: -i python3.10 --out dist + working-directory: maturin/test-crates/pyo3-mixed manylinux: 'auto' - name: maturin build manylinux2014 uses: ./ @@ -226,7 +229,8 @@ jobs: with: container: ${{ matrix.platform.container }} rust-toolchain: ${{ matrix.toolchain }} - args: -m ${{ matrix.platform.test-crate }}/Cargo.toml -i python3.8 + working-directory: ${{ matrix.platform.test-crate }} + args: -i python3.8 manylinux: ${{ matrix.platform.manylinux }} target: ${{ matrix.platform.target }} - name: setup rust-toolchain diff --git a/README.md b/README.md index edd0c30..57d4a78 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ take a look at the following examples: | container | No | manylinux docker container image name | string | Default depends on `target` and `manylinux` options, Set to `off` to disable manylinux docker build and build on the host instead. | | rust-toolchain | No | Rust toolchain name | string | Defaults to `stable` for Docker build | | rustup-components | No | Rustup components | string | Defaults to empty | +| working-directory | No | The working directory to run the command in | string | Defaults to the root of the repository | ## `manylinux` Docker container diff --git a/action.yml b/action.yml index 56b95bb..c8ed7d2 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: Rustup components. See https://rust-lang.github.io/rustup/concepts/components.html required: false + working-directory: + description: Working directory to run maturin in. + required: false runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 70894f7..8cc1f16 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11702,11 +11702,18 @@ async function dockerBuild(tag, manylinux, args) { dockerEnvs.push(env); } } + let workdir = core.getInput('working-directory'); + if (workdir.length > 0) { + workdir = path.join(workspace, workdir); + } + else { + workdir = workspace; + } const exitCode = await exec.exec('docker', [ 'run', '--rm', '--workdir', - workspace, + workdir, '-e', 'DEBIAN_FRONTEND=noninteractive', '-e', @@ -11822,6 +11829,7 @@ async function innerMain() { else { const rustToolchain = await getRustToolchain(args); const rustupComponents = core.getInput('rustup-components'); + const workdir = core.getInput('working-directory') || process.cwd(); core.startGroup('Install Rust target'); if (rustToolchain.length > 0) { await exec.exec('rustup', ['override', 'set', rustToolchain]); @@ -11880,15 +11888,18 @@ async function innerMain() { uploadArgs.push(arg); } else { + const cwd = process.cwd(); + process.chdir(workdir); const globber = await glob.create(arg); for await (const file of globber.globGenerator()) { uploadArgs.push(file); } + process.chdir(cwd); } } fullCommand = `${maturinPath} ${command} ${uploadArgs.join(' ')}`; } - exitCode = await exec.exec(fullCommand, undefined, { env }); + exitCode = await exec.exec(fullCommand, undefined, { env, cwd: workdir }); } if (exitCode !== 0) { throw new Error(`maturin: returned ${exitCode}`); diff --git a/src/index.ts b/src/index.ts index 1679f3b..f8da6df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -503,11 +503,17 @@ async function dockerBuild( } } + let workdir = core.getInput('working-directory') + if (workdir.length > 0) { + workdir = path.join(workspace, workdir) + } else { + workdir = workspace + } const exitCode = await exec.exec('docker', [ 'run', '--rm', '--workdir', - workspace, + workdir, // A list of environment variables '-e', 'DEBIAN_FRONTEND=noninteractive', @@ -644,6 +650,8 @@ async function innerMain(): Promise { } else { const rustToolchain = await getRustToolchain(args) const rustupComponents = core.getInput('rustup-components') + const workdir = core.getInput('working-directory') || process.cwd() + core.startGroup('Install Rust target') if (rustToolchain.length > 0) { await exec.exec('rustup', ['override', 'set', rustToolchain]) @@ -709,15 +717,20 @@ async function innerMain(): Promise { if (arg.startsWith('-')) { uploadArgs.push(arg) } else { + const cwd = process.cwd() + process.chdir(workdir) + const globber = await glob.create(arg) for await (const file of globber.globGenerator()) { uploadArgs.push(file) } + + process.chdir(cwd) } } fullCommand = `${maturinPath} ${command} ${uploadArgs.join(' ')}` } - exitCode = await exec.exec(fullCommand, undefined, {env}) + exitCode = await exec.exec(fullCommand, undefined, {env, cwd: workdir}) } if (exitCode !== 0) { throw new Error(`maturin: returned ${exitCode}`)