diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 7a86483..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,122 +0,0 @@ -name: Publish package - -on: - push: - tags: - - 'aqua-v*.*.*' - - 'cross-chain-v*.*.*' - - 'fusion-v*.*.*' - - 'limit-order-v*.*.*' - - 'swap-vm-v*.*.*' - # Temp: triggers for testing new pipelines in PR: https://github.com/1inch/sdks/pull/23 - - '*/v*.*.*' - workflow_dispatch: - inputs: - tag: - type: string - description: Tag to publish (e.g. aqua/v1.2.3) - required: true - dry_run: - type: boolean - description: Dry run (preview publish commands) - required: false - default: false - -jobs: - determine-sdk: - runs-on: ubuntu-latest - outputs: - sdk: ${{ steps.determine-sdk.outputs.sdk }} - sdk_path: ${{ steps.determine-sdk.outputs.sdk_path }} - steps: - - name: Determine SDK from tag - id: determine-sdk - run: | - TAG=${GITHUB_REF_NAME} - if [[ "$TAG" == aqua-v* ]]; then - echo "sdk=aqua" >> "$GITHUB_OUTPUT" - echo "sdk_path=typescript/aqua" >> "$GITHUB_OUTPUT" - elif [[ "$TAG" == cross-chain-v* ]]; then - echo "sdk=cross-chain" >> "$GITHUB_OUTPUT" - echo "sdk_path=typescript/cross-chain" >> "$GITHUB_OUTPUT" - elif [[ "$TAG" == fusion-v* ]]; then - echo "sdk=fusion" >> "$GITHUB_OUTPUT" - echo "sdk_path=typescript/fusion" >> "$GITHUB_OUTPUT" - elif [[ "$TAG" == limit-order-v* ]]; then - echo "sdk=limit-order" >> "$GITHUB_OUTPUT" - echo "sdk_path=typescript/limit-order" >> "$GITHUB_OUTPUT" - elif [[ "$TAG" == swap-vm-v* ]]; then - echo "sdk=swap-vm" >> "$GITHUB_OUTPUT" - echo "sdk_path=typescript/swap-vm" >> "$GITHUB_OUTPUT" - else - echo "Unknown tag pattern: $TAG" >&2 - exit 1 - fi - - publish-to-npm: - needs: determine-sdk - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 22 - registry-url: 'https://registry.npmjs.org' - scope: '@1inch' - cache: pnpm - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build SDK - run: pnpm nx build ${{ needs.determine-sdk.outputs.sdk }} - - - name: Publish ๐Ÿš€ - run: | - VERSION=$(node -p "require('../package.json').version") - if [[ "$VERSION" == *"-rc"* ]]; then - pnpm publish --no-git-checks --access=public --tag next - else - pnpm publish --no-git-checks --access=public - fi - working-directory: ${{ needs.determine-sdk.outputs.sdk_path }}/dist - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - - publish-to-github: - needs: determine-sdk - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: pnpm - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build SDK - run: pnpm nx build ${{ needs.determine-sdk.outputs.sdk }} - - - name: Auth in GitHub private registry npm - run: | - echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc - echo "@1inch:registry=https://npm.pkg.github.com" >> .npmrc - - - name: Publish ๐Ÿš€ - run: pnpm publish --no-git-checks - working-directory: ${{ needs.determine-sdk.outputs.sdk_path }}/dist \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 233eca7..1bed1b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,37 +1,52 @@ -name: Release new version +name: Release typescript on: workflow_dispatch: inputs: - sdk: + project: type: choice - description: SDK to release + description: Library to release required: true options: - aqua - - cross-chain - - fusion - - limit-order + - sdk-core - swap-vm - version: + bump: type: choice - description: Version bump type + description: Semver bump or custom required: true options: - patch - minor - major - prerelease + preid: + type: string + description: Prerelease identifier (used when bump = prerelease) + required: false + default: rc + dry_run: + type: boolean + description: Dry Run + required: false + default: false + +permissions: + contents: write + packages: write + actions: write jobs: release: runs-on: ubuntu-latest - permissions: - contents: write - packages: write - actions: write + outputs: + project: ${{ steps.pkg.outputs.project }} + sdk_path: ${{ steps.pkg.outputs.sdk_path }} + package_name: ${{ steps.pkg.outputs.package_name }} + pkg_version: ${{ steps.pkg.outputs.pkg_version }} + tag: ${{ steps.pkg.outputs.tag }} steps: - - name: Checkout + - name: Checkout master uses: actions/checkout@v4 with: fetch-depth: 0 @@ -45,55 +60,144 @@ jobs: with: node-version: 22 cache: pnpm + registry-url: https://registry.npmjs.org - - name: Install Dev Dependencies - run: pnpm install -D + - name: Install dependencies + run: pnpm install --frozen-lockfile - - name: Get SDK info - id: sdk_info + - name: Configure git run: | - SDK_PATH="typescript/${{ github.event.inputs.sdk }}" - echo "SDK_PATH=$SDK_PATH" >> "$GITHUB_OUTPUT" - cd $SDK_PATH - echo "OLD_VERSION=$(pnpm pkg get version | tr -d '"')" >> "$GITHUB_OUTPUT" + git config --global user.email "ci_cd_bot@1inch.io" + git config --global user.name "CI/CD Bot" + env: + GITHUB_TOKEN: ${{ github.token }} - - name: Bump package.json version + - name: Run Nx release id: version + env: + GITHUB_TOKEN: ${{ github.token }} run: | - cd ${{ steps.sdk_info.outputs.SDK_PATH }} - pnpm version ${{ github.event.inputs.version }} --preid rc --git-tag-version=false - echo "NEW_VERSION=$(pnpm pkg get version | tr -d '"')" >> "$GITHUB_OUTPUT" + SPECIFIER="${{ inputs.bump }}" + + PREID_FLAG="" + if [ "${{ inputs.bump }}" = "prerelease" ] && [ -n "${{ inputs.preid }}" ]; then + PREID_FLAG="--preid ${{ inputs.preid }}" + fi - - name: Generate changelog + DRY_RUN_FLAG="" + if [ "${{ inputs.dry_run }}" = "true" ]; then + DRY_RUN_FLAG="--dry-run" + fi + + npx nx release "$SPECIFIER" \ + --projects="${{ inputs.project }}" \ + $PREID_FLAG \ + $DRY_RUN_FLAG \ + --skip-publish \ + --verbose + + - name: Resolve package info + id: pkg run: | - cd ${{ steps.sdk_info.outputs.SDK_PATH }} - # Try to generate changelog from the last tag for this SDK - LAST_TAG="${{ github.event.inputs.sdk }}-v${{ steps.sdk_info.outputs.OLD_VERSION }}" - pnpm changelog:generate -t $LAST_TAG || pnpm changelog:generate + SDK_PATH="typescript/${{ inputs.project }}" + PKG_NAME=$(node -p "require('./$SDK_PATH/package.json').name") + PKG_VERSION=$(node -p "require('./$SDK_PATH/package.json').version") + TAG="${{ inputs.project }}/v${PKG_VERSION}" - - name: Create github release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + echo "project=${{ inputs.project }}" >> "$GITHUB_OUTPUT" + echo "sdk_path=$SDK_PATH" >> "$GITHUB_OUTPUT" + echo "package_name=$PKG_NAME" >> "$GITHUB_OUTPUT" + echo "pkg_version=$PKG_VERSION" >> "$GITHUB_OUTPUT" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + + - name: Show updated version run: | - git config --global user.email ci_cd_bot@1inch.io - git config --global user.name "CI/CD Bot" - - cd ${{ steps.sdk_info.outputs.SDK_PATH }} - git add package.json - git commit -m "version @1inch/${{ github.event.inputs.sdk }}-sdk v${{ steps.version.outputs.NEW_VERSION }}" - - TAG_NAME="${{ github.event.inputs.sdk }}-v${{ steps.version.outputs.NEW_VERSION }}" - git tag $TAG_NAME - git push - git push --tags - - if [ -f CHANGELOG.md ]; then - gh release create $TAG_NAME --notes-file CHANGELOG.md --title "@1inch/${{ github.event.inputs.sdk }}-sdk v${{ steps.version.outputs.NEW_VERSION }}" - else - gh release create $TAG_NAME --generate-notes --title "@1inch/${{ github.event.inputs.sdk }}-sdk v${{ steps.version.outputs.NEW_VERSION }}" + if [ "${{ inputs.dry_run }}" = "true" ]; then + echo "(dry-run: version on disk is unchanged)" fi + echo "Version = ${{ steps.pkg.outputs.pkg_version }}" + + publish-npmjs: + runs-on: ubuntu-latest + needs: release + if: ${{ github.event.inputs.dry_run != 'true' }} + permissions: + contents: read + packages: write + id-token: write + steps: + - name: Checkout tag + uses: actions/checkout@v4 + with: + ref: ${{ needs.release.outputs.tag }} + fetch-depth: 0 - - name: Trigger publish + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + registry-url: https://registry.npmjs.org + always-auth: true + + # Updating npm to 11 since it's minimal version supporting "npm publish" with OIDC token + - name: Install npm@11 + run: npm install -g npm@11 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build package (pnpm) + run: pnpm --filter "${{ needs.release.outputs.package_name }}" build + + - name: Publish to npmjs + working-directory: ${{ needs.release.outputs.sdk_path }} + run: | + TAG_ARG="" + if [ "${{ github.event.inputs.bump }}" = "prerelease" ]; then + TAG_ARG="--tag next" + fi + + npm publish --access public --provenance $TAG_ARG + + publish-github-packages: + runs-on: ubuntu-latest + needs: release + if: ${{ github.event.inputs.dry_run != 'true' }} + permissions: + contents: read + packages: write + steps: + - name: Checkout tag + uses: actions/checkout@v4 + with: + ref: ${{ needs.release.outputs.tag }} + fetch-depth: 0 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build package (pnpm) + run: pnpm --filter "${{ needs.release.outputs.package_name }}" build + + - name: Publish to GitHub Packages env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh workflow run publish.yml -r ${{ github.event.inputs.sdk }}-v${{ steps.version.outputs.NEW_VERSION }} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ github.token }} + working-directory: ${{ needs.release.outputs.sdk_path }} + run: | + npm config set @1inch:registry https://npm.pkg.github.com + npm config set //npm.pkg.github.com/:_authToken "${NODE_AUTH_TOKEN}" + + npm publish --access public diff --git a/.github/workflows/test-publish.yml b/.github/workflows/test-publish.yml deleted file mode 100644 index d23c754..0000000 --- a/.github/workflows/test-publish.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Test Publish (Dry Run) - -on: - workflow_dispatch: - inputs: - sdk: - type: choice - description: SDK to test publish - required: true - options: - - aqua - - cross-chain - - fusion - - limit-order - - swap-vm - dry_run: - type: boolean - description: 'Dry run (do not actually publish)' - required: false - default: true - -jobs: - test-publish: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - uses: actions/setup-node@v4 - with: - node-version: 22 - registry-url: 'https://registry.npmjs.org' - scope: '@1inch' - cache: pnpm - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build SDK - run: pnpm nx build ${{ github.event.inputs.sdk }} - - - name: Check build output - run: | - echo "๐Ÿ“ฆ Checking build output for ${{ github.event.inputs.sdk }}" - ls -la typescript/${{ github.event.inputs.sdk }}/dist/ - - echo "" - echo "๐Ÿ“‹ Package.json contents:" - cat typescript/${{ github.event.inputs.sdk }}/dist/package.json | head -20 - - echo "" - echo "๐Ÿ“ Build structure:" - find typescript/${{ github.event.inputs.sdk }}/dist -type f -name "*.js" | head -10 - - - name: Dry Run - Publish Test - if: ${{ github.event.inputs.dry_run == 'true' }} - run: | - cd typescript/${{ github.event.inputs.sdk }} - echo "๐Ÿงช DRY RUN: Would publish the following package:" - npm pack dist --dry-run - echo "" - echo "โœ… Dry run complete - no packages were published" - - - name: Real Publish (Manual Approval Required) - if: ${{ github.event.inputs.dry_run == 'false' }} - run: | - echo "โš ๏ธ Real publish requested - this would publish to NPM" - echo "This workflow is for testing only - use the release workflow for real publishing" - exit 1 \ No newline at end of file diff --git a/nx.json b/nx.json index b8dfb7b..d9e3307 100644 --- a/nx.json +++ b/nx.json @@ -81,6 +81,17 @@ }, "automaticFromRef": true }, + "version": { + "updateDependents": "never", + "logUnchangedProjects": true + }, + "git": { + "commit": true, + "commitMessage": "chore(release): {version}", + "tag": true, + "push": true, + "stageChanges": true + }, "groups": { "typescript": { "projects": ["typescript/*"], @@ -88,10 +99,7 @@ } }, "releaseTag": { - "pattern": "{projectName}/{version}" - }, - "git": { - "commitMessage": "chore(release): {version}" + "pattern": "{projectName}/v{version}" } } } diff --git a/typescript/README.md b/typescript/README.md index 466e9a8..0362e0f 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -81,19 +81,22 @@ pnpm lint:types ### Release Process 1. **Create a new release:** - - Go to GitHub Actions โ†’ "Release new version" - - Select the SDK to release - - Choose version bump type (patch, minor, major, prerelease) + - Go to GitHub Actions โ†’ "Release" + - Pick the SDK to release (aqua, sdk-core, swap-vm) + - Choose the bump (patch, minor, major, prerelease; prerelease can take a `preid`) + - Dependents are not auto-bumped (NX `updateDependents=never`) 2. **Automatic publishing:** - - The release workflow creates a version tag (e.g., `aqua/v1.0.0`) - - This triggers the publish workflow automatically - - The SDK is published to public NPM registry + - The release workflow commits + tags (e.g., `aqua/v1.0.0`) and generates changelogs/GitHub Releases + - Publish happens in the same workflow (split jobs for npmjs and GitHub Packages) + - Prerelease bumps publish with npm dist-tag `next`; normal bumps use the default tag + - Dry runs skip publishing and leave on-disk versions unchanged ### Version Tags Each SDK has independent versioning with specific tag patterns: - `aqua/v*.*.*` - @1inch/aqua-sdk +- `sdk-core/v*.*.*` - @1inch/sdk-core - `swap-vm/v*.*.*` - @1inch/swap-vm-sdk ## ๐Ÿ”ง Configuration