-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add scripts for automated pkg publication
Signed-off-by: Andres Correa Casablanca <[email protected]>
- Loading branch information
Showing
18 changed files
with
272 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
name: Greetings | ||
# SPDX-FileCopyrightText: 2024 KindSpells Labs S.L. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
on: [pull_request, issues] | ||
name: "Greetings" | ||
|
||
on: | ||
- "pull_request" | ||
- "issues" | ||
|
||
jobs: | ||
greeting: | ||
runs-on: ubuntu-latest | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: 'Greeting' # v1.2.0 | ||
uses: 'actions/first-interaction@1dbfe1ba5525b8257e1f259b09745bee346d62d8' | ||
- name: "Greeting" # v1.2.0 | ||
uses: "actions/first-interaction@1dbfe1ba5525b8257e1f259b09745bee346d62d8" | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-message: '🥳 Thank you for opening your first issue for Coder-Spirit/nominal ! 😀' | ||
pr-message: '🥳 Thank you for your first PR on Coder-Spirit/nominal ! 😀' | ||
repo-token: "${{ secrets.GITHUB_TOKEN }}" | ||
issue-message: "🥳 Thank you for opening your first issue for Coder-Spirit/nominal ! 😀" | ||
pr-message: "🥳 Thank you for your first PR on Coder-Spirit/nominal ! 😀" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# SPDX-FileCopyrightText: 2024 KindSpells Labs S.L. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
name: "Publish Package to NPMJS" | ||
on: | ||
release: | ||
types: ["created"] | ||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
node-version: [ 22 ] | ||
os: [ "ubuntu-latest" ] | ||
pnpm: [ "9.7.0" ] | ||
|
||
runs-on: "${{ matrix.os }}" | ||
|
||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
|
||
steps: | ||
- name: "Checkout repository" # v4.1.1 | ||
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" | ||
- name: "Install PNPM" # v3.0.0 | ||
uses: "pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d" | ||
with: | ||
version: "${{ matrix.pnpm }}" | ||
- name: "Use Node.js ${{ matrix.node-version }}" # v4.0.2 | ||
uses: "actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8" | ||
with: | ||
node-version: "${{ matrix.node-version }}" | ||
cache: "pnpm" | ||
registry-url: "https://registry.npmjs.org" | ||
- name: "Install dependencies" | ||
run: "pnpm install --recursive --frozen-lockfile" | ||
- name: "Publish to NPM registry" | ||
run: "pnpm turbo publish:safe" | ||
working-directory: "." | ||
env: | ||
NPM_CONFIG_PROVENANCE: "true" | ||
NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,50 @@ | ||
name: Tests | ||
# SPDX-FileCopyrightText: 2024 KindSpells Labs S.L. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
name: "Tests" | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ main ] | ||
branches: [ "main" ] | ||
merge_group: | ||
branches: [ main] | ||
branches: [ "main" ] | ||
|
||
defaults: | ||
run: | ||
working-directory: . | ||
working-directory: "." | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
node-version: [ 18, 20, 22 ] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
pnpm: ['9.7.0'] | ||
os: ["ubuntu-latest", "windows-latest", "macos-latest"] | ||
pnpm: ["9.7.0"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
runs-on: "${{ matrix.os }}" | ||
|
||
env: | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ vars.TURBO_TEAM }} | ||
TURBO_TOKEN: "${{ secrets.TURBO_TOKEN }}" | ||
TURBO_TEAM: "${{ vars.TURBO_TEAM }}" | ||
|
||
steps: | ||
- name: Checkout repository # v4.1.1 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | ||
- name: Install PNPM # v3.0.0 | ||
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d | ||
- name: "Checkout repository" # v4.1.1 | ||
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" | ||
- name: "Install PNPM" # v3.0.0 | ||
uses: "pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d" | ||
with: | ||
version: ${{ matrix.pnpm }} | ||
- name: Use Node.js ${{ matrix.node-version }} # v4.0.2 | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 | ||
version: "${{ matrix.pnpm }}" | ||
- name: "Use Node.js ${{ matrix.node-version }}" # v4.0.2 | ||
uses: "actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8" | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'pnpm' | ||
node-version: "${{ matrix.node-version }}" | ||
cache: "pnpm" | ||
|
||
# All | ||
- name: (All) Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
- name: (All) Run All Tasks | ||
run: pnpm turbo all | ||
- name: "(All) Install dependencies" | ||
run: "pnpm install --frozen-lockfile" | ||
- name: "(All) Run All Tasks" | ||
run: "pnpm turbo all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
set -eu; | ||
|
||
unset CDPATH; # For safety | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"; | ||
SCRIPT_DIR="$(realpath "${SCRIPT_DIR}")"; | ||
|
||
DENO_FUTURE=1 "${SCRIPT_DIR}/biome-check-staged.ts" $@; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/usr/bin/env -S deno run --no-config --allow-env --allow-read --allow-sys --allow-run | ||
#!/usr/bin/env -S deno run --node-modules-dir --unstable-byonm --allow-env --allow-read --allow-sys --allow-run | ||
|
||
import process from 'node:process' | ||
import { $ } from 'npm:[email protected]' | ||
import { $ } from 'zx' | ||
|
||
const JSON_EXT = 'json|jsonc' | ||
const JS_EXT = 'js|mjs|cjs|jsx' | ||
|
@@ -16,7 +17,7 @@ const runGitDiffStaged = async (): Promise<string[]> => { | |
).lines() | ||
} | ||
|
||
export const main = async () => { | ||
const main = async () => { | ||
const stagedFiles = (await runGitDiffStaged()).filter(file => | ||
extsRegex.test(file), | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
set -eu; | ||
|
||
unset CDPATH; # For safety | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"; | ||
SCRIPT_DIR="$(realpath "${SCRIPT_DIR}")"; | ||
|
||
DENO_FUTURE=1 "${SCRIPT_DIR}/safe-publish.ts" $@; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env -S deno run --node-modules-dir --unstable-byonm --allow-env --allow-read --allow-sys --allow-run | ||
|
||
import { readFile } from 'node:fs/promises' | ||
import process from 'node:process' | ||
|
||
import { $ } from 'zx' | ||
|
||
type PackageJson = { | ||
name: string | ||
version: string | ||
} | ||
|
||
const isPackageJson = (value: unknown): value is PackageJson => { | ||
if (typeof value !== 'object' || value === null) { | ||
throw new Error('Invalid package.json: not an object') | ||
} | ||
|
||
if (!('name' in value)) { | ||
throw new Error('Invalid package.json: missing "name" field') | ||
} | ||
if (typeof value['name'] !== 'string') { | ||
throw new Error('Invalid package.json: "name" field is not a string') | ||
} | ||
|
||
if (!('version' in value)) { | ||
throw new Error('Invalid package.json: missing "version" field') | ||
} | ||
if (typeof value['version'] !== 'string') { | ||
throw new Error('Invalid package.json: "version" field is not a string') | ||
} | ||
|
||
return true | ||
} | ||
|
||
const getPackageJson = async (): Promise<PackageJson> => { | ||
const packageJsonStr = await readFile('package.json', 'utf-8') | ||
const packageJson = JSON.parse(packageJsonStr) as unknown | ||
|
||
if (!isPackageJson(packageJson)) { | ||
throw new Error('Invalid package.json') // Never thrown | ||
} | ||
|
||
return packageJson | ||
} | ||
|
||
const getCurrentPublishedVersion = async (pkgName: string): Promise<string> => { | ||
return (await $`npm view --workspaces false --json ${pkgName} version`) | ||
.text() | ||
.trim() | ||
.replaceAll('"', '') | ||
} | ||
|
||
const main = async (): Promise<void> => { | ||
const packageJson = await getPackageJson() | ||
const publishedVersion = await getCurrentPublishedVersion(packageJson.name) | ||
|
||
// TODO: improve checks, to ensure that versions grow monotonically | ||
if (packageJson.version === publishedVersion) { | ||
return // Nothing to publish | ||
} | ||
|
||
await $`pnpm publish --provenance --no-git-checks --access public`.stdio( | ||
'inherit', | ||
'inherit', | ||
'inherit', | ||
) | ||
} | ||
|
||
try { | ||
await main() | ||
} catch (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "@coderspirit/dev-configs/tsconfig", | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"lib": ["es2022"], | ||
"module": "es2022", | ||
|
||
"rootDir": ".", | ||
"baseUrl": "./src/" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["dist/**/*", "node_modules/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.