Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
81629ab
Migrate from idp monorepo
javierbrea Nov 14, 2024
f3b1136
chore: Remove unused target
javierbrea Nov 14, 2024
7d6421e
chore: Fix dictionaries
javierbrea Nov 14, 2024
c782dcd
chore: Add workflow test
javierbrea Nov 14, 2024
4012896
chore: Add shell option
javierbrea Nov 14, 2024
5341238
chore: Add dependency between jobs
javierbrea Nov 14, 2024
7d2f2a0
chore: Add dependency between targets
javierbrea Nov 14, 2024
173180a
chore: Add dependency between targets
javierbrea Nov 14, 2024
01f2908
chore: Build before linting
javierbrea Nov 14, 2024
e99e664
chore: Build dev dependencies before linting
javierbrea Nov 14, 2024
086ec09
chore: Run check:spell
javierbrea Nov 14, 2024
892f1c5
feat: Update cache
javierbrea Nov 14, 2024
4b5af5f
chore: Fix unable to update cache
javierbrea Nov 14, 2024
d64013d
chore: Add check:types step
javierbrea Nov 14, 2024
468767f
chore: Add dependency between jobs
javierbrea Nov 14, 2024
ae6f6a5
chore: Try storing cache in the same workflow
javierbrea Nov 14, 2024
ef23f07
chore: Try fixing the cache
javierbrea Nov 14, 2024
d4b4d0c
chore: Try using different cache keys
javierbrea Nov 14, 2024
7ce301d
chore: Add all targets
javierbrea Nov 14, 2024
8acac55
chore: Avoid nx rejecting cache
javierbrea Nov 14, 2024
e2e44d6
chore: reduce coverage threshold
javierbrea Nov 14, 2024
96804f3
chore: Rename jobs
javierbrea Nov 14, 2024
8d337dd
feat: Try saving cache
javierbrea Nov 14, 2024
ce9e966
chore: Try renaming cache
javierbrea Nov 14, 2024
0bc88f3
chore: Fix nx cache not working
javierbrea Nov 14, 2024
f8c0c84
chore: Fix nx cache not working
javierbrea Nov 14, 2024
0b54609
chore: Run only affected in PR
javierbrea Nov 14, 2024
7390a61
chore: Try using another cache with files hash
javierbrea Nov 14, 2024
63f42e6
chore: Remove commit cache
javierbrea Nov 14, 2024
afa9b42
test: Fix mermaid diagrams tests temporarily
javierbrea Nov 14, 2024
a0d4cb7
chore: Upgrade mermaid-cli library
javierbrea Nov 14, 2024
42bc82d
chore: Skip test and add TODO
javierbrea Nov 14, 2024
606e609
chore: Add dependency between jobs
javierbrea Nov 14, 2024
2dda2a7
chore: Add lint affected
javierbrea Nov 14, 2024
3794fea
chore: Try saving cache always
javierbrea Nov 14, 2024
77aa175
chore: Try not using ref name in cache
javierbrea Nov 14, 2024
a33f6e9
chore: Use simple cache action
javierbrea Nov 14, 2024
da672ce
chore: Use single job to run all targets
javierbrea Nov 14, 2024
29eb99c
chore: Run workflow
javierbrea Nov 14, 2024
367aaf6
chore: Run workflow
javierbrea Nov 14, 2024
59f8b18
test: Test save cache with single job
javierbrea Nov 14, 2024
3c4a80c
chore: Use simple cache
javierbrea Nov 14, 2024
6e9c368
chore: Delete cache to overwrite it
javierbrea Nov 14, 2024
3be5699
chore: Delete cache to overwrite it
javierbrea Nov 14, 2024
a9b2d87
chore: Use reusable action
javierbrea Nov 14, 2024
0390055
chore: Use reusable action
javierbrea Nov 14, 2024
b8a65b0
chore: Use reusable action
javierbrea Nov 14, 2024
e291294
chore: Try using github.token
javierbrea Nov 14, 2024
3e9ae6e
chore: Add shell
javierbrea Nov 14, 2024
59f7899
chore: Use reusable workflow
javierbrea Nov 14, 2024
cad0181
chore: Run in series
javierbrea Nov 14, 2024
21d8905
chore: Add change for testing caches
javierbrea Nov 14, 2024
82b2065
chore: Test markdown-conf-sync code change
javierbrea Nov 14, 2024
b89833c
chore: Restore files to its original state
javierbrea Nov 14, 2024
88a0a44
chore: Test another change in markdown-conf-sync test file
javierbrea Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Install and cache
description: Setup the runner environment, by installing dependencies and restoring caches

runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
- name: Cache dependencies
id: cache-pnpm
uses: actions/cache@v4
with:
path: node_modules
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install Node.js dependencies
shell: bash
run: pnpm install
49 changes: 49 additions & 0 deletions .github/actions/run-nx-target/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Run Nx target
description: Setup the Nx cache, and run a target

inputs:
target:
description: The Nx target to run
required: true
github_token:
description: GitHub token
default: '${{ github.token }}'

