diff --git a/.github/workflows/publish-core.yml b/.github/workflows/publish-core.yml new file mode 100644 index 0000000..40b5e30 --- /dev/null +++ b/.github/workflows/publish-core.yml @@ -0,0 +1,76 @@ +name: Publish ads-core to npm + +on: + workflow_dispatch: + inputs: + environment: + description: "Environment (production or beta)" + required: false + default: production + type: choice + options: + - production + - beta + CA_TOKEN: + description: "CodeArtifact Token" + required: true + type: string + CA_OWNER: + description: "CodeArtifact Domain Owner" + required: true + type: string + +permissions: + contents: read + id-token: write + +env: + CODEARTIFACT_DOMAIN: main + CODEARTIFACT_REPOSITORY: internal-npm + AWS_REGION: us-east-1 + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "24" + + - name: Read package version + id: pkg + run: | + VERSION=$(node -p "require('./packages/core/package.json').version") + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "Publishing @vtex/ads-core@${VERSION}" + + - name: Configure npm for CodeArtifact + run: | + set -euo pipefail + CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${{ github.event.inputs.CA_OWNER }}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/" + npm config set registry "${CODEARTIFACT_URL}" + npm config set "//${CODEARTIFACT_DOMAIN}-${{ github.event.inputs.CA_OWNER }}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${{ github.event.inputs.CA_TOKEN }}" + + - name: Download package from CodeArtifact + run: | + set -euo pipefail + npm pack "@vtex/ads-core@${{ steps.pkg.outputs.version }}" + echo "Downloaded:" + ls -1 *.tgz + + - name: Set npm registry to npmjs + run: npm config set registry https://registry.npmjs.org + + - name: Publish tarball to npmjs + run: | + set -euo pipefail + TARBALL=$(ls -1 *.tgz | head -n 1) + TAG_FLAG="" + if [ "${{ github.event.inputs.environment }}" = "beta" ]; then + TAG_FLAG="--tag beta" + fi + npm publish "${TARBALL}" --access public ${TAG_FLAG} diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml deleted file mode 100644 index 0a5b010..0000000 --- a/.github/workflows/publish-npm.yml +++ /dev/null @@ -1,115 +0,0 @@ -name: Publish from CodeArtifact to npm - -on: - workflow_dispatch: - inputs: - version: - description: "Full tag name (e.g. ads-core-v1.2.3 or ads-react-v1.2.3)" - required: true - type: string - environment: - description: "Environment (production or beta)" - required: false - default: production - type: choice - options: - - production - - beta - CA_TOKEN: - description: "CodeArtifact Token" - required: true - type: string - CA_OWNER: - description: "CodeArtifact Domain Owner" - required: true - type: string - -permissions: - contents: read - id-token: write - -env: - CODEARTIFACT_DOMAIN: main - CODEARTIFACT_REPOSITORY: internal-npm - AWS_REGION: us-east-1 - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: "24" - - - name: Parse package name and version from tag - id: parse - run: | - set -euo pipefail - TAG="${{ github.event.inputs.version }}" - - if [[ ! "$TAG" =~ ^(ads-core|ads-react)-v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then - echo "Invalid tag format: $TAG" - echo "Expected: ads-core-v1.2.3 or ads-react-v1.2.3" - exit 1 - fi - - # Extract short name (ads-core or ads-react) and version - SHORT_NAME="${TAG%-v*}" - PACKAGE_VERSION="${TAG#*-v}" - PACKAGE_NAME="@vtex/${SHORT_NAME}" - - echo "package_name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT - echo "package_version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT - echo "Parsed: ${PACKAGE_NAME}@${PACKAGE_VERSION}" - - - name: Configure npm for CodeArtifact - run: | - set -euo pipefail - - export CODEARTIFACT_TOKEN="${{ github.event.inputs.CA_TOKEN }}" - export CODEARTIFACT_DOMAIN_OWNER="${{ github.event.inputs.CA_OWNER }}" - - if [ -z "${CODEARTIFACT_TOKEN:-}" ]; then - echo "CODEARTIFACT_TOKEN not set"; exit 1 - fi - - CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/" - - echo "Configuring npm to use ${CODEARTIFACT_URL}" - - npm config set registry "${CODEARTIFACT_URL}" - npm config set "//${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${CODEARTIFACT_TOKEN}" - - - name: Download package from CodeArtifact - run: | - set -euo pipefail - PACKAGE_NAME="${{ steps.parse.outputs.package_name }}" - PACKAGE_VERSION="${{ steps.parse.outputs.package_version }}" - - echo "Downloading ${PACKAGE_NAME}@${PACKAGE_VERSION} from CodeArtifact..." - npm pack "${PACKAGE_NAME}@${PACKAGE_VERSION}" - - echo "Generated files:" - ls -1 *.tgz - - - name: Set npm registry to npmjs - run: | - set -euo pipefail - npm config set registry https://registry.npmjs.org - npm install -g npm@latest - - - name: Publish tarball to npmjs - run: | - set -euo pipefail - - TARBALL=$(ls -1 *.tgz | head -n 1) - TAG_FLAG="" - if [ "${{ github.event.inputs.environment }}" = "beta" ]; then - TAG_FLAG="--tag beta" - fi - echo "Publishing ${TARBALL} to npmjs..." - npm publish "${TARBALL}" --access public ${TAG_FLAG} diff --git a/.github/workflows/publish-react.yml b/.github/workflows/publish-react.yml new file mode 100644 index 0000000..f3863bd --- /dev/null +++ b/.github/workflows/publish-react.yml @@ -0,0 +1,76 @@ +name: Publish ads-react to npm + +on: + workflow_dispatch: + inputs: + environment: + description: "Environment (production or beta)" + required: false + default: production + type: choice + options: + - production + - beta + CA_TOKEN: + description: "CodeArtifact Token" + required: true + type: string + CA_OWNER: + description: "CodeArtifact Domain Owner" + required: true + type: string + +permissions: + contents: read + id-token: write + +env: + CODEARTIFACT_DOMAIN: main + CODEARTIFACT_REPOSITORY: internal-npm + AWS_REGION: us-east-1 + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "24" + + - name: Read package version + id: pkg + run: | + VERSION=$(node -p "require('./packages/react/package.json').version") + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "Publishing @vtex/ads-react@${VERSION}" + + - name: Configure npm for CodeArtifact + run: | + set -euo pipefail + CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${{ github.event.inputs.CA_OWNER }}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/" + npm config set registry "${CODEARTIFACT_URL}" + npm config set "//${CODEARTIFACT_DOMAIN}-${{ github.event.inputs.CA_OWNER }}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${{ github.event.inputs.CA_TOKEN }}" + + - name: Download package from CodeArtifact + run: | + set -euo pipefail + npm pack "@vtex/ads-react@${{ steps.pkg.outputs.version }}" + echo "Downloaded:" + ls -1 *.tgz + + - name: Set npm registry to npmjs + run: npm config set registry https://registry.npmjs.org + + - name: Publish tarball to npmjs + run: | + set -euo pipefail + TARBALL=$(ls -1 *.tgz | head -n 1) + TAG_FLAG="" + if [ "${{ github.event.inputs.environment }}" = "beta" ]; then + TAG_FLAG="--tag beta" + fi + npm publish "${TARBALL}" --access public ${TAG_FLAG} diff --git a/.vtex/deployment.yaml b/.vtex/deployment.yaml index 73908ab..bfed4ed 100644 --- a/.vtex/deployment.yaml +++ b/.vtex/deployment.yaml @@ -3,17 +3,45 @@ build: provider: dkcicd pipelines: + - name: node-ci-v2 + parameters: + nodeVersion: "24-bookworm" + packageManager: pnpm + skipInstall: false + nodeCommands: + - build + when: + - event: pull_request + source: branch + + - name: npm-publish-v1 + parameters: + nodeVersion: "24-bookworm" + packageManager: pnpm + skipInstall: false + contextPath: packages/core + nodeCommands: + - build + publishViaGithubWorkflow: true + workflowFile: publish-core.yml + workflowVersion: "{{ ref_name }}" + when: + - event: push + source: tag + regex: ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ + - name: npm-publish-v1 parameters: nodeVersion: "24-bookworm" packageManager: pnpm skipInstall: false + contextPath: packages/react nodeCommands: - build publishViaGithubWorkflow: true - workflowFile: publish-npm.yml + workflowFile: publish-react.yml workflowVersion: "{{ ref_name }}" when: - event: push source: tag - regex: ^(ads-core|ads-react)-v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ + regex: ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ diff --git a/README.md b/README.md index 7f8511f..38ea04f 100644 --- a/README.md +++ b/README.md @@ -94,28 +94,29 @@ Open a single PR with everything: code changes, updated `package.json`, updated ### 2. Tag and trigger the pipeline -After the PR is merged, pull `main` and push a Git tag for each bumped package: +After the PR is merged, pull `main` and push a single Git tag for both packages (they are always kept at the same version): ```bash git checkout main && git pull # Production release -git tag @vtex/ads-core@1.2.3 -git push origin @vtex/ads-core@1.2.3 +git tag v1.2.3 +git push origin v1.2.3 # Beta release -git tag @vtex/ads-core@1.2.3-beta.0 -git push origin @vtex/ads-core@1.2.3-beta.0 +git tag v1.2.3-beta.0 +git push origin v1.2.3-beta.0 ``` -Pushing the tag triggers the `npm-publish-v1` pipeline, which builds the package and publishes it to AWS CodeArtifact. +Pushing the tag triggers two `npm-publish-v1` pipelines in parallel — one for `ads-core` and one for `ads-react` — which build each package and publish them to AWS CodeArtifact. ### 3. Publish to npm -After the pipeline completes, go to **Actions → Publish from CodeArtifact to npm** and trigger it manually with: +After both pipelines complete, the DK automatically triggers the corresponding GitHub Actions workflows: -- **version**: the full tag name (e.g. `@vtex/ads-core@0.5.2`) -- **CA_TOKEN** and **CA_OWNER**: provided by the pipeline run output -- **environment**: `production` (default) or `beta` +- **Actions → Publish ads-core to npm** (`publish-core.yml`) +- **Actions → Publish ads-react to npm** (`publish-react.yml`) -> **Prerequisite:** each package must have a [NPM Trusted Publisher](https://docs.npmjs.com/trusted-publishers) configured on npmjs.com pointing to this repo and the `publish-npm.yml` workflow. This is a one-time setup per package. +Each workflow reads the version from its own `package.json`, downloads the tarball from CodeArtifact, and publishes it to npmjs. The `CA_TOKEN` and `CA_OWNER` inputs are filled automatically by DK. You can also trigger them manually if needed. + +> **Prerequisite:** each package must have a [NPM Trusted Publisher](https://docs.npmjs.com/trusted-publishers) configured on npmjs.com pointing to this repo — `publish-core.yml` for `@vtex/ads-core` and `publish-react.yml` for `@vtex/ads-react`. This is a one-time setup per package. diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 551944b..12ee774 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @vtex/ads-react +## 0.5.2 + +### Patch Changes + +- Version bump to sync with @vtex/ads-core@0.5.2 + ## 0.5.1 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 0f846a0..dc88142 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,7 +1,7 @@ { "name": "@vtex/ads-react", "type": "module", - "version": "0.5.1", + "version": "0.5.2", "main": "dist/cjs/index.cjs.js", "module": "dist/esm/index.js", "types": "dist/esm/index.d.ts",