mirror of
https://github.com/dagger/dagger-for-github.git
synced 2026-01-01 13:10:18 +11:00
feat: add 'cmds' input
Signed-off-by: João Fernandes <joaofnds@joaofnds.com>
This commit is contained in:
parent
d1bb14ca11
commit
056e107b22
6 changed files with 47 additions and 11 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -29,7 +29,7 @@ jobs:
|
|||
uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
args: do test
|
||||
cmds: do test
|
||||
workdir: ./test/ci
|
||||
|
||||
install-only:
|
||||
|
|
|
|||
17
README.md
17
README.md
|
|
@ -43,7 +43,7 @@ jobs:
|
|||
name: Dagger
|
||||
uses: dagger/dagger-for-github@v2
|
||||
with:
|
||||
args: do test
|
||||
cmds: do test
|
||||
```
|
||||
|
||||
### Install Only
|
||||
|
|
@ -60,6 +60,19 @@ steps:
|
|||
run: dagger version
|
||||
```
|
||||
|
||||
### Multiple commands
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
-
|
||||
name: Install Dagger
|
||||
uses: dagger/dagger-for-github@v2
|
||||
with:
|
||||
cmds: |
|
||||
project update
|
||||
do test
|
||||
```
|
||||
|
||||
## Customizing
|
||||
|
||||
### inputs
|
||||
|
|
@ -69,7 +82,7 @@ Following inputs can be used as `step.with` keys
|
|||
| Name | Type | Default | Description |
|
||||
|------------------|---------|--------------|------------------------------------------------------------------|
|
||||
| `version` | String | `latest` | Dagger version |
|
||||
| `args` | String | | Arguments to pass to Dagger |
|
||||
| `cmds` | String | | Commands to run on Dagger |
|
||||
| `workdir` | String | `.` | Working directory (below repository root) |
|
||||
| `install-only` | Bool | `false` | Just install Dagger |
|
||||
| `cleanup` | Bool | `true` | Cleanup Dagger home folder at the end of a job |
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ inputs:
|
|||
args:
|
||||
description: 'Arguments to pass to Dagger'
|
||||
required: false
|
||||
deprecationMessage: 'Use cmds input instead'
|
||||
cmds:
|
||||
description: 'Commands to run on Dagger'
|
||||
required: false
|
||||
workdir:
|
||||
description: 'Working directory (below repository root)'
|
||||
default: '.'
|
||||
|
|
|
|||
16
dist/index.js
generated
vendored
16
dist/index.js
generated
vendored
|
|
@ -45,7 +45,8 @@ function getInputs() {
|
|||
workdir: core.getInput('workdir') || '.',
|
||||
args: core.getInput('args'),
|
||||
installOnly: core.getBooleanInput('install-only'),
|
||||
cleanup: core.getBooleanInput('cleanup')
|
||||
cleanup: core.getBooleanInput('cleanup'),
|
||||
cmds: yield getInputList('cmds')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
@ -220,15 +221,22 @@ function run() {
|
|||
core.debug(`Added ${daggerDir} to PATH`);
|
||||
return;
|
||||
}
|
||||
else if (!inputs.args) {
|
||||
throw new Error('args input required');
|
||||
else if (!inputs.args && !inputs.cmds.length) {
|
||||
throw new Error(`you need to provide either 'args' or 'cmds'`);
|
||||
}
|
||||
if (inputs.workdir && inputs.workdir !== '.') {
|
||||
core.info(`Using ${inputs.workdir} as working directory`);
|
||||
process.chdir(inputs.workdir);
|
||||
}
|
||||
stateHelper.setCleanup(inputs.cleanup);
|
||||
yield exec.exec(`${daggerBin} ${inputs.args} --log-format plain`);
|
||||
if (inputs.args) {
|
||||
inputs.cmds.unshift(inputs.args);
|
||||
}
|
||||
for (const cmd of inputs.cmds) {
|
||||
yield core.group(cmd, () => __awaiter(this, void 0, void 0, function* () {
|
||||
yield exec.exec(`${daggerBin} ${cmd} --log-format plain`);
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ export interface Inputs {
|
|||
args: string;
|
||||
installOnly: boolean;
|
||||
cleanup: boolean;
|
||||
cmds: string[];
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
|
|
@ -14,7 +15,8 @@ export async function getInputs(): Promise<Inputs> {
|
|||
workdir: core.getInput('workdir') || '.',
|
||||
args: core.getInput('args'),
|
||||
installOnly: core.getBooleanInput('install-only'),
|
||||
cleanup: core.getBooleanInput('cleanup')
|
||||
cleanup: core.getBooleanInput('cleanup'),
|
||||
cmds: await getInputList('cmds')
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
15
src/main.ts
15
src/main.ts
|
|
@ -17,8 +17,8 @@ async function run(): Promise<void> {
|
|||
core.addPath(daggerDir);
|
||||
core.debug(`Added ${daggerDir} to PATH`);
|
||||
return;
|
||||
} else if (!inputs.args) {
|
||||
throw new Error('args input required');
|
||||
} else if (!inputs.args && !inputs.cmds.length) {
|
||||
throw new Error(`you need to provide either 'args' or 'cmds'`);
|
||||
}
|
||||
|
||||
if (inputs.workdir && inputs.workdir !== '.') {
|
||||
|
|
@ -27,7 +27,16 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
stateHelper.setCleanup(inputs.cleanup);
|
||||
await exec.exec(`${daggerBin} ${inputs.args} --log-format plain`);
|
||||
|
||||
if (inputs.args) {
|
||||
inputs.cmds.unshift(inputs.args);
|
||||
}
|
||||
|
||||
for (const cmd of inputs.cmds) {
|
||||
await core.group(cmd, async () => {
|
||||
await exec.exec(`${daggerBin} ${cmd} --log-format plain`);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue