Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1b2f809
Enable step debug mode in example .env
ncalteen Feb 15, 2024
3a39db3
Re-enable several linting rules
ncalteen Feb 15, 2024
8d4bef3
Add example actions to test against
ncalteen Feb 15, 2024
633fb7a
TSConfig cleanup
ncalteen Feb 15, 2024
6bb931e
Clean up linting errors in fixtures
ncalteen Feb 15, 2024
f0ed668
Mock tsconfig-paths
ncalteen Feb 15, 2024
5c4e476
Add/update tests
ncalteen Feb 15, 2024
2c0a920
Switch to tsx
ncalteen Feb 15, 2024
421d4b3
Add docstring
ncalteen Feb 15, 2024
2418f5f
Switch to async call
ncalteen Feb 15, 2024
a5b684b
Clarify types
ncalteen Feb 15, 2024
41aa17c
Rename env to dotenv
ncalteen Feb 15, 2024
1b4632f
Move check functions
ncalteen Feb 15, 2024
8d78894
Add function docstring
ncalteen Feb 15, 2024
bbdceb0
Add docstrings and correct types
ncalteen Feb 15, 2024
19f8927
Add types
ncalteen Feb 15, 2024
cc0b9fa
Documentation
ncalteen Feb 15, 2024
90d6b0d
Additional comments and typing
ncalteen Feb 15, 2024
43faf24
Additional comments and typing
ncalteen Feb 15, 2024
56e3f1b
Add TSConfig bootstrap
ncalteen Feb 15, 2024
dbb7cac
Add basic local-action script
ncalteen Feb 15, 2024
1e2bfbb
Direct local-action to new script
ncalteen Feb 15, 2024
98a5b89
Note v1.0.0 changes
ncalteen Feb 15, 2024
b4d6c5b
Note actions step debug setting
ncalteen Feb 15, 2024
8816b38
Ignore extra dirs
ncalteen Feb 15, 2024
afc7fe0
Update ignored linting files
ncalteen Feb 15, 2024
b8b3848
Update prettier config
ncalteen Feb 15, 2024
9d88f09
Update support info
ncalteen Feb 15, 2024
408d057
Add tests for variable types
ncalteen Feb 15, 2024
5cacaac
Remove extra test
ncalteen Feb 15, 2024
e1b429f
Remove extra const
ncalteen Feb 15, 2024
b7329a2
Ignore .js for coverage
ncalteen Feb 15, 2024
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
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# GitHub Actions inputs should follow `INPUT_<name>` format (case-insensitive).
INPUT_milliseconds=2400

# Enable/disable step debug logs
ACTIONS_STEP_DEBUG=false
# Enable/disable step debug logging. Normally this is false by default, but for
# the purpose of debugging, it is set to true here.
ACTIONS_STEP_DEBUG=true
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.github/
.vscode/
badges/
bin/
coverage/
dist/
node_modules/
coverage/
reports/
*.json
6 changes: 0 additions & 6 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ globals:
Atomics: readonly
SharedArrayBuffer: readonly

ignorePatterns:
- node_modules/.*
- coverage/.*

parser: '@typescript-eslint/parser'

parserOptions:
Expand Down Expand Up @@ -38,11 +34,9 @@ extends:
rules:
{
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'camelcase': 'off',
'eslint-comments/no-use': 'off',
'i18n-text/no-en': 'off',
'import/no-namespace': 'off',
'no-console': 'off',
'no-unused-vars': 'off'
}
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
dist/
node_modules/
coverage/
reports/
20 changes: 10 additions & 10 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
arrowParens: avoid
bracketSameLine: true
bracketSpacing: true
endOfLine: lf
htmlWhitespaceSensitivity: css
jsxSingleQuote: false
printWidth: 80
tabWidth: 2
useTabs: false
proseWrap: always
quoteProps: as-needed
semi: false
singleQuote: true
quoteProps: as-needed
jsxSingleQuote: false
tabWidth: 2
trailingComma: none
bracketSpacing: true
bracketSameLine: true
arrowParens: avoid
proseWrap: always
htmlWhitespaceSensitivity: css
endOfLine: lf
useTabs: false
48 changes: 41 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Contributing

All contributions are welcome and greatly appreciated!
All contributions are welcome and greatly appreciated! However, please try to
keep them limited in scope so that they can be more easily reviewed.

## Steps to Contribute

