Skip to content

Commit

Permalink
Restructure and Documentation (#32)
Browse files Browse the repository at this point in the history
This pull request primarily focuses on improving the code quality and
readability of the project. It involves changes to the ESLint
configuration, updates to the GitHub Actions workflow, and modifications
to the `README.md` and `CONTRIBUTING.md` files. Furthermore, the pull
request includes updates to the test suite and several fixture files.

### General Configuration

- Moved linting/configuration files out of `.github/linters` for
visibility.
- Added the `LINTER_RULES_PATH` environment variable to the `linter.yml`
workflow to update the path where the linter rules are located.
- Trim `.gitignore` down.

### ESLint Configuration

- Remove unnecessary paths from `.eslintignore`.
- Ignore several linting rules related to `.js` files being used as test
fixtures.
- Update to use ECMAScript version ES2022.

### TypeScript Configuration

- Enabled `.js` imports for JavaScript actions.

### Testing

- Switched from Mocha/Chai to Jest for testing (Chai required
dependencies that were no longer being maintained).
- Separated test fixtures by language.
- Added basic TypeScript/JavaScript test fixtures to simulate actions
projects.
- Added mocks for `@actions/core`.
- Disabled caching to resolve errors when testing `commands/run.ts`.
- Added 

### Documentation

- Several small tweaks to `README.md` (formatting and clarity). 
- Added `npm link` testing instructions to `CONTRIBUTING.md`.

### Functionality/Logic

- Moved the `@actions/core` stubs to separate exported functions.
- Separated types and enums into their own code files.

Closes #31
  • Loading branch information
ncalteen authored Feb 8, 2024
2 parents 80e8b66 + ba85f2b commit dd9dee7
Show file tree
Hide file tree
Showing 69 changed files with 7,153 additions and 3,696 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib/
dist/
node_modules/
coverage/
*.json
27 changes: 14 additions & 13 deletions .github/linters/.eslintrc.yml → .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
env:
es2022: true
node: true
es6: true
mocha: true
jest: true

globals:
Atomics: readonly
SharedArrayBuffer: readonly

ignorePatterns:
- '!.*'
- '**/node_modules/.*'
- '**/dist/.*'
- '**/coverage/.*'
- '*.json'
- node_modules/.*
- coverage/.*

parser: '@typescript-eslint/parser'

parserOptions:
ecmaVersion: 2023
sourceType: module
ecmaVersion: 2022
project:
- './.github/linters/tsconfig.eslint.json'
- './tsconfig.json'
- tsconfig.eslint.json
- tsconfig.json

plugins:
- '@typescript-eslint'
Expand All @@ -31,17 +27,22 @@ settings:
typescript: {}

extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended-requiring-type-checking
- plugin:@typescript-eslint/recommended
- eslint:recommended
- plugin:github/recommended
- plugin:import/typescript
- plugin:jest/recommended

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-console': 'off',
'no-unused-vars': 'off'
}
9 changes: 0 additions & 9 deletions .github/linters/tsconfig.eslint.json

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
id: setup-node
Expand All @@ -40,6 +42,10 @@ jobs:
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JAVASCRIPT_DEFAULT_STYLE: prettier
LINTER_RULES_PATH: .
TYPESCRIPT_DEFAULT_STYLE: prettier
VALIDATE_ALL_CODEBASE: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JSCPD: false
VALIDATE_TYPESCRIPT_STANDARD: false
103 changes: 4 additions & 99 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,102 +1,7 @@
# Dependency directory
node_modules

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# OS metadata
.DS_Store
coverage
node_modules
npm-debug.log*
reports
Thumbs.db

