Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separates CI version script from local one #78

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-boxes-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"any-ts": patch
---

ci
5 changes: 5 additions & 0 deletions .changeset/nine-boats-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"any-ts": patch
---

fix: straightens out release pipeline
64 changes: 0 additions & 64 deletions .github/workflows/publish.yml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}

2 changes: 1 addition & 1 deletion bin/cli.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
27 changes: 0 additions & 27 deletions bin/version.sh

This file was deleted.

56 changes: 12 additions & 44 deletions bin/release.ts → bin/version.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -23,31 +22,12 @@ namespace log {
}
}


function run<fn extends () => unknown>(fn: fn): ReturnType<fn>
function run<fns extends readonly (() => unknown)[]>(...fns: fns): { [ix in keyof fns]: globalThis.ReturnType<fns[ix]> }
function run(...fns: (() => unknown)[]) { return fns.map(fn => fn()) }

type intercalate<acc extends string, xs extends readonly unknown[], btwn extends string>
= xs extends readonly [infer head extends string, ...infer tail]
? intercalate<acc extends "" ? `${head}` : `${acc}${btwn}${head}`, tail, btwn>
: acc
;

type join<
xs extends readonly literal[],
btwn extends string = ""
> = intercalate<"", xs, `${btwn}`>

type literal = string | number | boolean | bigint

const join
: <btwn extends string>(btwn: btwn) => <const xs extends readonly string[]>(...xs: xs) => join<xs, btwn>
= (btwn) => (...xs) => xs.join(btwn) as never

const path
: <xs extends readonly literal[]>(...xs: xs) => join<xs, "/">
= (...[head, ...tail]: readonly literal[]) => {
: (...[head, ...tail]: string[]) => string
= (...[head, ...tail]) => {
const hd = head ? `${head}` : "/";
const path = tail.map(String).reduce(
(path, s) => {
Expand All @@ -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<const xs extends readonly string[]>(...xs: xs): join<[typeof root, ...xs], "/">
function fromRoot<const xs extends readonly string[]>(...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<path extends string = string> {
Expand All @@ -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) }
Expand All @@ -105,23 +77,19 @@ 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
else throw ["Expected manifest to have a version", json]
}

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
Expand Down Expand Up @@ -164,7 +132,7 @@ const main = () => {

run(
checkCleanWorktree,
$.exec(`pnpm run changeset`),
// $.exec(`pnpm run changes`),
$.exec(`pnpm run version`),
)

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down