Skip to content

Commit

Permalink
Add working-directory input option
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 12, 2022
1 parent 60a2132 commit 7a830fa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ./
Expand All @@ -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: ./
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 13 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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}`);
Expand Down
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -644,6 +650,8 @@ async function innerMain(): Promise<void> {
} 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])
Expand Down Expand Up @@ -709,15 +717,20 @@ async function innerMain(): Promise<void> {
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}`)
Expand Down

0 comments on commit 7a830fa

Please sign in to comment.