|
| 1 | +name: Publish from CodeArtifact to npm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Package Version (ex: 1.2.3)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + environment: |
| 11 | + description: 'Environment (production or beta)' |
| 12 | + required: true |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - production |
| 16 | + - beta |
| 17 | + CA_TOKEN: |
| 18 | + description: 'CodeArtifact Token' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + CA_OWNER: |
| 22 | + description: 'CodeArtifact Domain Owner' |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + id-token: write # required for Trusted Publishing |
| 29 | + |
| 30 | +env: |
| 31 | + CODEARTIFACT_DOMAIN: main |
| 32 | + CODEARTIFACT_REPOSITORY: internal-npm |
| 33 | + NPM_PACKAGE_NAME: "@vtex/api" |
| 34 | + AWS_REGION: us-east-1 |
| 35 | + |
| 36 | +jobs: |
| 37 | + publish: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Setup Node |
| 44 | + uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: '22' |
| 47 | + |
| 48 | + - name: Configure npm for CodeArtifact |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | +
|
| 52 | + export CODEARTIFACT_TOKEN="${{ github.event.inputs.CA_TOKEN}}" |
| 53 | + echo "::add-mask::${{ github.event.inputs.CA_TOKEN}}" |
| 54 | + export CODEARTIFACT_DOMAIN_OWNER="${{ github.event.inputs.CA_OWNER}}" |
| 55 | + echo "::add-mask::${{ github.event.inputs.CA_OWNER}}" |
| 56 | +
|
| 57 | + if [ -z "${CODEARTIFACT_TOKEN:-}" ]; then |
| 58 | + echo "CODEARTIFACT_TOKEN not set"; exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + CODEARTIFACT_URL="https://${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/" |
| 62 | +
|
| 63 | + echo "Configuring npm to use ${CODEARTIFACT_URL}" |
| 64 | +
|
| 65 | + npm config set registry "${CODEARTIFACT_URL}" |
| 66 | + npm config set "//${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${AWS_REGION}.amazonaws.com/npm/${CODEARTIFACT_REPOSITORY}/:_authToken" "${CODEARTIFACT_TOKEN}" |
| 67 | +
|
| 68 | + - name: Download package from CodeArtifact |
| 69 | + run: | |
| 70 | + set -euo pipefail |
| 71 | + VERSION="${{ github.event.inputs.version }}" |
| 72 | +
|
| 73 | + echo "Downloading ${NPM_PACKAGE_NAME}@${VERSION} from CodeArtifact..." |
| 74 | + npm pack "${NPM_PACKAGE_NAME}@${VERSION}" |
| 75 | +
|
| 76 | + echo "Generated files:" |
| 77 | + ls -1 *.tgz |
| 78 | +
|
| 79 | + - name: Set npm registry to npmjs |
| 80 | + run: | |
| 81 | + set -euo pipefail |
| 82 | + npm config set registry https://registry.npmjs.org |
| 83 | + npm install -g npm@latest |
| 84 | +
|
| 85 | + - name: Publish tarball to npmjs |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | +
|
| 89 | + TARBALL=$(ls -1 *.tgz | head -n 1) |
| 90 | + TAG_FLAG="" |
| 91 | + if [ "${{ github.event.inputs.environment }}" = "beta" ]; then |
| 92 | + TAG_FLAG="--tag beta" |
| 93 | + fi |
| 94 | + echo "Publishing ${TARBALL} to npmjs..." |
| 95 | + npm publish "${TARBALL}" --provenance --access public ${TAG_FLAG} |
0 commit comments