github / github/local-action

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

Đang mở
#271 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
451
Fork
28
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách kiểm tra tài liệu về --pre và --post cũng như cách xử lý đường dẫn xung quanh vị trí của action.yml. Sử dụng trình tái hiện src/generic/main.ts được cung cấp để so sánh các lần thực thi từ bên trong và bên ngoài repository, bao gồm cả trạng thái được truyền từ main sang post. Được xem là hoàn tất khi hành vi đường dẫn được ghi chép và cách xử lý trạng thái của bước post nhất quán với nhau.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
github-actions, node.js, typescript
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.