Skip to content
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LF in the working tree on every platform. Git for Windows defaults to
# core.autocrlf=true, which rewrites a checkout to CRLF — that breaks two things
# at once: the completion scripts and man page ship in the npm package and are
# read by shells and man(1), and `npm run verify:generated` compares the
# read by shells and man(1), and `pnpm run verify:generated` compares the
# generator's LF output byte-for-byte against what is on disk.
* text=auto eol=lf
48 changes: 48 additions & 0 deletions .github/scripts/install-global.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Install the packed tarball globally, the way a user of that package manager
# would, and export ENTRY: the path that package manager's launcher hands node.
# The INSTALL-01 steps reach the copy by that path rather than through `git fi`,
# which is the only way a shadowed copy gets to say anything at all.
#
# The two lay a global install out differently. npm puts the package under its
# prefix. pnpm puts it in a node_modules of its own global directory: directly
# under `pnpm root -g` up to pnpm 10, and in a per-package subdirectory of it
# from pnpm 11.
param(
[Parameter(Mandatory)]
[ValidateSet('npm', 'pnpm')]
[string]$Installer
)

$ErrorActionPreference = 'Continue'
$tgz = (Get-ChildItem gettyimages-git-fi-*.tgz).FullName
$package = 'node_modules\@gettyimages\git-fi\dist\index.js'

if ($Installer -eq 'pnpm') {
# pnpm refuses a global install until it has a global bin directory on PATH,
# which `pnpm setup` arranges on a user's machine. Do the same here, for this
# step and the ones after it.
if (-not $env:PNPM_HOME) {
$env:PNPM_HOME = Join-Path $env:RUNNER_TEMP 'pnpm-home'
"PNPM_HOME=$env:PNPM_HOME" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
}
$bin = (pnpm bin -g).Trim()
New-Item -ItemType Directory -Force $bin | Out-Null
$env:PATH = "$bin;$env:PATH"
$bin | Out-File -Append -Encoding utf8 $env:GITHUB_PATH

pnpm add -g $tgz
if ($LASTEXITCODE) { throw "pnpm add -g failed ($LASTEXITCODE)" }
$root = (pnpm root -g).Trim()
$candidates = @(Join-Path $root '@gettyimages\git-fi\dist\index.js')
$candidates += Get-ChildItem $root -Directory | ForEach-Object { Join-Path $_.FullName $package }
} else {
npm install -g $tgz
if ($LASTEXITCODE) { throw "npm install -g failed ($LASTEXITCODE)" }
$prefix = (npm config get prefix).Trim()
$candidates = @(Join-Path $prefix $package)
}

$entry = $candidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $entry) { throw "no installed git-fi entry point found for $Installer among: $($candidates -join ', ')" }
"installed with $Installer at $entry"
"ENTRY=$entry" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
77 changes: 49 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,34 @@ jobs:
steps:
- uses: actions/checkout@v4

# pnpm's version comes from `packageManager` in package.json.
- uses: pnpm/action-setup@v6
with:
cache: true

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm

- run: npm ci
- run: npm test
- run: pnpm install --frozen-lockfile
- run: pnpm test

# The matrix above drives the compiled binary straight out of the checkout, so
# nothing there installs globally or reaches git-fi by the name a shell
# resolves. That left the whole of INSTALL-01 untested: a user migrating off
# the Ruby gem had a launcher left in Ruby's bin directory, ahead of npm's
# prefix on PATH, and `git fi` ran that one instead. Windows PowerShell rather
# than pwsh because that is the shell the report came from.
#
# Once per package manager a user installs git-fi with: npm and pnpm lay a
# global install out differently, and write different launchers, so the
# same-install check has a different shape to get right for each.
windows-install:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
installer: [npm, pnpm]
defaults:
run:
# INSTALL-01 writes its report to stderr, and this shell defaults
Expand All @@ -49,19 +61,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v6
with:
cache: true

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- run: npm ci
- run: npm pack
- run: pnpm install --frozen-lockfile
- run: pnpm pack

- name: install the tarball globally with ${{ matrix.installer }}
run: ./.github/scripts/install-global.ps1 -Installer ${{ matrix.installer }}

- name: git fi reaches the global install, and says nothing extra
run: |
$ErrorActionPreference = 'Continue'
$tgz = (Get-ChildItem gettyimages-git-fi-*.tgz).FullName
npm install -g $tgz
$v = (git fi --version) -join ''
if ($v -notmatch '^git-fi \d+\.\d+\.\d+$') { throw "git fi --version said: $v" }