Expand All @@ -13,16 +14,23 @@ All contributions are welcome and greatly appreciated!
> version automatically.

1. Fork this repository
1. Clone your fork
1. Install the dependencies with `npm install`
1. Make and test your changes
1. Commit your changes
1. Test your changes
1. Make sure to run `npm run all` before committing your final changes!

Make sure to do the following when you commit your changes:

- Increase the version number in [`package.json`](./package.json)
- Run `npm install` to ensure dependencies are up to date
- Run `npm run all` to run formatting, linting, etc.

1. Open a pull request back to this repository
1. Notify the maintainers of this repository for peer review and approval
1. Merge :tada:

The maintainers of this repository will create a new release with your changes
so that everyone can use the new release and enjoy the awesome features of
branch deployments!
so that everyone can enjoy your contributions!

## Testing

Expand All @@ -37,7 +45,7 @@ This project requires **100%** test coverage.
### Testing Local Updates

As you make changes, it's a great idea to run the `local-action` tool regularly
against any testing repositories.
against various repositories with different configurations.

1. Symlink your package folder (this should only need to be done once)

Expand All @@ -60,9 +68,35 @@ Once you're finished testing, make sure to unlink!
npm unlink @github/local-action
```

#### Example Actions to Test

After making updates and running the test suite, please also make sure to test
your updates using the following GitHub Actions repositories:

- [`actions/javascript-action`](https://github.com/actions/javascript-action)
- [`actions/typescript-action`](https://github.com/actions/typescript-action)

1. Clone each repository locally
1. From your `github/local-action` fork, test each action

```bash
npm exec local-action \
"/<action repository clone path>/typescript-action" \
"src/index.ts" \
"<path to your .env file>"

npm exec local-action \
"/<action repository clone path>/javascript-action" \
"src/index.ts" \
"<path to your .env file>"
```

For an example `.env` file to use for testing, see
[`.env.example`](./.env.example).

### Running the Test Suite

Simply run the following command to execute the entire test suite:
Simply run the following command to invoke the entire test suite:

```bash
npm run test
Expand Down
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ actions can be run directly on your workstation.
>
> This tool currently only supports JavaScript and TypeScript actions!

## v1.0.0 Changes

