Skip to content

Commit cfca9e1

Browse files
authored
Add support for pre/post commands (#203)
This pull request introduces support for `pre` and `post` scripts in GitHub Actions, updates documentation to reflect these changes, and adds fixtures to test the functionality across different languages and module systems. Closes #183 ### Documentation Updates: * [`CHANGELOG.md`](diffhunk://#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4edR3-R13): Added an entry for version 4, highlighting support for `pre` and `post` scripts in GitHub Actions. * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L185-R213): Updated the `local-action run` command to include optional `--pre` and `--post` arguments, along with examples and descriptions for their usage. ### Fixture Additions for `pre` and `post` Scripts: * JavaScript Fixtures: - Added `pre` and `post` scripts with `index.js` and `main.js` files in `__fixtures__/javascript/success` and `__fixtures__/javascript-esm/success`. These scripts demonstrate basic input handling and output setting for actions. [[1]](diffhunk://#diff-f8541f0b923ac556ae7560287567c67d2bac46beb480a11ee286b5fe5603d73dR1-R3) [[2]](diffhunk://#diff-13b3808981fc67a311be46f6573b193dcfda3dac1699c1e934287249cdcd7b63R1-R13) * TypeScript Fixtures: - Added `pre` and `post` scripts with `index.ts` and `main.ts` files in `__fixtures__/typescript/success` and `__fixtures__/typescript-esm/success`. These scripts showcase similar functionality as the JavaScript fixtures but with TypeScript syntax. [[1]](diffhunk://#diff-92977f7e53208fa72e2158e41d5402f216d40720463ecd30f2a2f00781c66f65R1-R3) [[2]](diffhunk://#diff-d61a1b02638db9fb7d01bdf456f72897331cdfc738572de62445b52b13b370dbR1-R9) [[3]](diffhunk://#diff-26abda3a139ba9b44e9ef716318f64217b26df0165d0ed9fb1cc2b6acc4b1cecR1-R3) [[4]](diffhunk://#diff-aeff2990bef1136e31d03757577627865298369c2286e6c2a7c4fa58f929b0c1R1-R9) ### Utility Mock: * [`__fixtures__/path.ts`](diffhunk://#diff-92b0347f0720c1eaba4d2f5d1e79e0e96de62442f21dc09e1d7faf51aed10042R1-R7): Added a mock implementation of the `resolve` function using Jest for testing purposes.
2 parents 4c3ce0b + 1c4a59a commit cfca9e1

File tree

36 files changed

+694
-253
lines changed

36 files changed

+694
-253
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v4
4+
5+
This version adds support for
6+
[`pre`](https://docs.github.com/en/actions/reference/metadata-syntax-for-github-actions#runspre)
7+
and
8+
[`post`](https://docs.github.com/en/actions/reference/metadata-syntax-for-github-actions#runspost)
9+
scripts for actions. These should follow the same structure as the `run` action
10+
code (see the
11+
[`README.md`](https://github.com/github/local-action#action-structure) for more
12+
details).
13+
314
## v3
415

516
This version adds **experimental** support for [pnpm](https://pnpm.io/) and

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,35 @@ For additional information about transpiled action code, see
182182
| `-h`, `--help` | Display help information |
183183
| `-V`, `--version` | Display version information |
184184

185-
### `local-action run <path> <logic entrypoint> <dotenv file>`
186-
187-
| Argument | Description |
188-
| ------------------ | ------------------------------------------------------ |
189-
| `path` | Path to the local action directory |
190-
| | Example: `/path/to/action.yml` |
191-
| `logic entrypoint` | Action logic entrypoint (relative to action directory) |
192-
| | Example: `src/main.ts` |
193-
| `dotenv file` | Path to the local `.env` file for action inputs |
194-
| | Example: `/path/to/.env` |
195-
| | See the example [`.env.example`](.env.example) |
185+
### `local-action run <path> <logic entrypoint> <dotenv file> [--pre <pre entrypoint>] [--post <post entrypoint>]`
186+
187+
| Argument | Description |
188+
| -------------------------- | ------------------------------------------------------------------- |
189+
| `path` | Path to the local action directory |
190+
| | Example: `/path/to/action.yml` |
191+
| `logic entrypoint` | Action logic entrypoint (relative to action directory) |
192+
| | Example: `src/main.ts` |
193+
| `dotenv file` | Path to the local `.env` file for action inputs |
194+
| | Example: `/path/to/.env` |
195+
| | See the example [`.env.example`](.env.example) |
196+
| `--pre <pre entrypoint>` | (Optional) `pre` command entrypoint (relative to action directory) |
197+
| | Example: `pre/main.ts` |
198+
| `--post <post entrypoint>` | (Optional) `post` command entrypoint (relative to action directory) |
199+
| | Example: `post/main.ts` |
196200

197201
Examples:
198202

199203
```bash
200-
local-action run /path/to/typescript-action src/main.ts .env
204+
local-action run /path/to/typescript-action src/main.ts .env --pre pre/main.ts --post post/main.ts
201205

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

206210
#### Output
207211

208212
```console
209-
$ local-action run /path/to/typescript-action src/main.ts .env
213+
$ local-action run /path/to/typescript-action src/main.ts .env --pre pre/main.ts --post post/main.ts
210214
_ _ _ ____ _
211215
/ \ ___| |_(_) ___ _ __ | _ \ ___| |__ _ _ __ _ __ _ ___ _ __
212216
/ _ \ / __| __| |/ _ \| '_ \ | | | |/ _ \ '_ \| | | |/ _` |/ _` |/ _ \ '__|
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { run } = require('./main')
2+
3+
run()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { getInput, info, setOutput } = require('@actions/core')
2+
3+
async function run() {
4+
const myInput = getInput('myInput')
5+
6+
setOutput('myOutput', myInput)
7+
8+
info('JavaScript Action Succeeded!')
9+
}
10+
11+
module.exports = {
12+
run
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { run } = require('./main')
2+
3+
run()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { getInput, info, setOutput } = require('@actions/core')
2+
3+
async function run() {
4+
const myInput = getInput('myInput')
5+
6+
setOutput('myOutput', myInput)
7+
8+
info('JavaScript Action Succeeded!')
9+
}
10+
11+
module.exports = {
12+
run
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { run } = require('./main')
2+
3+
run()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { getInput, info, setOutput } = require('@actions/core')
2+
3+
async function run() {
4+
const myInput = getInput('myInput')
5+
6+
setOutput('myOutput', myInput)
7+
8+
info('JavaScript Action Succeeded!')
9+
}
10+
11+
module.exports = {
12+
run
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { run } = require('./main')
2+
3+
run()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { getInput, info, setOutput } = require('@actions/core')
2+
3+
async function run() {
4+
const myInput = getInput('myInput')
5+
6+
setOutput('myOutput', myInput)
7+
8+
info('JavaScript Action Succeeded!')
9+
}
10+
11+
module.exports = {
12+
run
13+
}

0 commit comments

Comments
 (0)