Expand Down Expand Up @@ -95,8 +111,7 @@ jobs:
# Reached by path rather than by name, which is the only way the copy
# being shadowed gets to say anything at all (`npx` for the user who
# hit this).
$prefix = (npm config get prefix).Trim()
$entry = Join-Path $prefix 'node_modules\@gettyimages\git-fi\dist\index.js'
$entry = $env:ENTRY

$stdout = & node $entry --version 2>$null
if (($stdout -join '') -notmatch '^git-fi \d+\.\d+\.\d+$') {
Expand Down Expand Up @@ -142,23 +157,30 @@ jobs:
# after it is removed by hand.
windows-leftover-gem:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
installer: [npm, pnpm]
defaults:
run:
shell: powershell
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v6
with:
cache: true
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm pack
- run: pnpm install --frozen-lockfile
- run: pnpm pack

- name: install the tarball globally with ${{ matrix.installer }}
run: ./.github/scripts/install-global.ps1 -Installer ${{ matrix.installer }}

- name: install a git-munge-shaped gem the way its README said to
run: |
$ErrorActionPreference = 'Continue'
$tgz = (Get-ChildItem gettyimages-git-fi-*.tgz).FullName
npm install -g $tgz

"=== ruby on this runner ==="
& ruby --version 2>&1
Expand Down Expand Up @@ -221,9 +243,7 @@ jobs:
throw "the gem launcher should be what git fi reaches, got: $reached"
}

$prefix = (npm config get prefix).Trim()
$entry = Join-Path $prefix 'node_modules\@gettyimages\git-fi\dist\index.js'
$all = (& node $entry --version 2>&1 | Out-String)
$all = (& node $env:ENTRY --version 2>&1 | Out-String)
if ($all -notmatch 'ahead of this one') { throw "expected the shadow report, got: $all" }

- name: and still shadows it once the gem files are deleted by hand
Expand All @@ -245,34 +265,35 @@ jobs:
throw "the leftover links are not in git's way, so there is nothing to report: $broken"
}

$prefix = (npm config get prefix).Trim()
$entry = Join-Path $prefix 'node_modules\@gettyimages\git-fi\dist\index.js'
$all = (& node $entry --version 2>&1 | Out-String)
$all = (& node $env:ENTRY --version 2>&1 | Out-String)
if ($all -notmatch 'ahead of this one') { throw "expected the shadow report, got: $all" }

# Fail if the committed man page, completions, or docs tables are stale — i.e.
# someone changed src/help.ts without re-running the generator. Keeps the
# generated artifacts honest, since they ship in the npm package and the docs
# site without being regenerated at publish time.
#
# The check itself is the `verify:generated` npm script, so a contributor can
# reproduce this failure locally with the same command rather than reading it
# out of this file. (`npm test` regenerates as it runs, so it can't catch
# The check itself is the `verify:generated` package script, so a contributor
# can reproduce this failure locally with the same command rather than reading
# it out of this file. (`pnpm test` regenerates as it runs, so it can't catch
# drift — this job is what guards a commit that skipped the test loop.)
generated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v6
with:
cache: true

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- run: npm ci
- run: pnpm install --frozen-lockfile
- name: Verify generated files are up to date
run: |
npm run verify:generated || {
echo "::error::Generated files are stale. Run 'npm run gen:docs' and commit the result."
pnpm run verify:generated || {
echo "::error::Generated files are stale. Run 'pnpm run gen:docs' and commit the result."
exit 1
}
35 changes: 20 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write # push the Release commit back to main
id-token: write # npm provenance
id-token: write # trusted publishing and provenance
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

# pnpm's version comes from `packageManager` in package.json. It
# publishes through trusted publishing (OIDC) on its own, so setup-node
# gets no `registry-url`: the .npmrc that writes names an auth token from
# NODE_AUTH_TOKEN, which this workflow doesn't set.
- uses: pnpm/action-setup@v6
with:
cache: true

- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm

# Tokenless trusted publishing needs npm >= 11.5.1; the version bundled
# with Node ships older, so pull the latest npm explicitly.
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest

- name: Resolve version from the release tag
id: version
Expand All @@ -48,11 +49,13 @@ jobs:
fi
echo "value=$version" >> "$GITHUB_OUTPUT"

- run: npm ci
- run: pnpm install --frozen-lockfile

- name: Bump package.json to the release version
if: github.event_name == 'release'
run: npm version "${{ steps.version.outputs.value }}" --no-git-tag-version --allow-same-version
# pnpm checks for a clean tree even without a tag; a re-run of this job
# can find the bump from the last attempt still uncommitted.
run: pnpm version "${{ steps.version.outputs.value }}" --no-git-tag-version --allow-same-version --no-git-checks

# Prepend the release body to CHANGELOG.md, inserted after the marker line.
# NOTES comes in through the environment so arbitrary markdown needs no
Expand Down Expand Up @@ -80,22 +83,24 @@ jobs:

# Idempotent: skip if the version is already published, so a release can be
# re-run without failing on a version conflict. prepublishOnly runs tests.
# --no-git-checks because the version bump and changelog above are
# committed only after the publish succeeds, so the tree is dirty here.
- name: Publish to npm
if: github.event_name == 'release'
run: |
VERSION="${{ steps.version.outputs.value }}"
if npm view "@gettyimages/git-fi@${VERSION}" version >/dev/null 2>&1; then
echo "@gettyimages/git-fi@${VERSION} already published — skipping npm publish."
if [ -n "$(pnpm view "@gettyimages/git-fi@${VERSION}" version 2>/dev/null)" ]; then
echo "@gettyimages/git-fi@${VERSION} already published — skipping publish."
else
npm publish --provenance --access public
pnpm publish --provenance --access public --no-git-checks
fi

- name: Commit version and changelog to main
if: github.event_name == 'release'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json CHANGELOG.md
git add package.json CHANGELOG.md
if git diff --cached --quiet; then
echo "No version or changelog changes to commit."
else
Expand All @@ -106,4 +111,4 @@ jobs:
# workflow_dispatch: validate packaging without uploading.
- name: Publish (dry run)
if: github.event_name == 'workflow_dispatch'
run: npm publish --dry-run --access public
run: pnpm publish --dry-run --access public --no-git-checks
20 changes: 10 additions & 10 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ git-fi is a git subcommand (`git fi`), written in TypeScript for Node >= 22, tha
## Commands

```bash
npm install # dev dependencies (tsx, typescript)
npm start -- --help # run src/ directly via tsx
npm run build # tsc to dist/, then regenerate man/, completions/, docs tables
npm test # tsc, verify:generated, then the whole suite
npm run verify:generated # fail if a committed generated file is stale
npm run trial:on # link this checkout as `git fi` on PATH (trial:off reverts)
npm run docs # serve the Docsify site at http://127.0.0.1:3000/
pnpm install # dev dependencies (tsx, typescript)
pnpm start --help # run src/ directly via tsx
pnpm run build # tsc to dist/, then regenerate man/, completions/, docs tables
pnpm test # tsc, verify:generated, then the whole suite
pnpm run verify:generated # fail if a committed generated file is stale
pnpm run trial:on # link this checkout as `git fi` on PATH (trial:off reverts)
pnpm run docs # serve the Docsify site at http://127.0.0.1:3000/
```

`just` lists the same tasks under shorter names; most recipes delegate to an npm script, so `package.json` is where a command is defined.
The tooling is pnpm, pinned by `packageManager` in `package.json`; don't reintroduce npm commands or a `package-lock.json`. `just` lists the same tasks under shorter names; most recipes delegate to a package script, so `package.json` is where a command is defined.

Run one test file, or filter by name:

Expand All @@ -23,7 +23,7 @@ node --import tsx --test test/parse.test.ts
node --import tsx --test --test-name-pattern='<name>' test/cli.test.ts
```

Most suites drive the compiled binary (`dist/index.js`, see `test/helpers.ts`) against throwaway repos (a bare `origin` plus a working clone), so run `npx tsc` first when a change touches `src/`. There is no linter; `tsc` and `verify:generated` are the static checks.
Most suites drive the compiled binary (`dist/index.js`, see `test/helpers.ts`) against throwaway repos (a bare `origin` plus a working clone), so run `pnpm exec tsc` first when a change touches `src/`. There is no linter; `tsc` and `verify:generated` are the static checks.

## Spec-driven

Expand All @@ -41,7 +41,7 @@ Most suites drive the compiled binary (`dist/index.js`, see `test/helpers.ts`) a

## Generated files

`src/help.ts` is the single source of truth for flags. `scripts/gen-docs.ts` generates `man/git-fi.1`, `completions/*`, and the marked `<!-- BEGIN GENERATED -->` tables in `docs/commands.md`. Completion logic lives in `scripts/completion/*.tmpl`. Edit those sources and run `npm run build`; never hand-edit the outputs.
`src/help.ts` is the single source of truth for flags. `scripts/gen-docs.ts` generates `man/git-fi.1`, `completions/*`, and the marked `<!-- BEGIN GENERATED -->` tables in `docs/commands.md`. Completion logic lives in `scripts/completion/*.tmpl`. Edit those sources and run `pnpm run build`; never hand-edit the outputs.

## Releases

Expand Down
Loading
Loading