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:
❯ 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!
❯ pwd
.../repo
❯ npx @github/local-action ./generic ../src/generic/main.ts .env --post ../src/generic/main.ts
error: option '--post <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?
❯ 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:
❯ 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:
import * as core from "@actions/core";
const isPostActionChecked = {
inMain: false,
inPost: false,
};
export async function run(): Promise<void> {
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");
}
}
}
# 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
# 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...
Given the following directory structure:
for example, using https://github.com/actions/cache's sub-actions
saveandrestore. Importantly, there is noaction.ymlin the root directory of the repository, and this is by design! (Imagine in the future not justgeneric/action.ymlbut other things likevideo/action.ymlordocker/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:So, relative to
./generic'saction.yml, thesrc/...things are in../src, right? I still get an error!It seems that you must make the main entry point correctly relative, but the
--postentry-point should be relative to the current working directory?So, the comment in the documentation about
--preand--postbeing relative to the "action directory" is incorrect and misleading! It seems they are relative to the current working directory instead:which looks like another correct execution, but the behaviour is, in fact, incorrect, if someone has safety checks in the
postrun related to state passing frommaintopost.Here is a minimal reproducer for
src/generic/main.ts:# 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...