Skip to content

Commit

Permalink
feat: display uncaught error by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adbayb committed Oct 31, 2024
1 parent fad5a55 commit 853f959
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 135 deletions.
7 changes: 7 additions & 0 deletions .changeset/flat-pots-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"termost": minor
---

Display uncaught error by default and allow `helpers.message` to accept Error-like objects.

Please note that the `helpers.message` do not accept anymore an array of strings.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Continous delivery

on:
push:
Expand All @@ -8,8 +8,11 @@ on:
concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
integrate:
uses: ./.github/workflows/workflow.yml
release:
timeout-minutes: 5
needs: integrate
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -34,7 +37,11 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create release pull request or Publish to npm
- name: Publish pre-release version(s)
run: |
pnpm --filter=\!@examples/\* --recursive exec pnpm version "$(pnpm show ./ version)-next-${GITHUB_SHA::7}"
pnpm --filter=\!@examples/\* --recursive exec pnpm publish --tag next --no-git-checks
- name: Prepare or Publish stable version(s)
uses: changesets/action@v1
with:
commit: "chore: release package(s)"
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Continuous integration

on:
push:
branches-ignore: main

jobs:
main:
uses: ./.github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Check pull request
name: Conventional commit

on:
pull_request:
types: [opened, edited]

jobs:
pr_title:
main:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/dependency_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Dependency changelog

on:
pull_request_target:
paths:
- "**/pnpm-lock.yaml"

jobs:
main:
timeout-minutes: 5
runs-on: ubuntu-latest
if: github.actor == 'renovate[bot]'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.head_ref }}
- name: Configure Git
run: |
git config --global user.email [email protected]
git config --global user.name 'Ayoub Adib'
- name: Create changelog entry
uses: actions/github-script@v7
# Credits to https://github.com/backstage/backstage/blob/bcc11651add5a2589898dfb9d665ebb9d412201b/.github/workflows/sync_renovate-changesets.yml
with:
script: |
const { promises: fs } = require("fs");
async function getPackagesNames(files) {
const names = [];
for (const file of files) {
const data = JSON.parse(await fs.readFile(file, "utf8"));
if (!data.private) {
names.push(data.name);
}
}
return names;
}
async function createChangeset(fileName, packageBumps, packages) {
let message = "";
for (const [pkg, bump] of packageBumps) {
message = message + `Updated dependency \`${pkg}\` to \`${bump}\`.\n`;
}
const pkgs = packages.map((pkg) => `"${pkg}": minor`).join("\n");
const body = `---\n${pkgs}\n---\n\n${message.trim()}\n`;
await fs.writeFile(fileName, body);
}
async function getBumps(files) {
const bumps = new Map();
for (const file of files) {
const { stdout: changes } = await exec.getExecOutput("git", [
"show",
file,
]);
for (const change of changes.split("\n")) {
if (!change.match(/^\+\s/)) {
continue;
}
const match = change.match(/"(.*?)"/g);
bumps.set(match[0].replace(/"/g, ""), match[1].replace(/"/g, ""));
}
}
return bumps;
}
const branch = await exec.getExecOutput("git branch --show-current");
if (!branch.stdout.startsWith("renovate/")) {
console.log("Not a renovate branch, skipping");
return;
}
const diffOutput = await exec.getExecOutput("git diff --name-only HEAD~1");
const diffFiles = diffOutput.stdout.split("\n");
if (diffFiles.find((f) => f.startsWith(".changeset"))) {
console.log("Changeset already exists, skipping");
return;
}
const files = diffFiles
.filter((file) => file !== "package.json") // skip root package.json
.filter((file) => file.includes("package.json"));
const packageNames = await getPackagesNames(files);
if (!packageNames.length) {
console.log("No package.json changes to published packages, skipping");
return;
}
const { stdout: shortHash } = await exec.getExecOutput(
"git rev-parse --short HEAD"
);
const fileName = `.changeset/renovate-${shortHash.trim()}.md`;
const packageBumps = await getBumps(files);
await createChangeset(fileName, packageBumps, packageNames);
await exec.exec("git", ["add", fileName]);
await exec.exec("git commit -C HEAD --amend --no-edit");
await exec.exec("git push --force");
35 changes: 2 additions & 33 deletions .github/workflows/integrate.yml → .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Continuous Integration
name: Main shareable workflow

on:
push:
workflow_call:

jobs:
install:
Expand Down Expand Up @@ -94,34 +94,3 @@ jobs:
run: pnpm install --frozen-lockfile
- name: Check (static analysis including linters, types, and commit message)
run: pnpm check
test:
timeout-minutes: 5
needs: build
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Get node version
run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT
id: node
- name: Setup node ${{ steps.node.outputs.version }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.node.outputs.version }}
cache: pnpm
- name: Setup cache
id: cache
uses: actions/cache@v4
with:
path: |
./node_modules
./turbo
key: ${{ runner.os }}-cache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check (code execution)
run: pnpm test
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*turbo*
public-hoist-pattern[]=*typescript*
public-hoist-pattern[]=*types*
4 changes: 2 additions & 2 deletions examples/default/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const program = termost<ProgramContext>(
{
onException(error) {
console.log(
"Catches `uncaughtException` and `unhandledRejection` events",
"`onException` catches `uncaughtException` and `unhandledRejection`",
error,
);
},
onShutdown() {
console.log(
"Catches `SIGINT` and `SIGTERM` OS signals (useful, for example, to release resources before interrupting the process)",
"`onShutdown` catches `SIGINT` and `SIGTERM` OS signals (useful, for example, to release resources before interrupting the process)",
);
},
},
Expand Down
7 changes: 0 additions & 7 deletions examples/task/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ program
label: "👋 You can also customize the label",
type: "information",
});
helpers.message(
["I support also", "multilines", "with array input"],
{
label: "👋 You can also customize the label",
type: "information",
},
);
console.log(
helpers.format(
"\nYou can also have a total control on the formatting through the `format` helper.",
Expand Down
7 changes: 0 additions & 7 deletions termost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,6 @@ program
type: "information",
label: "👋 You can also customize the label",
});
helpers.message(
["I support also", "multilines", "with array input"],
{
type: "information",
label: "👋 You can also customize the label",
},
);
console.log(
helpers.format(
"\nYou can also have a total control on the formatting through the `format` helper.",
Expand Down
Loading

0 comments on commit 853f959

Please sign in to comment.