Skip to content

v0.1.0-preview.11

v0.1.0-preview.11 #37

Workflow file for this run

name: Publish prerelease packages on NPM
permissions:
id-token: write # Required for OIDC - https://docs.npmjs.com/trusted-publishers#supported-cicd-providers
contents: read
packages: read
on:
release:
types: [created]
jobs:
validate-release:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Validate release type
run: |
# Check if this is a prerelease
if [[ "${{ github.event.release.prerelease }}" != "true" ]]; then
echo "❌ This workflow is for prereleases only. Please use the main release workflow for production releases."
exit 1
fi
# Check if the tag matches the version in lerna.json
RELEASE_VERSION="${{ github.event.release.tag_name }}"
LERNA_VERSION=$(node -p "require('./lerna.json').version")
if [[ "v$LERNA_VERSION" != "$RELEASE_VERSION" ]]; then
echo "❌ Release tag $RELEASE_VERSION doesn't match lerna.json version v$LERNA_VERSION"
exit 1
fi
echo "✅ Release validation passed"
build-and-publish:
runs-on: ubuntu-latest
environment: production
needs: validate-release
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '18.x'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build packages
run: |
export BUILD_MODE=release
yarn build
- name: Create packages
run: yarn lerna run pack --stream
- name: Determine npm tag
id: npm-tag
run: |
RELEASE_TAG="${{ github.event.release.tag_name }}"
# Check if the release tag contains "preview"
if [[ "$RELEASE_TAG" =~ .*preview.* ]]; then
echo "tag=preview" >> "$GITHUB_OUTPUT"
echo "Using 'preview' npm tag for release $RELEASE_TAG"
else
echo "tag=alpha" >> "$GITHUB_OUTPUT"
echo "Using 'alpha' npm tag for release $RELEASE_TAG"
fi
- name: Publish core package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/core
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}
- name: Wait for core package to be available
run: |
# Get the version from lerna.json
VERSION=$(node -p "require('./lerna.json').version")
PACKAGE_NAME="@datadog/flagging-core"
echo "Waiting for $PACKAGE_NAME@$VERSION to be available on npm..."
echo "This may take a few minutes due to npm registry propagation..."
# Wait up to 5 minutes (300 seconds) with 10-second intervals
for i in {1..30}; do
echo "Attempt $i/30: Checking if $PACKAGE_NAME@$VERSION is available..."
# Try to fetch the package info from npm
if npm view "$PACKAGE_NAME@$VERSION" --json > /dev/null 2>&1; then
echo "✅ $PACKAGE_NAME@$VERSION is now available on npm!"
echo "Package details:"
npm view "$PACKAGE_NAME@$VERSION" --json
break
fi
if [ $i -eq 30 ]; then
echo "❌ Timeout: $PACKAGE_NAME@$VERSION is still not available after 5 minutes"
echo "This might indicate an issue with the npm publish or registry propagation"
exit 1
fi
echo "Package not yet available, waiting 10 seconds..."
sleep 10
done
- name: Publish browser package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/browser
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}
- name: Publish node-server package
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.ENV_NPM_TOKEN }}" > ~/.npmrc
npm config set access public
cd packages/node-server
npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.ENV_NPM_TOKEN }}