diff --git a/.github/workflows/publish-protocol-core.yaml b/.github/workflows/publish-protocol-core.yaml index 07470e4..19cbcaf 100644 --- a/.github/workflows/publish-protocol-core.yaml +++ b/.github/workflows/publish-protocol-core.yaml @@ -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 "bot@quickswap.exchange" - - - 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: @@ -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: | @@ -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 @@ -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 @@ -277,6 +227,22 @@ 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 "bot@quickswap.exchange" + + - 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: | @@ -284,6 +250,7 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Create GitHub Release + if: steps.check_version.outputs.exists == 'false' env: GH_TOKEN: ${{ github.token }} run: | @@ -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 diff --git a/.github/workflows/publish-sdk.yaml b/.github/workflows/publish-sdk.yaml index 7d8d2de..560038f 100644 --- a/.github/workflows/publish-sdk.yaml +++ b/.github/workflows/publish-sdk.yaml @@ -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 "bot@quickswap.exchange" - - - 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: @@ -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: | @@ -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 @@ -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 @@ -274,6 +224,22 @@ 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 "bot@quickswap.exchange" + + - 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: | @@ -281,6 +247,7 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Create GitHub Release + if: steps.check_version.outputs.exists == 'false' env: GH_TOKEN: ${{ github.token }} run: | @@ -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 diff --git a/packages/protocol-core/package.json b/packages/protocol-core/package.json index 083ece2..0cc39d0 100644 --- a/packages/protocol-core/package.json +++ b/packages/protocol-core/package.json @@ -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": { diff --git a/packages/sdk/test/fraction.test.ts b/packages/sdk/test/fraction.test.ts index 1a36ca7..698024d 100755 --- a/packages/sdk/test/fraction.test.ts +++ b/packages/sdk/test/fraction.test.ts @@ -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