With the release of `v1.0.0`, there was a need to switch from
[`ts-node`](https://www.npmjs.com/package/ts-node) to
[`tsx`](https://www.npmjs.com/package/tsx). However, the bundled version of
`tsx` is being used, so you should no longer need to install either :grinning:

## Prerequisites

### Installed Tools

- [Node.js and npm](https://nodejs.org/en)
- [`ts-node`](https://www.npmjs.com/package/ts-node)

### Action Structure

Expand Down Expand Up @@ -72,23 +78,24 @@ the following when preparing for release:

- Commit the `node_modules` directory to your repository
- Transpile your code and dependencies using tools like
[`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) or
[`@vercel/ncc`](https://www.npmjs.com/package/@vercel/ncc)

Currently, this tool supports **non-transpiled action code only**. This is
because it uses [`proxyquire`](https://github.com/thlorenz/proxyquire) to
override GitHub Actions Toolkit dependencies (e.g
**This tool supports non-transpiled action code only.** This is because it uses
[`proxyquire`](https://github.com/thlorenz/proxyquire) to override GitHub
Actions Toolkit dependencies (e.g
[`@actions/core`](https://www.npmjs.com/package/@actions/core)). In transpiled
code, this simply doesn't work.

For example, if you have a TypeScript action that follows the same format as the
[template](https://github.com/actions/typescript-action), you would have both
`src` and `dist` directories in your repository. The `dist` directory contains
the transpiled code with any dependencies included. When running this utility,
you will want to target the code files in the `src` directory instead. This has
the added benefit of being able to hook into debugging utilities in your IDE
:tada:
you will want to target the code files in the `src` directory instead (including
the dependencies this tool wants to replace). This has the added benefit of
being able to hook into debugging utilities in your IDE :tada:

For additional information, see
For additional information about transpiled action code, see
[Commit, tag, and push your action to GitHub](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action#commit-tag-and-push-your-action-to-github).

## Installation
Expand Down Expand Up @@ -123,6 +130,12 @@ For additional information, see
npm i -g .
```

Alternatively, you can link the package if you want to make code changes

```bash
npm link .
```

## Commands

### `local-action`
Expand All @@ -132,17 +145,26 @@ For additional information, see
| `-h`, `--help` | Display help information |
| `-V`, `--version` | Display version information |

### `local-action run <path> <entrypoint> <env file>`

| Argument | Description |
| ------------ | ---------------------------------------------------- |
| `path` | Path to the local action directory |
| | Example: `/path/to/action.yml` |
| `entrypoint` | Action entrypoint (relative to the action directory) |
| | Example: `src/index.ts` |
| `env 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> <entrypoint> <dotenv file>`

| Argument | Description |
| ------------- | ---------------------------------------------------- |
| `path` | Path to the local action directory |
| | Example: `/path/to/action.yml` |
| `entrypoint` | Action entrypoint (relative to the action directory) |
| | Example: `src/index.ts` |
| `dotenv file` | Path to the local `.env` file for action inputs |
| | Example: `/path/to/.env` |
| | See the example [`.env.example`](.env.example) |

Examples:

```bash
local-action run /path/to/typescript-action src/index.ts .env

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

#### Output

Expand Down
9 changes: 5 additions & 4 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Support

## How to file issues and get help
## How to Get Help

This project uses GitHub issues to track bugs and feature requests. Please
search the existing issues before filing new issues to avoid duplicates. For new
Expand All @@ -9,9 +9,10 @@ issues, file your bug or feature request as a new issue.
For help or questions about using this project, please feel free to submit an
issue as well.

This project is under active development and maintained by GitHub staff and the
community. We will do our best to respond to support, feature requests, and
community questions in a timely manner.
This project is under development and maintained by GitHub staff and the
community, however availability is limited . We will do our best to respond to
support, feature requests, and community questions in a timely manner, but there
is no "official" support for this project at this time.

## GitHub Support Policy

Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/javascript/failure/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-commonjs */

const { run } = require('./main')

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
3 changes: 2 additions & 1 deletion __fixtures__/javascript/failure/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable import/no-commonjs */

const core = require('@actions/core')

// eslint-disable-next-line @typescript-eslint/require-await
async function run() {
core.setFailed('JavaScript Action Failed!')
}
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/javascript/no-import/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-commonjs */

const { run } = require('./main')

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
2 changes: 1 addition & 1 deletion __fixtures__/javascript/no-import/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable import/no-commonjs */

// eslint-disable-next-line @typescript-eslint/require-await
async function run() {
return
}
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/javascript/success/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-commonjs */

const { run } = require('./main')

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
3 changes: 2 additions & 1 deletion __fixtures__/javascript/success/src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable import/no-commonjs */

const core = require('@actions/core')

// eslint-disable-next-line @typescript-eslint/require-await
async function run() {
const myInput = core.getInput('myInput')
core.setOutput('myOutput', myInput)
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/typescript/failure/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import { run } from './main'

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
7 changes: 4 additions & 3 deletions __fixtures__/typescript/failure/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
/* eslint-disable @typescript-eslint/require-await */

import { setFailed } from '@actions/core'

// eslint-disable-next-line @typescript-eslint/require-await
export async function run(): Promise<void> {
core.setFailed('TypeScript Action Failed!')
setFailed('TypeScript Action Failed!')
}
3 changes: 2 additions & 1 deletion __fixtures__/typescript/no-import/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import { run } from './main'

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
3 changes: 2 additions & 1 deletion __fixtures__/typescript/no-import/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line @typescript-eslint/require-await
/* eslint-disable @typescript-eslint/require-await */

export async function run(): Promise<void> {
return
}
3 changes: 2 additions & 1 deletion __fixtures__/typescript/success/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import { run } from './main'

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
11 changes: 6 additions & 5 deletions __fixtures__/typescript/success/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as core from '@actions/core'
/* eslint-disable @typescript-eslint/require-await */

import { getInput, info, setOutput } from '@actions/core'

// eslint-disable-next-line @typescript-eslint/require-await
export async function run(): Promise<void> {
const myInput: string = core.getInput('myInput')
core.setOutput('myOutput', myInput)
core.info('TypeScript Action Succeeded!')
const myInput: string = getInput('myInput')
setOutput('myOutput', myInput)
info('TypeScript Action Succeeded!')
}
2 changes: 2 additions & 0 deletions __mocks__/tsconfig-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const loadConfig = jest.fn().mockImplementation()
export const register = jest.fn().mockImplementation()
Loading