Skip to content
Open
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
119 changes: 47 additions & 72 deletions .github/workflows/postman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,70 @@ name: Publish to Postman Workspace

on:
push:
branches:
- main
branches: [demo-main]
pull_request:
branches:
- main
branches: [demo-main]
workflow_dispatch:

jobs:
quality-checks:
name: Validate API and Collections
postman:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v6

- run: curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: '>= 20.19.0'
cache: 'yarn'
node-version: "24"
cache: "npm"

- name: Install dependencies
run: yarn install

- name: Install Postman CLI
run: curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh

- name: Verify Postman CLI version
run: postman --version

- name: Login to Postman
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
run: postman login --with-api-key "$POSTMAN_API_KEY"

- name: Run unit and integration tests
run: yarn test

- name: Run Spectral linting on collections
run: yarn lint:collections
run: npm install

- name: Start API server
- name: Start server in background
run: |
yarn start &
echo $! > server.pid

- name: Wait for API readiness
run: |
for attempt in {1..30}; do
if curl -sSf http://localhost:3000/health >/dev/null; then
exit 0
fi
if curl -sSf http://localhost:3000 >/dev/null; then
exit 0
npm run dev &
echo $! > pidfile
# Wait for server to be ready (port 3000)
for i in {1..20}; do
if nc -z localhost 3000; then
echo "Server is up!"
break
fi
sleep 1
echo "Waiting for server..."
sleep 2
done
echo "API did not become ready in time." >&2
exit 1

- name: Run Postman collection tests
run: yarn test:api

- name: Stop API server
if: always()
# Local collection run does not require Postman cloud login (see Postman CLI auth docs).
# This avoids "invalid API key" when secrets are unavailable (e.g. PRs from forks).
- name: Validate Collection
run: |
if [ -f server.pid ]; then
kill $(cat server.pid) || true
rm server.pid
fi
postman collection run "postman/collections/Intergalactic Bank API"

- name: Show workspace configuration
if: github.event_name != 'pull_request'
- name: Push to Postman Cloud
if: github.event_name == 'push'
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
# Optional: set repo variable POSTMAN_REGION to `eu` if you use EU data residency
POSTMAN_REGION: ${{ vars.POSTMAN_REGION }}
run: |
echo "🧩 Workspace Configuration:"
cat .postman/config.json
echo ""
echo "📁 Collections to sync:"
ls -la postman/collections/
echo ""
echo "🌍 Environments to sync:"
ls -la postman/environments/

- name: Push workspace to Postman
run: postman workspace push -y

- name: Confirm sync success
if: github.event_name != 'pull_request'
if [ -z "${POSTMAN_API_KEY}" ]; then
echo "::error::POSTMAN_API_KEY is empty. Add it under Settings → Secrets and variables → Actions."
echo "Secrets are not passed to workflows for pull_request events opened from repository forks."
exit 1
fi
if [ -n "${POSTMAN_REGION}" ]; then
postman login --with-api-key "$POSTMAN_API_KEY" --region "$POSTMAN_REGION"
else
postman login --with-api-key "$POSTMAN_API_KEY"
fi
postman workspace push -y
- name: Stop server
if: always()
run: |
echo "✅ Workspace successfully synced!"
echo "🌐 View your workspace at: https://web.postman.co/workspace/a6c44822-f001-4728-b0d4-5a1917289054"
if [ -f pidfile ]; then
kill $(cat pidfile) || true
rm pidfile
fi
44 changes: 2 additions & 42 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo "🔍 Running linter on staged files..."
npx lint-staged

echo "🧪 Running tests..."
npm test

# Run Spectral linting on Postman collections if they changed
if git diff --cached --name-only | grep -qE "postman/collections/"; then
echo "📋 Linting Postman collections with Spectral..."
node .spectral/lint-with-names.js

if [ $? -ne 0 ]; then
echo "❌ Spectral linting failed for Postman collections"
exit 1
fi

echo "✅ Postman collection linting passed!"
fi

# Run Postman tests only if Postman collection files changed
if git diff --cached --name-only | grep -qE "postman/"; then
echo "📬 Postman collection changed - Running Postman tests..."

# Run all collections in postman/collections/
for collection in postman/collections/*.postman_collection.json; do
if [ -f "$collection" ]; then
echo " → Running: $(basename "$collection")"
postman collection run "$collection"

if [ $? -ne 0 ]; then
echo "❌ Postman collection failed: $collection"
exit 1
fi
fi
done

echo "✅ All Postman collections passed!"
else
echo "⏭️ No Postman collection changes detected, skipping Postman tests"
fi

echo "✅ All pre-commit checks passed!"
# Pre-commit hooks disabled (no-op). Restore previous behavior from git history if needed.
exit 0
7 changes: 7 additions & 0 deletions .postman/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Use this workspace to collaborate
workspace:
id: ""

localResources:
specs:
- ../openapi/openapi.yaml
23 changes: 0 additions & 23 deletions openapi/.openapi-generator-ignore

This file was deleted.

Loading