Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
brenoepics committed May 9, 2024

Verified

This commit was signed with the committer’s verified signature.
jarededwards Jared Edwards
1 parent a671408 commit a778153
Showing 3 changed files with 29 additions and 101 deletions.
126 changes: 27 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,46 @@
# GitHub Action Template
# PRP Preprocessor

> [!NOTE]
> Docs: [docs.github.com](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action)
This repository contains a template for creating a GitHub Action using
TypeScript. It includes a set of workflows that automate the process of testing,
building, and checking the code.

## Action Details

The main entry point for the action is `src/index.ts`, which imports and runs
the `run` function from `src/main.ts`. This function retrieves an input named
"who-to-greet" and then sets an output named hello with the value "Hello,
<who-to-greet>!".
The PRP Preprocessor is a GitHub Action that allows you to replace variables in a text file. The variables are defined
in a map and can be used in the text file with the following syntax: `{_ variable _}`. Spaces are allowed around the
variable name.

## Development

The code is written in TypeScript and transpiled to JavaScript for distribution.
The `tsconfig.json` file contains the TypeScript compiler options. The
`package.json` file contains various scripts for formatting, linting, testing,
and building the code. The `preinstall` script ensures that `pnpm` is used as
the package manager.

## Usage
## Installation

To use this action in a workflow, you can reference it with the `uses` keyword
and the path to the repository. You can also specify inputs with the `with`
keyword. For example:
To install the PRP Preprocessor, you can add it as a step in your GitHub Actions workflow.
Here's an example of how to
use it:

```yaml
steps:
- name: Example Step
uses: ./ # Uses an action in the root directory, if you push this repository to GitHub, you can use the following: uses: <username>/typescript-action-template@v1
- name: PRP Preprocessor
uses: brenoepics/prp-preprocessor@v1
with:
who-to-greet: "Mona the Octocat"
```
This will run the action with the input `who-to-greet` set to "Mona the Octocat"

## Adding Inputs and Outputs

> [!NOTE]
> Docs: [docs.github.com](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions)

To add inputs and outputs to your GitHub Action, you need to define them in the
`action.yml` file. Inputs are defined under the `inputs` field and outputs under
the `outputs` field. Each input or output has a unique ID, a description, and
other optional properties. For example, an input could be defined as follows:

```yaml
inputs:
my-input:
description: "Description of the input"
required: true
default: "Default value"
rootDir: './example'
extension: '.prp'
```
And an output could be defined as follows:

```yaml
outputs:
my-output:
description: "Description of the output"
```

In your TypeScript code, you can use the `core.getInput` function from the
`@actions/core` package to retrieve the value of an input, and the
`core.setOutput` function to set the value of an output.

## Running the Action Locally

> [!TIP]
> If you don't want to install `act` on your environment, you can use GitHub Codespaces to run the action.

### Nektos/act
## Usage
> [!NOTE]
> Docs: [Nektos](https://nektosact.com/introduction.html)

Install [Nektos/act](https://github.com/nektos/act) and run the following
command:

```bash
act push -W .github/workflows/ci.yml
```

## Workflows

There are several workflows defined in the `.github/workflows` directory:
> TODO
- `ci.yml`: This workflow runs on every push or pull request to the `main`
branch. It checks out the code, installs dependencies using `pnpm`, checks the
code formatting, lints the code, runs tests, and then runs the action with a
greeting.
## Inputs
- `check-dist.yml`: This workflow also runs on every push or pull request to the
`main` branch. It checks out the code, installs dependencies, builds the
`dist/` directory, and then checks if the `dist/` directory matches the
expected output. If it doesn't, the workflow fails and uploads the expected
`dist/` directory as a workflow artifact.
The PRP Preprocessor accepts the following inputs:
- `codeql-analysis.yml`: This workflow runs on every push or pull request to the
`main` branch, as well as on a schedule. It checks out the code, initializes
CodeQL with the TypeScript language, auto builds the code, and then performs a
CodeQL analysis.
| Name | Description | Required | Default |
|------------------|-----------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------------|
| `rootDir` | The root directory to start searching for files. | Yes | . |
| `extension` | The extension of the files to process. | Yes | .prp |
| `includeSubDirs` | Whether to include subdirectories in the search for files. | No | false |
| `ignoredVars` | A list of variables to ignore. | No | [] |
| `ignoredDirs` | A list of directories to ignore, according to the [.gitignore spec 2.22.1.](https://git-scm.com/docs/gitignore) | No | ["node_modules",".git",".github","__tests__",".vscode",".idea"] |
| `encodings` | The encoding to use when reading and writing files. | No | utf8 |

## Dependencies
## Outputs

The action uses the `@actions/core` and `@actions/github` packages as
dependencies. The `@actions/core` package provides functions for getting inputs
and setting outputs, among other things. The `@actions/github` package provides
GitHub-related functionality.
The PRP Preprocessor does not produce any outputs.

## License

This project is licensed under Apache-2.0. See the [LICENSE](LICENSE) file for
details.
This project is licensed under the Apache-2.0 License.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -25805,7 +25805,7 @@ exports.processFiles = processFiles;
function replaceVariables(variables, content) {
let newContent = content.toString();
variables.forEach((value, key) => {
newContent = newContent.replace(new RegExp(`\\{\\s*_\\s*${key.trim()}\\s*_\\s*\\}`, "g"), value);
newContent = newContent.replaceAll(new RegExp(`\\{\\s*_\\s*${key.trim()}\\s*_\\s*\\}`, "g"), value);
});
return newContent;
}
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit a778153

Please sign in to comment.