Skip to content

Commit

Permalink
feat: make commit with processed files
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed May 15, 2024
1 parent 2b59689 commit c7344cd
Show file tree
Hide file tree
Showing 14 changed files with 6,695 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ jobs:
with:
rootDir: './example'
env:
EXAMPLE: 'World'
prpTitle: 'prp-preprocessor'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img src="https://raw.githubusercontent.com/CIFriends/brandkit/main/no-bg/cifriends.svg" alt="Logo" width="200px">
</a>

# prp-preprocessor
# {{_ prpTitle _}}

_A versatile GitHub Action that enables variable replacement in files using a simple_ `{_ variable _}` _syntax._

Expand Down
46 changes: 46 additions & 0 deletions README.prp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div align="center">
<a href="https://github.com/CIFriends">
<img src="https://raw.githubusercontent.com/CIFriends/brandkit/main/no-bg/cifriends.svg" alt="Logo" width="200px">
</a>

# {{_ prpTitle _}}

_A versatile GitHub Action that enables variable replacement in files using a simple_ `{_ variable _}` _syntax._

![Release](https://img.shields.io/github/v/release/CIFriends/prp-preprocessor?include_prereleases&sort=semver&logo=github)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/cifriends/prp-preprocessor/ci.yml?logo=github)
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/cifriends/prp-preprocessor?logo=github)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=CIFriends_prp-preprocessor&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=CIFriends_prp-preprocessor)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=CIFriends_prp-preprocessor&metric=coverage)](https://sonarcloud.io/summary/new_code?id=CIFriends_prp-preprocessor)
</div>

## Installation

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:

```yml
steps:
- name: PRP Preprocessor
uses: CIFriends/prp-preprocessor@v1
with:
rootDir: './example'
```
## Inputs
The PRP Preprocessor accepts the following inputs:
| 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 |

## License

This project is licensed under the Apache-2.0 License.
1 change: 1 addition & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const mockedProcessFiles = processFiles as jest.MockedFunction<typeof processFil
const inputParams: InputParams = {
rootDir: "/root",
extension: ".ts",
message: "Committing {_amount_} files with extension {_extension_} in directory {_rootDir_}",
envVars: new Map(),
ignoredDir: [],
ignoredVars: [],
Expand Down
60 changes: 31 additions & 29 deletions __tests__/utils/VariablesManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,60 @@ import { getEnvVariables, getInputParams, InputParams } from "../../src/utils/Va
import * as core from "@actions/core";
import { BufferEncoding } from "@vercel/ncc/dist/ncc/loaders/typescript/lib/typescript";

jest.mock('@actions/core');
jest.mock("@actions/core");

describe('VariableManager', () => {
describe("VariableManager", () => {
beforeEach(() => {
jest.resetAllMocks();
});

describe('getEnvVariables', () => {
it('returns all environment variables excluding ignored ones', () => {
process.env = { VAR1: 'value1', VAR2: 'value2', VAR3: 'value3' };
const ignored = ['VAR2'];
describe("getEnvVariables", () => {
it("returns all environment variables excluding ignored ones", () => {
process.env = { VAR1: "value1", VAR2: "value2", VAR3: "value3" };
const ignored = ["VAR2"];
const result = getEnvVariables(ignored);
expect(result).toEqual(new Map([['VAR1', 'value1'], ['VAR3', 'value3']]));
expect(result).toEqual(new Map([["VAR1", "value1"], ["VAR3", "value3"]]));
});

it('returns empty map if all environment variables are ignored', () => {
process.env = { VAR1: 'value1', VAR2: 'value2' };
const ignored = ['VAR1', 'VAR2'];
it("returns empty map if all environment variables are ignored", () => {
process.env = { VAR1: "value1", VAR2: "value2" };
const ignored = ["VAR1", "VAR2"];
const result = getEnvVariables(ignored);
expect(result).toEqual(new Map());
});
});

describe('getInputParams', () => {
it('returns all input parameters', () => {
describe("getInputParams", () => {
it("returns all input parameters", () => {
const mockedCore = core as jest.Mocked<typeof core>;
mockedCore.getInput.mockImplementation((name: string) => {
switch (name) {
case 'rootDir':
return '/root/dir';
case 'extension':
return '.ts';
case 'encodings':
return 'utf8' as BufferEncoding;
case "rootDir":
return "/root/dir";
case "commitMessage":
return "chore: process {_amount_} PRP files in {_rootDir_}";
case "extension":
return ".ts";
case "encodings":
return "utf8" as BufferEncoding;
default:
return '';
return "";
}
});
mockedCore.getBooleanInput.mockReturnValue(true);
mockedCore.getMultilineInput.mockReturnValue(['VAR1', 'VAR2']);

const result = getInputParams();
mockedCore.getMultilineInput.mockReturnValue(["VAR1", "VAR2"]);
process.env = { VAR1: "value1", VAR2: "value2" };
const expected: InputParams = {
rootDir: '/root/dir',
extension: '.ts',
ignoredVars: ['VAR1', 'VAR2'],
ignoredDir: ['VAR1', 'VAR2'],
envVars: new Map(),
rootDir: "/root/dir",
message: "chore: process {_amount_} PRP files in {_rootDir_}",
extension: ".ts",
ignoredVars: ["VAR1", "VAR2"],
ignoredDir: ["VAR1", "VAR2"],
envVars: new Map<string, string>(),
includeSubDir: true,
encodings: 'utf8'
encodings: "utf8"
};
expect(result).toEqual(expected);
expect(getInputParams()).toEqual(expected);
});
});
});
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: "Preprocess files with this pre-extension"
required: true
default: ".prp"
commitMessage:
description: "Commit message"
required: true
default: "chore: process {_amount_} PRP files"
encoding:
description: "Encoding of the files"
required: true
Expand Down
Loading

0 comments on commit c7344cd

Please sign in to comment.