Skip to content

Add support for pre/post commands #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v4

This version adds support for
[`pre`](https://docs.github.com/en/actions/reference/metadata-syntax-for-github-actions#runspre)
and
[`post`](https://docs.github.com/en/actions/reference/metadata-syntax-for-github-actions#runspost)
scripts for actions. These should follow the same structure as the `run` action
code (see the
[`README.md`](https://github.com/github/local-action#action-structure) for more
details).

## v3

This version adds **experimental** support for [pnpm](https://pnpm.io/) and
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,35 @@ For additional information about transpiled action code, see
| `-h`, `--help` | Display help information |
| `-V`, `--version` | Display version information |

### `local-action run <path> <logic entrypoint> <dotenv file>`

| Argument | Description |
| ------------------ | ------------------------------------------------------ |
| `path` | Path to the local action directory |
| | Example: `/path/to/action.yml` |
| `logic entrypoint` | Action logic entrypoint (relative to action directory) |
| | Example: `src/main.ts` |
| `dotenv file` | Path to the local `.env` file for action inputs |
| | Example: `/path/to/.env` |
| | See the example [`.env.example`](.env.example) |
### `local-action run <path> <logic entrypoint> <dotenv file> [--pre <pre entrypoint>] [--post <post entrypoint>]`

| Argument | Description |
| -------------------------- | ------------------------------------------------------------------- |
| `path` | Path to the local action directory |
| | Example: `/path/to/action.yml` |
| `logic entrypoint` | Action logic entrypoint (relative to action directory) |
| | Example: `src/main.ts` |
| `dotenv file` | Path to the local `.env` file for action inputs |
| | Example: `/path/to/.env` |
| | See the example [`.env.example`](.env.example) |
| `--pre <pre entrypoint>` | (Optional) `pre` command entrypoint (relative to action directory) |
| | Example: `pre/main.ts` |
| `--post <post entrypoint>` | (Optional) `post` command entrypoint (relative to action directory) |
| | Example: `post/main.ts` |

Examples:

```bash
local-action run /path/to/typescript-action src/main.ts .env
local-action run /path/to/typescript-action src/main.ts .env --pre pre/main.ts --post post/main.ts

# The `run` action is invoked by default as well
local-action /path/to/typescript-action src/main.ts .env
local-action /path/to/typescript-action src/main.ts .env --pre pre/main.ts --post post/main.ts
```

#### Output

```console
$ local-action run /path/to/typescript-action src/main.ts .env
$ local-action run /path/to/typescript-action src/main.ts .env --pre pre/main.ts --post post/main.ts
_ _ _ ____ _
/ \ ___| |_(_) ___ _ __ | _ \ ___| |__ _ _ __ _ __ _ ___ _ __
/ _ \ / __| __| |/ _ \| '_ \ | | | |/ _ \ '_ \| | | |/ _` |/ _` |/ _ \ '__|
Expand Down
3 changes: 3 additions & 0 deletions __fixtures__/javascript-esm/success/post/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { run } = require('./main')

run()
13 changes: 13 additions & 0 deletions __fixtures__/javascript-esm/success/post/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getInput, info, setOutput } = require('@actions/core')

async function run() {
const myInput = getInput('myInput')

setOutput('myOutput', myInput)

info('JavaScript Action Succeeded!')
}

module.exports = {
run
}
3 changes: 3 additions & 0 deletions __fixtures__/javascript-esm/success/pre/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { run } = require('./main')

run()
13 changes: 13 additions & 0 deletions __fixtures__/javascript-esm/success/pre/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getInput, info, setOutput } = require('@actions/core')

async function run() {
const myInput = getInput('myInput')

setOutput('myOutput', myInput)

info('JavaScript Action Succeeded!')
}

module.exports = {
run
}
3 changes: 3 additions & 0 deletions __fixtures__/javascript/success/post/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { run } = require('./main')

run()
13 changes: 13 additions & 0 deletions __fixtures__/javascript/success/post/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getInput, info, setOutput } = require('@actions/core')

async function run() {
const myInput = getInput('myInput')

setOutput('myOutput', myInput)

info('JavaScript Action Succeeded!')
}

module.exports = {
run
}
3 changes: 3 additions & 0 deletions __fixtures__/javascript/success/pre/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { run } = require('./main')

run()
13 changes: 13 additions & 0 deletions __fixtures__/javascript/success/pre/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getInput, info, setOutput } = require('@actions/core')

async function run() {
const myInput = getInput('myInput')

setOutput('myOutput', myInput)

info('JavaScript Action Succeeded!')
}

module.exports = {
run
}
7 changes: 7 additions & 0 deletions __fixtures__/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { jest } from '@jest/globals'

export const resolve = jest.fn()

export default {
resolve
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript-esm/success/post/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main.js'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript-esm/success/post/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript ESM Action Succeeded!')
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript-esm/success/pre/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main.js'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript-esm/success/pre/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript ESM Action Succeeded!')
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript/success-yaml/post/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript/success-yaml/post/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript Action Succeeded!')
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript/success-yaml/pre/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript/success-yaml/pre/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript Action Succeeded!')
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript/success/post/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript/success/post/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript Action Succeeded!')
}
3 changes: 3 additions & 0 deletions __fixtures__/typescript/success/pre/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './main'

run()
9 changes: 9 additions & 0 deletions __fixtures__/typescript/success/pre/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getInput, info, setOutput } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

info('TypeScript Action Succeeded!')
}
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy