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
152 changes: 142 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,162 @@ on:
types: [closed]
branches: [main]

permissions:
contents: read

jobs:
release:
checks:
if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
outputs:
version: ${{ steps.version.outputs.version }}
tag_name: ${{ steps.version.outputs.tag_name }}
steps:
- uses: actions/checkout@v4

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

- name: Get version
id: version
run: echo "version=v$(node -p 'require("./package.json").version')" >> "$GITHUB_OUTPUT"
- name: Create and push tag
run: |
git tag ${{ steps.version.outputs.version }}
git push origin ${{ steps.version.outputs.version }}
VERSION=$(node -p 'require("./package.json").version')
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid version: $VERSION"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag_name=v$VERSION" >> "$GITHUB_OUTPUT"

- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm run build
- run: npm test

publish:
needs: checks
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4

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

- run: npm ci
- run: npm run build
- run: npm test
- run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

update-homebrew:
needs: [checks, publish]
runs-on: ubuntu-latest
steps:
- name: Wait for npm publish
run: |
VERSION="${{ needs.checks.outputs.version }}"
for i in $(seq 1 30); do
if npm view "@fintoc/cli@$VERSION" version 2>/dev/null; then
echo "Found @fintoc/cli@$VERSION on npm"
exit 0
fi
echo "Attempt $i/30 - waiting 10s..."
sleep 10
done
echo "Timed out waiting for @fintoc/cli@$VERSION on npm"
npm view "@fintoc/cli" versions --json || true
exit 1

- name: Download tarball and compute SHA256
id: sha
run: |
VERSION="${{ needs.checks.outputs.version }}"
URL="https://registry.npmjs.org/@fintoc/cli/-/cli-${VERSION}.tgz"
TARBALL=$(mktemp)
HTTP_CODE=$(curl -sL -o "$TARBALL" -w '%{http_code}' "$URL")
if [ "$HTTP_CODE" != "200" ]; then
echo "Failed to download tarball (HTTP $HTTP_CODE)"
exit 1
fi
SHA256=$(sha256sum "$TARBALL" | awk '{print $1}')
echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"
echo "url=$URL" >> "$GITHUB_OUTPUT"

- name: Clone homebrew-tap
uses: actions/checkout@v4
with:
repository: fintoc-com/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
path: homebrew-tap

- name: Update formula
env:
TARBALL_URL: ${{ steps.sha.outputs.url }}
TARBALL_SHA256: ${{ steps.sha.outputs.sha256 }}
VERSION: ${{ needs.checks.outputs.version }}
run: |
for var in TARBALL_URL TARBALL_SHA256 VERSION; do
[ -z "${!var}" ] && echo "::error::$var is empty" && exit 1
done
envsubst '$TARBALL_URL $TARBALL_SHA256 $VERSION' > homebrew-tap/Formula/fintoc.rb <<'RUBY'
class Fintoc < Formula
desc "CLI for the Fintoc API"
homepage "https://github.com/fintoc-com/fintoc-cli"
url "$TARBALL_URL"
version "$VERSION"
sha256 "$TARBALL_SHA256"
license "BSD-3-Clause"

depends_on "node"

def install
system "npm", "install", *std_npm_args
bin.install_symlink Dir["#{libexec}/bin/*"]
end

test do
assert_match "fintoc/#{version}", shell_output("#{bin}/fintoc --version")
end
end
RUBY

- name: Commit and push
run: |
VERSION="${{ needs.checks.outputs.version }}"
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/fintoc.rb
if git diff --cached --quiet; then
echo "Formula already up to date"
exit 0
fi
git commit -m "fintoc $VERSION" -m "https://github.com/fintoc-com/fintoc-cli/releases/tag/v$VERSION"
git push

tag:
needs: [checks, publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Create and push tag
env:
TAG_NAME: ${{ needs.checks.outputs.tag_name }}
run: |
if git ls-remote --exit-code --tags origin "refs/tags/$TAG_NAME" >/dev/null 2>&1; then
echo "::error::Tag $TAG_NAME already exists"
exit 1
fi
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
124 changes: 0 additions & 124 deletions .github/workflows/update-homebrew.yml

This file was deleted.

8 changes: 4 additions & 4 deletions src/lib/webhooks/__tests__/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('webhook relay handlers', () => {

await createWebhookRelayHandlers({}).webhook_event!(message)

expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 --> payment.succeeded [evt_123]')
expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 <-- payment.succeeded [evt_123]')
})

test('prints the full event in JSON mode', async () => {
Expand Down Expand Up @@ -86,9 +86,9 @@ describe('webhook relay handlers', () => {
},
body: event,
})
expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 --> payment.succeeded [evt_123]')
expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 <-- payment.succeeded [evt_123]')
expect(log).toHaveBeenCalledWith(
'2026-05-11 14:52:13 <-- [204] POST https://webhook.site/828b463d-c4a4-4f6b-a450-7c2cdb575d63 [evt_123]',
'2026-05-11 14:52:13 --> [204] POST https://webhook.site/828b463d-c4a4-4f6b-a450-7c2cdb575d63 [evt_123]',
)
})

Expand All @@ -104,7 +104,7 @@ describe('webhook relay handlers', () => {

await createWebhookRelayHandlers({ events: ['payment.succeeded'] }).webhook_event!(message)

expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 --> payment.succeeded [evt_123]')
expect(log).toHaveBeenCalledWith('2026-05-11 14:52:12 <-- payment.succeeded [evt_123]')
})

test('skips events not included in the event filter', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/webhooks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const displayWebhookEvent = (event: WebhookEvent, options: { json: boolean | und
return
}

log(`${dim(reformatDate(event.created_at))} --> ${bold(event.type)} [${event.id}]`)
log(`${dim(reformatDate(event.created_at))} <-- ${bold(event.type)} [${event.id}]`)
}

const colorStatusCode = (statusCode: number) => {
Expand All @@ -89,7 +89,7 @@ const displayForwardResult = (
const timestamp = dim(reformatDate(result.timestamp))
const code = bold(colorStatusCode(result.statusCode))

log(`${timestamp} <-- [${code}] ${result.method} ${result.url} [${result.event}]`)
log(`${timestamp} --> [${code}] ${result.method} ${result.url} [${result.event}]`)

if (options.json) {
log('\n')
Expand Down
Loading