diff --git a/.changeset/forty-boxes-thank.md b/.changeset/forty-boxes-thank.md new file mode 100644 index 0000000..76935e1 --- /dev/null +++ b/.changeset/forty-boxes-thank.md @@ -0,0 +1,5 @@ +--- +"any-ts": patch +--- + +ci diff --git a/.changeset/nine-boats-repeat.md b/.changeset/nine-boats-repeat.md new file mode 100644 index 0000000..b31595c --- /dev/null +++ b/.changeset/nine-boats-repeat.md @@ -0,0 +1,5 @@ +--- +"any-ts": patch +--- + +fix: straightens out release pipeline diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 85ae393..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Publish -on: - push: - branches: [main] - pull_request: -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Check project - uses: actions/checkout@v4 - - name: Install pnpm - run: corepack enable - - name: Install node - uses: actions/setup-node@v4 - with: - node-version-file: .node-version - cache: pnpm - - name: Install dependencies - run: pnpm install --frozen-lockfile - - name: Build - run: production=true pnpm build - release: - name: Release Packages - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - pull-requests: write - - needs: [build] - if: github.ref == 'refs/heads/main' - steps: - - name: Checkout project - uses: actions/checkout@v4 - - name: Install pnpm - run: corepack enable - - name: Install node - uses: actions/setup-node@v4 - with: - node-version-file: .node-version - cache: pnpm - # - name: Configure npm - # run: | - # echo '//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}' >> .npmrc - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install dependencies - run: pnpm install - - name: Build - run: production=true pnpm build - - name: Create PR or publish - id: changesets - uses: changesets/action@v1 - with: - version: pnpm run version - publish: pnpm run publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..87c4e25 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,75 @@ +name: Release package +on: + push: + branches: [main] + pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + release: + name: Release + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout project + uses: actions/checkout@v4 + - name: Install pnpm + run: corepack enable + - name: Install node + uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: pnpm + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Build + run: production=true pnpm build + - name: Create PR or publish + id: changesets + uses: changesets/action@v1 + with: + version: pnpm run ci:version + publish: pnpm run ci:publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + # release: + # name: Release Packages + # runs-on: ubuntu-latest + # permissions: + # contents: write + # packages: write + # pull-requests: write + # needs: [build] + # if: github.ref == 'refs/heads/main' + # steps: + # - name: Checkout project + # uses: actions/checkout@v4 + # - name: Install pnpm + # run: corepack enable + # - name: Install node + # uses: actions/setup-node@v4 + # with: + # node-version-file: .node-version + # cache: pnpm + # # - name: Configure npm + # # run: | + # # echo '//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}' >> .npmrc + # # env: + # # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Install dependencies + # run: pnpm install + # - name: Build + # run: production=true pnpm build + # - name: Create PR or publish + # id: changesets + # uses: changesets/action@v1 + # with: + # version: pnpm run version + # publish: pnpm run ci:publish + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + \ No newline at end of file diff --git a/bin/cli.ts b/bin/cli.ts index 0b87d0f..c461ffa 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -1,4 +1,4 @@ -#!/usr/bin/env pnpx tsx +#!/usr/bin/env pnpm dlx tsx import * as Shell from 'node:child_process' export interface CLI { diff --git a/bin/version.sh b/bin/version.sh deleted file mode 100755 index 7bff999..0000000 --- a/bin/version.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env sh - -userGrantsPermission() { - echo "Proceed? (Y/n)" - read -s -n 1 input - if [[("$input" = "y") || ("$input" = "Y") || ("$input" = "")]]; then - return 0 - else - return 1 - fi -} - -execVersion() { - echo "This script will version your package(s) according to the changeset you provided" - if userGrantsPermission; then - echo "Bumping local version(s)" - pnpm exec changeset version - else - echo "Versioning skipped; your changeset has not been executed." - fi -} - -main() { - execVersion; -} - -main; diff --git a/bin/release.ts b/bin/version.ts similarity index 79% rename from bin/release.ts rename to bin/version.ts index e180471..ba03c7c 100755 --- a/bin/release.ts +++ b/bin/version.ts @@ -1,4 +1,3 @@ -#!/usr/bin/env pnpx tsx import * as FileSystem from "node:fs" import * as Path from "node:path" import * as OS from "node:os" @@ -23,31 +22,12 @@ namespace log { } } - -function run unknown>(fn: fn): ReturnType function run unknown)[]>(...fns: fns): { [ix in keyof fns]: globalThis.ReturnType } function run(...fns: (() => unknown)[]) { return fns.map(fn => fn()) } -type intercalate - = xs extends readonly [infer head extends string, ...infer tail] - ? intercalate - : acc - ; - -type join< - xs extends readonly literal[], - btwn extends string = "" -> = intercalate<"", xs, `${btwn}`> - -type literal = string | number | boolean | bigint - -const join - : (btwn: btwn) => (...xs: xs) => join - = (btwn) => (...xs) => xs.join(btwn) as never - const path - : (...xs: xs) => join - = (...[head, ...tail]: readonly literal[]) => { + : (...[head, ...tail]: string[]) => string + = (...[head, ...tail]) => { const hd = head ? `${head}` : "/"; const path = tail.map(String).reduce( (path, s) => { @@ -61,15 +41,7 @@ const path return (path.endsWith("/") ? path.slice(0, -1) : path) as never } -const root: `~` = Path.resolve(__dirname, "..") as never - -function fromRoot(...xs: []): typeof root -function fromRoot(...xs: xs): join<[typeof root, ...xs], "/"> -function fromRoot(...xs: xs): string { - return path(root, ...xs) -} - -const versionFile = fromRoot("src", "version.ts") +const versionFile = path(Path.resolve(__dirname, ".."), "src", "version.ts") declare namespace Cause { interface PathNotFound { @@ -84,12 +56,12 @@ namespace Cause { }) } -function readFile(filepath: `${typeof root}${string}`): string | Cause.PathNotFound { +function readFile(filepath: string): string | Cause.PathNotFound { try { return FileSystem.readFileSync(filepath).toString("utf-8") } catch (err) { return Cause.PathNotFound(err) } } -function writeFile(filepath: `${typeof root}${string}`): (contents: string) => void | Cause.PathNotFound { +function writeFile(filepath: string): (contents: string) => void | Cause.PathNotFound { return (contents) => { try { return FileSystem.writeFileSync(filepath, contents) } catch (err) { return Cause.PathNotFound(err) } @@ -105,7 +77,8 @@ const hasVersion ; const readPackageVersion = (): string => { - const manifest = readFile(fromRoot("package.json")) + const manifest = readFile(path(Path.resolve(__dirname, ".."), "package.json")) + // const versionFile = path(Path.resolve(__dirname, ".."), "src", "version.ts") if (typeof manifest === "object") throw ["Expected manifest to be a string", manifest] const json: {} | null | undefined = JSON.parse(manifest) if (hasVersion(json)) return json.version @@ -113,15 +86,10 @@ const readPackageVersion = (): string => { } const versionTemplate: (version: string) => string - = (version) => - [ - `export const ANY_TS_VERSION = "${version}" as const`, - `export type ANY_TS_VERSION = typeof ANY_TS_VERSION`, - ].join(OS.EOL) -// `export const ANY_TS_VERSION = "${version}" as const${OS.EOL}` -// .concat(`export type ANY_TS_VERSION = typeof ANY_TS_VERSION`) - - + = (version) => [ + `export const ANY_TS_VERSION = "${version}" as const`, + `export type ANY_TS_VERSION = typeof ANY_TS_VERSION`, + ].join(OS.EOL) /** * Reads the package version from `package.json` and writes it as @@ -164,7 +132,7 @@ const main = () => { run( checkCleanWorktree, - $.exec(`pnpm run changeset`), + // $.exec(`pnpm run changes`), $.exec(`pnpm run version`), ) diff --git a/package.json b/package.json index 0e275d7..9dd332e 100644 --- a/package.json +++ b/package.json @@ -23,15 +23,14 @@ "sideEffects": false, "scripts": { "build": "pnpm clean:build && tsup src/index.ts \"!src/**/*.spec.ts\" --format cjs,esm --dts", - "changeset": "./bin/changeset.sh", "check": "tsc --noEmit", "clean": "pnpm run \"/^check:.*/\"", "clean:build": "rm -rf dist", "clean:deps": "rm -rf dist", "lint": "tsc --noEmit", - "release": "./bin/release.ts", - "version": "./bin/version.sh", - "publish": "changeset publish" + "changes": "./bin/changeset.sh", + "ci:version": "pnpm dlx tsx ./bin/version.ts", + "ci:publish": "changeset publish" }, "devDependencies": { "@changesets/cli": "^2.27.1",