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
125 changes: 46 additions & 79 deletions .github/workflows/publish-protocol-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,87 +114,21 @@ jobs:
fi
echo "Build validation passed"

- name: Upload build artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: protocol-core-build
path: packages/protocol-core/dist/
retention-days: 7

# ============================================
# JOB 3: Version Bump (if manual trigger)
# ============================================
version-bump:
name: Version Bump
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
timeout-minutes: 5
permissions:
contents: write

outputs:
new_version: ${{ steps.bump.outputs.new_version }}

steps:
- name: Verify branch is main
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Error: Can only publish from main branch"
exit 1
fi

- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0
with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '20'

- name: Configure Git
run: |
git config user.name "quickswap-bot"
git config user.email "[email protected]"

- name: Bump version
id: bump
run: |
cd packages/protocol-core
echo "Current version: $(node -p "require('./package.json').version")"
pnpm version ${{ inputs.bump }} --no-git-tag-version --no-commit-hooks
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Version bumped to: $NEW_VERSION"

- name: Commit and push version
run: |
git add packages/protocol-core/package.json
git diff --staged --quiet || git commit -m "chore(release): protocol-core v$(cd packages/protocol-core && node -p "require('./package.json').version") [skip ci]"
git tag "protocol-core/v$(cd packages/protocol-core && node -p "require('./package.json').version")"
git push origin HEAD --follow-tags

# ============================================
# JOB 4: Publish to NPM (Secure OIDC)
# JOB 3: Publish to NPM (Secure OIDC)
# Atomic: bump → build → publish → commit
# Version is only committed AFTER successful publish
# ============================================
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: [build-and-test, version-bump]
needs: build-and-test
if: |
always() &&
!cancelled() &&
needs.build-and-test.result == 'success' &&
(
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/protocol-core/v')) ||
(github.event_name == 'workflow_dispatch' && !inputs.dry_run && needs.version-bump.result == 'success')
(github.event_name == 'workflow_dispatch' && !inputs.dry_run)
)
timeout-minutes: 10
permissions:
Expand All @@ -206,15 +140,20 @@ jobs:
url: https://www.npmjs.com/package/@quickswap-defi/protocol-core

steps:
- name: Verify branch is main
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Error: Can only publish from main branch"
exit 1
fi

- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Fetch version bump
if: github.event_name == 'workflow_dispatch'
run: git fetch origin --tags

- name: Verify tag is on main branch
if: github.event_name == 'push'
run: |
Expand Down Expand Up @@ -243,6 +182,19 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

# --- Version bump (local only, NOT committed yet) ---
- name: Bump version locally
if: github.event_name == 'workflow_dispatch'
id: bump
run: |
cd packages/protocol-core
echo "Current version: $(node -p "require('./package.json').version")"
pnpm version ${{ inputs.bump }} --no-git-tag-version --no-commit-hooks
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Version bumped to: $NEW_VERSION (local only, not committed)"

# --- Build and publish ---
- name: Build package
run: pnpm --filter @quickswap-defi/protocol-core build

Expand All @@ -251,8 +203,6 @@ jobs:
cd packages/protocol-core
echo "Package details:"
npm pack --dry-run
echo ""
npm publish --dry-run

- name: Check if version already exists
id: check_version
Expand All @@ -277,13 +227,30 @@ jobs:
run: |
echo "Skipping: version ${{ steps.check_version.outputs.version }} already exists"

# --- Only after successful publish: commit version bump ---
- name: Configure Git
if: github.event_name == 'workflow_dispatch' && steps.check_version.outputs.exists == 'false'
run: |
git config user.name "quickswap-bot"
git config user.email "[email protected]"

- name: Commit and push version
if: github.event_name == 'workflow_dispatch' && steps.check_version.outputs.exists == 'false'
run: |
VERSION=$(cd packages/protocol-core && node -p "require('./package.json').version")
git add packages/protocol-core/package.json
git commit -m "chore(release): protocol-core v${VERSION} [skip ci]"
git tag "protocol-core/v${VERSION}"
git push origin HEAD --follow-tags