# Ignore built ts files
__tests__/runner/*

# IDE files
.idea
*.code-workspace
File renamed without changes.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.6.0
File renamed without changes.
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ This project requires **100%** test coverage.
> introducing any regressions. All changes will be throughly tested by
> maintainers of this repository before a new release is created.
### Testing Local Updates

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

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

```bash
npm link
```

1. Test your updated version

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

# Or...
npm exec local-action run <path> <entrypoint> <env file>
```

Once you're finished testing, make sure to unlink!

```bash
npm unlink @github/local-action
```

### Running the Test Suite

Simply run the following command to execute the entire test suite:
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

![GitHub Super-Linter](https://github.com/github/local-action/actions/workflows/linter.yml/badge.svg)
![Continuous Integration](https://github.com/github/local-action/actions/workflows/continuous-integration.yml/badge.svg)
![Coverage](badges/coverage.svg)
![Code Coverage](badges/coverage.svg)

Run custom GitHub Actions locally and test them in VS Code!

This command-line tool emulates functionality of the
This command-line tool emulates some **basic** functionality of the
[GitHub Actions Toolkit](https://github.com/actions/toolkit) so that custom
actions can be run directly on your workstation.

Expand Down Expand Up @@ -158,13 +158,13 @@ $ local-action run /path/to/typescript-action src/index.ts .env
Configuration
================================================================================

┌─────────┬────────────────────┬──────────────────────────────────────────┐
│ (index) │ Field │ Value │
├─────────┼────────────────────┼──────────────────────────────────────────┤
│ 0 │ 'Action Path' │ '/path/to/typescript-action' │
┌─────────┬────────────────────┬──────────────────────────────────────────
│ (index) │ Field │ Value
├─────────┼────────────────────┼──────────────────────────────────────────
│ 0 │ 'Action Path' │ '/path/to/typescript-action'
│ 1 │ 'Entrypoint' │ '/path/to/typescript-action/src/index.ts' │
│ 2 │ 'Environment File' │ '/path/to/local-action-debugger/.env' │
└─────────┴────────────────────┴──────────────────────────────────────────┘
│ 2 │ 'Environment File' │ '/path/to/local-action-debugger/.env'
└─────────┴────────────────────┴──────────────────────────────────────────

================================================================================
Action Metadata
Expand All @@ -190,7 +190,7 @@ $ local-action run /path/to/typescript-action src/index.ts .env
## Debugging in VS Code

This package can also be used with VS Code's built-in debugging tools. You just
need to add a `launch.json` to the directory containing your local action. The
need to add a `launch.json` to the project containing your local action. The
following can be used as an example.

```json
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: MyAction
name: JavaScript (Failing)
description: This action sets a failure status

runs:
Expand Down
6 changes: 6 additions & 0 deletions __fixtures__/javascript/failure/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */

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

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
12 changes: 12 additions & 0 deletions __fixtures__/javascript/failure/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* 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!')
}

module.exports = {
run
}
File renamed without changes.
16 changes: 16 additions & 0 deletions __fixtures__/javascript/no-import/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: JavaScript (No Import)
description: This action doesn't import any dependencies

inputs:
myInput:
description: An input
required: true
default: 'default value'

outputs:
myOutput:
description: An output

runs:
using: node20
main: dist/index.js
6 changes: 6 additions & 0 deletions __fixtures__/javascript/no-import/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */

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

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
10 changes: 10 additions & 0 deletions __fixtures__/javascript/no-import/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable import/no-commonjs */

// eslint-disable-next-line @typescript-eslint/require-await
async function run() {
return
}

module.exports = {
run
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: MyAction
name: JavaScript (Success)
description: This action returns without error

inputs:
Expand Down
6 changes: 6 additions & 0 deletions __fixtures__/javascript/success/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */

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

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
14 changes: 14 additions & 0 deletions __fixtures__/javascript/success/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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)
core.info('JavaScript Action Succeeded!')
}

module.exports = {
run
}
File renamed without changes.
6 changes: 6 additions & 0 deletions __fixtures__/typescript/failure/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: TypeScript (Failing)
description: This action sets a failure status

runs:
using: node20
main: dist/index.js
4 changes: 4 additions & 0 deletions __fixtures__/typescript/failure/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { run } from './main'

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

// eslint-disable-next-line @typescript-eslint/require-await
export async function run(): Promise<void> {
core.setFailed('TypeScript Action Failed!')
}
8 changes: 8 additions & 0 deletions __fixtures__/typescript/no-import/.env.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Do not commit your actual .env file to Git! This may contain secrets or other
# private information.

# GitHub Actions inputs should follow `INPUT_<name>` format (case-insensitive).
INPUT_milliseconds=2400

# Enable/disable step debug logs
ACTIONS_STEP_DEBUG=false
Loading

0 comments on commit dd9dee7

Please sign in to comment.