github / github/local-action

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

オープン
#271 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
451
フォーク
28
PR マージ指標
30日以内にマージされた PR はありません

説明

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

```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、--pre と --post のドキュメント、および action.yml の場所を基準としたパス処理を確認します。提供されている src/generic/main.ts の再現コードを使い、リポジトリ内とリポジトリ外からの実行を比較します。main から post に渡される状態も比較対象に含めます。ドキュメント化されたパスの動作と post ステップの状態処理が一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
github-actions, node.js, typescript
領域
cli
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。