runs:
using: composite
steps:
- uses: ./.github/actions/install
id: install
- name: Restore Nx cache
uses: actions/cache/restore@v4
id: cache-restore
with:
path: .nx
key: nx-cache
- name: Derive appropriate SHAs for base and head for `nx affected` commands
if: github.event_name == 'pull_request'
uses: nrwl/nx-set-shas@v2
with:
main-branch-name: ${{ github.event.pull_request.base.ref }}
- name: Run - Affected
if: github.event_name == 'pull_request'
shell: bash
run: NX_REJECT_UNKNOWN_LOCAL_CACHE=0 pnpm nx affected -t ${{ inputs.target }} --base=origin/${{ github.event.pull_request.base.ref }} --head=HEAD
- name: Lint
if: github.event_name != 'pull_request'
shell: bash
run: NX_REJECT_UNKNOWN_LOCAL_CACHE=0 pnpm nx run-many --target=${{ inputs.target }} --all
- name: Delete Previous Nx Cache
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
shell: bash
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "nx-cache" --confirm
env:
GH_TOKEN: ${{ inputs.github_token }}
- name: Save Nx cache
uses: actions/cache/save@v4
with:
path: .nx
key: nx-cache
88 changes: 88 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: "Check and build"
on:
push:
branches:
- release
- main
- chore/CRC-28/single-job

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
actions: write

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: lint
check-spell:
needs: lint
name: Check spell
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: check:spell
check-types:
needs: check-spell
name: Check types
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: check:types
test-unit:
needs: check-types
name: Test unit
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: test:unit
build:
needs: test-unit
name: Build
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: build
test-component:
needs: build
name: Test component
runs-on: ubuntu-latest
env:
cache-key: nx-cache
steps:
- name: Check out
uses: actions/checkout@v4
- uses: ./.github/actions/run-nx-target
with:
target: test:component
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# MacOS
.DS_store

# NX
.nx
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if ! [ -x "$(command -v pnpm)" ]; then
echo 'Pnpm is not installed, skipping lint hook' >&2
exit 0
else
pnpm lint:staged
fi
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"nrwl.angular-console"
]
}
3 changes: 3 additions & 0 deletions components/child-process-manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated
/coverage
/dist
14 changes: 14 additions & 0 deletions components/child-process-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

#### Added
#### Changed
#### Fixed
#### Deprecated
#### Removed

## [Unreleased]
97 changes: 97 additions & 0 deletions components/child-process-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# child-process-manager

This library allows to create a child process using `cross-spawn`, which provides compatibility across different operating systems, and manage its lifecycle. It mainly provides:

* Allows to handle child processes as promises. The promise is resolved when the process finish successfully, and rejected when it fails.
* Allows to kill the child process when the parent process is killed.
* Allows to get logs from the child process.

## Table of Contents

- [Usage](#usage)
- [Installation](#installation)
- [Example](#example)
- [Development](#development)
- [Installation](#installation-1)
- [Monorepo tool](#monorepo-tool)
- [Unit tests](#unit-tests)
- [Build](#build)
- [NPM scripts reference](#npm-scripts-reference)

## Usage

### Installation

This package is not published in NPM, so, for the moment it can be used only in this repository through PNPM workspaces. To use it, you have to add it to your dependencies in the `package.json` file:

```json title="package.json"
{
"dependencies": {
"@telefonica-cross/child-process-manager": "workspace:*"
}
}
```

### Example

Import the library, create a child process and wait for it to finish. It will return the exit code and the logs in the resolved object.

```js title="Example"
import { ChildProcessManager } from '@telefonica-cross/child-process-manager';

const childProcess = new ChildProcessManager(["echo", 'Hello world!']);

const { logs, exitCode } = await childProcess.run();

console.log(logs); // ["Hello world!"]
console.log(exitCode); // 0
```

## Development

### Installation

TypeScript components of the IDP project use Pnpm as dependencies manager. So, to start working on them, you have to install the dependencies by running `pnpm install` in the root folder of the repository.

Please refer to the monorepo README file for further information about [common requirements](../../README.md#requirements) and [installation process](../../README.md#installation) of all TypeScript components.

### Monorepo tool

Note that this component is part of a monorepo, so you can execute any command of the components from the root folder, and Nx will take care of executing the dependent commands in the right order. Any command described here should be executed from the root folder of the repository, using Nx.

For example, a command like this:

```sh title="Execute unit tests of the component inside its folder"
pnpm run test:unit
```

Should be executed like this:

```sh title="Execute unit tests of the component, and all needed dependencies, from root folder"
pnpm nx test:unit child-process-manager
```

### Unit tests

Unit tests are executed using [Jest](https://jestjs.io/). To run them, execute the following command:

```sh
pnpm run test:unit
```

### Build

This command generates the library into the `dist` directory, which is the one defined as the entry point in the `package.json` file. __Note that other components in the repository won't be able to use the library until this command is executed.__

```sh
pnpm run build
```

### NPM scripts reference

- `test:unit` - Run unit tests.
- `build` - Build the library.
- `check:types` - Checks the TypeScript types.
- `lint` - Lint the code.
- `lint:fix` - Fix lint errors.

23 changes: 23 additions & 0 deletions components/child-process-manager/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = (api) => {
const isTest = api.env("test");
if (isTest) {
return {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
plugins: [
[
"module-resolver",
{
root: ["."],
alias: {
"@src": "./src",
"@support": "./test/unit/support",
},
},
],
],
};
}
};
3 changes: 3 additions & 0 deletions components/child-process-manager/cspell.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createConfig } = require("../cspell-config/index.js");

module.exports = createConfig();
29 changes: 29 additions & 0 deletions components/child-process-manager/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from "path";

import {
defaultConfigWithoutTypescript,
typescriptConfig,
jestConfig,
} from "../eslint-config/index.js";

function componentPath() {
return path.resolve.apply(null, [import.meta.dirname, ...arguments]);
}

export default [
...defaultConfigWithoutTypescript,
{
...typescriptConfig,
settings: {
...typescriptConfig.settings,
"import/resolver": {
...typescriptConfig.settings["import/resolver"],
alias: {
map: [["@src", componentPath("src")]],
extensions: [".ts", ".js", ".jsx", ".json"],
},
},
},
},
jestConfig,
];
Loading