github / github/local-action

[Bug] `--pre` and `--post` documented as taking paths relative to "action directory", but it is relative to the `cwd` instead

Abierto
#271 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
451
Forks
28
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Given the following directory structure:

```
.../repo
├── dist
│ ├── generic
│ │ └── index.cjs
├── generic
│ └── action.yml
├── package.json
└── src
├── generic
│ ├── index.ts
│ └── main.ts
└── main.ts
```

for example, using https://github.com/actions/cache's sub-actions `save` and `restore`. Importantly, there is no `action.yml` in the root directory of the repository, and this is by design! (Imagine in the future not just `generic/action.yml` but other things like `video/action.yml` or `docker/action.yml`?)

If I run from `.` to valid file paths, I get an error as expected, the entry points should be relative to the action directory:

```bash
❯ pwd
.../repo
❯ npx @github/local-action ./generic ./src/generic/main.ts .env --post ./src/generic/main.ts
error: command-argument value './src/generic/main.ts' is invalid for argument 'entrypoint'. Entrypoint does not exist: ./src/generic/main.ts
```

So, relative to `./generic`'s `action.yml`, the `src/...` things are in `../src`, right? **I still get an error!**

```bash
❯ pwd
.../repo
❯ npx @github/local-action ./generic ../src/generic/main.ts .env --post ../src/generic/main.ts
error: option '--post ' argument '../src/generic/main.ts' is invalid. POST entrypoint does not exist: ../src/generic/main.ts
```

It seems that you must make the main entry point correctly relative, but the `--post` entry-point should be relative to the current working directory?

```bash
❯ pwd
.../repo
❯ npx @github/local-action ./generic ../src/generic/main.ts .env --post ./src/generic/main.ts
_ _ _ ____ _
/ \ ___| |_(_) ___ _ __ | _ \ ___| |__ _ _ __ _ __ _ ___ _ __
/ _ \ / __| __| |/ _ \| '_ \ | | | |/ _ \ '_ \| | | |/ _` |/ _` |/ _ \ '__|
/ ___ \ (__| |_| | (_) | | | | | |_| | __/ |_) | |_| | (_| | (_| | __/ |
/_/ \_\___|\__|_|\___/|_| |_| |____/ \___|_.__/ \__,_|\__, |\__, |\___|_|
|___/ |___/
================================================================================
Configuration
================================================================================

┌─────────┬────────────────────┬────────────────────────────────┐
│ (index) │ Field │ Value │
├─────────┼────────────────────┼────────────────────────────────┤
│ 0 │ 'Action Path' │ '.../repo/generic' │
│ 1 │ 'Entrypoint' │ '.../repo/src/generic/main.ts' │
│ 2 │ 'Post Entrypoint' │ '.../repo/src/generic/main.ts' │
│ 3 │ 'Environment File' │ '.../repo/.env' │
└─────────┴────────────────────┴────────────────────────────────┘

# Correct execution...
```

**So, the comment in the documentation about `--pre` and `--post` being relative to the "action directory" is incorrect and misleading!** It seems they are relative to the current working directory instead:

```bash
❯ pwd
.../repo
❯ mkdir test
❯ cd test
❯ pwd
.../repo/test
❯ npx @github/local-action ../generic ../src/generic/main.ts ../.env --post ../src/generic/main.ts
_ _ _ ____ _
/ \ ___| |_(_) ___ _ __ | _ \ ___| |__ _ _ __ _ __ _ ___ _ __
/ _ \ / __| __| |/ _ \| '_ \ | | | |/ _ \ '_ \| | | |/ _` |/ _` |/ _ \ '__|
/ ___ \ (__| |_| | (_) | | | | | |_| | __/ |_) | |_| | (_| | (_| | __/ |
/_/ \_\___|\__|_|\___/|_| |_| |____/ \___|_.__/ \__,_|\__, |\__, |\___|_|
|___/ |___/
================================================================================
Configuration
================================================================================

┌─────────┬────────────────────┬────────────────────────────────┐
│ (index) │ Field │ Value │
├─────────┼────────────────────┼────────────────────────────────┤
│ 0 │ 'Action Path' │ '.../repo/generic' │
│ 1 │ 'Entrypoint' │ '.../repo/src/generic/main.ts' │
│ 2 │ 'Post Entrypoint' │ '.../repo/src/generic/main.ts' │
│ 3 │ 'Environment File' │ '.../repo/.env' │
└─────────┴────────────────────┴────────────────────────────────┘

# Correct execution...

❯ cd ../..
❯ pwd
...
❯ npm i @actions/artifact @actions/cache @actions/core @actions/github @github/local-action
❯ npx @github/local-action repo/generic ../src/generic/main.ts repo/.env --post repo/src/generic/main.ts
_ _ _ ____ _
/ \ ___| |_(_) ___ _ __ | _ \ ___| |__ _ _ __ _ __ _ ___ _ __
/ _ \ / __| __| |/ _ \| '_ \ | | | |/ _ \ '_ \| | | |/ _` |/ _` |/ _ \ '__|
/ ___ \ (__| |_| | (_) | | | | | |_| | __/ |_) | |_| | (_| | (_| | __/ |
/_/ \_\___|\__|_|\___/|_| |_| |____/ \___|_.__/ \__,_|\__, |\__, |\___|_|
|___/ |___/
================================================================================
Configuration
================================================================================

┌─────────┬────────────────────┬────────────────────────────────┐
│ (index) │ Field │ Value │
├─────────┼────────────────────┼────────────────────────────────┤
│ 0 │ 'Action Path' │ 'repo/generic' │
│ 1 │ 'Entrypoint' │ 'repo/src/generic/main.ts' │
│ 2 │ 'Post Entrypoint' │ 'repo/src/generic/main.ts' │
│ 3 │ 'Environment File' │ 'repo/.env' │
└─────────┴────────────────────┴────────────────────────────────┘
```

which looks like another correct execution, but the behaviour is, in fact, incorrect, if someone has safety checks in the `post` run related to state passing from `main` to `post`.

Here is a minimal reproducer for `src/generic/main.ts`:

```typescript
import * as core from "@actions/core";

const isPostActionChecked = {
inMain: false,
inPost: false,
};

export async function run(): Promise {
const isPostAction = !!core.getState("isPostAction");
if (!isPostAction) {
core.info("In main...");
if (!isPostActionChecked.inMain) {
isPostActionChecked.inMain = true;
} else {
throw new Error("isPostAction() already checked in 'main' run");
}

core.saveState("isPostAction", "true");
} else {
core.info("In post...");
if (!isPostActionChecked.inPost) {
isPostActionChecked.inPost = true;
} else {
throw new Error("isPostAction() already checked in 'post' run");
}
}
}
```

```bash
# Executing from OUTSIDE the repository, correct paths and incorrect behaviour:
❯ npx @github/local-action repo/generic ../src/generic/main.ts repo/.env --post repo/src/generic/main.ts
================================================================================
Running Action
================================================================================

In main...
::save-state name=isPostAction::true

================================================================================
Running Post Step
================================================================================

In main...
.../repo/src/generic/main.ts:15
throw new Error("isPostAction() already checked in 'main' run");
^

Error: isPostAction() already checked in 'main' run
```

```bash
# Execution of the same code from INSIDE the repository, correct paths and correct behaviour...
❯ npx @github/local-action ./generic ../src/generic/main.ts ./.env --post ./src/generic/main.ts
================================================================================
Running Action
================================================================================

::info::In main...

================================================================================
Running Post Step
================================================================================

::info::In post...

```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.