- name: Get published version
id: version
run: |
VERSION=$(cd packages/protocol-core && node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Create GitHub Release
if: steps.check_version.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
Expand All @@ -300,7 +267,7 @@ jobs:
${{ contains(steps.version.outputs.version, '-') && '--prerelease' || '' }}

# ============================================
# JOB 5: Post-Publish Verification
# JOB 4: Post-Publish Verification
# ============================================
verify-publish:
name: Verify Publication
Expand Down
125 changes: 46 additions & 79 deletions .github/workflows/publish-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,87 +111,21 @@ jobs:
fi
echo "Build validation passed"

- name: Upload build artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: sdk-build
path: packages/sdk/dist/
retention-days: 7

# ============================================
# JOB 3: Version Bump (if manual trigger)
# ============================================
version-bump:
name: Version Bump
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
timeout-minutes: 5
permissions:
contents: write

outputs:
new_version: ${{ steps.bump.outputs.new_version }}

steps:
- name: Verify branch is main
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Error: Can only publish from main branch"
exit 1
fi

- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0
with:
version: 9

- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '20'

- name: Configure Git
run: |
git config user.name "quickswap-bot"
git config user.email "[email protected]"

- name: Bump version
id: bump
run: |
cd packages/sdk
echo "Current version: $(node -p "require('./package.json').version")"
pnpm version ${{ inputs.bump }} --no-git-tag-version --no-commit-hooks
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Version bumped to: $NEW_VERSION"

- name: Commit and push version
run: |
git add packages/sdk/package.json
git diff --staged --quiet || git commit -m "chore(release): sdk v$(cd packages/sdk && node -p "require('./package.json').version") [skip ci]"
git tag "sdk/v$(cd packages/sdk && node -p "require('./package.json').version")"
git push origin HEAD --follow-tags

# ============================================
# JOB 4: Publish to NPM (Secure OIDC)
# JOB 3: Publish to NPM (Secure OIDC)
# Atomic: bump → build → publish → commit
# Version is only committed AFTER successful publish
# ============================================
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: [build-and-test, version-bump]
needs: build-and-test
if: |
always() &&
!cancelled() &&
needs.build-and-test.result == 'success' &&
(
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/sdk/v')) ||
(github.event_name == 'workflow_dispatch' && !inputs.dry_run && needs.version-bump.result == 'success')
(github.event_name == 'workflow_dispatch' && !inputs.dry_run)
)
timeout-minutes: 10
permissions:
Expand All @@ -203,15 +137,20 @@ jobs:
url: https://www.npmjs.com/package/@quickswap-defi/sdk

steps:
- name: Verify branch is main
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Error: Can only publish from main branch"
exit 1
fi

- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Fetch version bump
if: github.event_name == 'workflow_dispatch'
run: git fetch origin --tags

- name: Verify tag is on main branch
if: github.event_name == 'push'
run: |
Expand Down Expand Up @@ -240,6 +179,19 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

# --- Version bump (local only, NOT committed yet) ---
- name: Bump version locally
if: github.event_name == 'workflow_dispatch'
id: bump
run: |
cd packages/sdk
echo "Current version: $(node -p "require('./package.json').version")"
pnpm version ${{ inputs.bump }} --no-git-tag-version --no-commit-hooks
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Version bumped to: $NEW_VERSION (local only, not committed)"

# --- Build and publish ---
- name: Build package
run: pnpm --filter @quickswap-defi/sdk build

Expand All @@ -248,8 +200,6 @@ jobs:
cd packages/sdk
echo "Package details:"
npm pack --dry-run
echo ""
npm publish --dry-run

- name: Check if version already exists
id: check_version
Expand All @@ -274,13 +224,30 @@ jobs:
run: |
echo "Skipping: version ${{ steps.check_version.outputs.version }} already exists"

# --- Only after successful publish: commit version bump ---
- name: Configure Git
if: github.event_name == 'workflow_dispatch' && steps.check_version.outputs.exists == 'false'
run: |
git config user.name "quickswap-bot"
git config user.email "[email protected]"

- name: Commit and push version
if: github.event_name == 'workflow_dispatch' && steps.check_version.outputs.exists == 'false'
run: |
VERSION=$(cd packages/sdk && node -p "require('./package.json').version")
git add packages/sdk/package.json
git commit -m "chore(release): sdk v${VERSION} [skip ci]"
git tag "sdk/v${VERSION}"
git push origin HEAD --follow-tags

- name: Get published version
id: version
run: |
VERSION=$(cd packages/sdk && node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Create GitHub Release
if: steps.check_version.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
Expand All @@ -297,7 +264,7 @@ jobs:
${{ contains(steps.version.outputs.version, '-') && '--prerelease' || '' }}

# ============================================
# JOB 5: Post-Publish Verification
# JOB 4: Post-Publish Verification
# ============================================
verify-publish:
name: Verify Publication
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quickswap-defi/protocol-core",
"version": "2.0.1",
"version": "0.1.0",
"license": "MIT",
"description": "Pure protocol knowledge for QuickSwap DEX — chains, stablecoins, fees, schema detection",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/fraction.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fraction } from '../src'
import JSBI from 'jsbi'

describe.only('Fraction', () => {
describe('Fraction', () => {
describe('#quotient', () => {
it('floor division', () => {
expect(new Fraction(JSBI.BigInt(8), JSBI.BigInt(3)).quotient).toEqual(JSBI.BigInt(2)) // one below
Expand Down