feat: add 'cmds' input

Signed-off-by: João Fernandes <joaofnds@joaofnds.com>
This commit is contained in:
João Fernandes 2022-04-12 18:38:32 -03:00
parent d1bb14ca11
commit 056e107b22
No known key found for this signature in database
GPG key ID: 064E0BACE9889F9C
6 changed files with 47 additions and 11 deletions

View file

@ -29,7 +29,7 @@ jobs:
uses: ./
with:
version: ${{ matrix.version }}
args: do test
cmds: do test
workdir: ./test/ci
install-only:

View file

@ -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 |

View file

@ -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
View file

@ -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);

View file

@ -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')
};
}

View file

@ -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);
}