|
| 1 | +name: "publish: datatype parser" |
| 2 | + |
| 3 | +# Independent publish + release for the standalone @clickhouse/datatype-parser |
| 4 | +# package (the data-type string parser). It is NOT part of the npm workspace |
| 5 | +# lockstep release driven by publish.yml — it carries its own version in |
| 6 | +# packages/datatype-parser/package.json and ships on its own cadence. Triggered |
| 7 | +# manually, and — like publish.yml — must be dispatched from the `release` |
| 8 | +# branch: the npm-publish environment is protected so only that branch may |
| 9 | +# deploy (the repo's human-in-the-loop release gate). Dispatches from any other |
| 10 | +# ref are skipped by the job-level `if` guard below. |
| 11 | +# |
| 12 | +# The release branch is itself protected, so the unit suite is not re-run here. |
| 13 | +# The `publish` job instead builds, packs the tarball, installs that exact |
| 14 | +# tarball into a throwaway project and smoke-tests its imports, and only then |
| 15 | +# publishes the same tarball with the "latest" tag (npm OIDC + provenance) and |
| 16 | +# pushes a matching git tag. The `e2e` job then repeats the smoke test against |
| 17 | +# the freshly published version on the registry across the supported Node |
| 18 | +# versions. |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + id-token: write # Required for npm OIDC authentication and provenance |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: ${{ github.workflow }} |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | +on: |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +jobs: |
| 32 | + publish: |
| 33 | + # The npm-publish environment only permits the release branch to deploy; |
| 34 | + # skip cleanly on any other ref instead of failing the protection check. |
| 35 | + if: github.ref == 'refs/heads/release' |
| 36 | + runs-on: ubuntu-latest |
| 37 | + timeout-minutes: 10 |
| 38 | + environment: npm-publish |
| 39 | + permissions: |
| 40 | + contents: write # Required to push the release git tag |
| 41 | + id-token: write # Required for npm OIDC authentication and provenance |
| 42 | + defaults: |
| 43 | + run: |
| 44 | + working-directory: packages/datatype-parser |
| 45 | + outputs: |
| 46 | + version: ${{ steps.version.outputs.version }} |
| 47 | + steps: |
| 48 | + - name: Checkout repository |
| 49 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 50 | + |
| 51 | + - name: Setup Node.js |
| 52 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 53 | + with: |
| 54 | + node-version: 24 |
| 55 | + registry-url: "https://registry.npmjs.org" |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + run: npm ci |
| 59 | + |
| 60 | + - name: Build |
| 61 | + run: npm run build |
| 62 | + |
| 63 | + - name: Get the release version |
| 64 | + id: version |
| 65 | + run: | |
| 66 | + VERSION=$(node -p "require('./package.json').version") |
| 67 | + echo "Publishing @clickhouse/datatype-parser@$VERSION" |
| 68 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 69 | +
|
| 70 | + - name: Pack the tarball |
| 71 | + id: pack |
| 72 | + # prepack rebuilds dist before packing. |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | + TARBALL=$(npm pack --pack-destination "$RUNNER_TEMP" | tail -1) |
| 76 | + echo "Packed: $TARBALL" |
| 77 | + echo "tarball=$RUNNER_TEMP/$TARBALL" >> "$GITHUB_OUTPUT" |
| 78 | +
|
| 79 | + - name: Pre-publish smoke test (install the packed tarball) |
| 80 | + env: |
| 81 | + TARBALL: ${{ steps.pack.outputs.tarball }} |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + work="$(mktemp -d)" |
| 85 | + cd "$work" |
| 86 | + npm init -y >/dev/null 2>&1 |
| 87 | + npm install "$TARBALL" |
| 88 | + # Verify the main barrel entry resolves and exposes the parser, from |
| 89 | + # the exact artifact we are about to publish. |
| 90 | + node --input-type=module -e " |
| 91 | + import * as dt from '@clickhouse/datatype-parser'; |
| 92 | + if (typeof dt.parseDataType !== 'function') throw new Error('parseDataType missing from main export'); |
| 93 | + console.log('OK: packed tarball imports cleanly'); |
| 94 | + " |
| 95 | +
|
| 96 | + - name: Publish to npm |
| 97 | + # Publish the exact tarball that passed the pre-publish smoke test. |
| 98 | + env: |
| 99 | + TARBALL: ${{ steps.pack.outputs.tarball }} |
| 100 | + run: npm publish "$TARBALL" --access public --provenance |
| 101 | + |
| 102 | + - name: Create and push release git tag |
| 103 | + env: |
| 104 | + RELEASE_TAG: datatype-parser-v${{ steps.version.outputs.version }} |
| 105 | + RELEASE_VERSION: ${{ steps.version.outputs.version }} |
| 106 | + run: | |
| 107 | + if git ls-remote --exit-code --tags origin "refs/tags/${RELEASE_TAG}" >/dev/null 2>&1; then |
| 108 | + echo "Tag ${RELEASE_TAG} already exists on origin; skipping." |
| 109 | + exit 0 |
| 110 | + fi |
| 111 | + git config user.name "github-actions[bot]" |
| 112 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 113 | + git tag -a "${RELEASE_TAG}" -m "Release @clickhouse/datatype-parser ${RELEASE_VERSION}" |
| 114 | + git push origin "refs/tags/${RELEASE_TAG}" |
| 115 | +
|
| 116 | + e2e: |
| 117 | + name: e2e (node ${{ matrix.node }}) |
| 118 | + needs: publish |
| 119 | + if: needs.publish.result == 'success' |
| 120 | + runs-on: ubuntu-latest |
| 121 | + timeout-minutes: 10 |
| 122 | + strategy: |
| 123 | + fail-fast: true |
| 124 | + matrix: |
| 125 | + node: [20, 22, 24] |
| 126 | + env: |
| 127 | + PUBLISHED_VERSION: ${{ needs.publish.outputs.version }} |
| 128 | + steps: |
| 129 | + - name: Setup NodeJS ${{ matrix.node }} |
| 130 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 131 | + with: |
| 132 | + node-version: ${{ matrix.node }} |
| 133 | + registry-url: "https://registry.npmjs.org" |
| 134 | + |
| 135 | + - name: Wait for @clickhouse/datatype-parser@${{ needs.publish.outputs.version }} on npm |
| 136 | + run: | |
| 137 | + set -euo pipefail |
| 138 | + if [ -z "${PUBLISHED_VERSION}" ]; then |
| 139 | + echo "PUBLISHED_VERSION is empty; cannot wait for npm publication." >&2 |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | + pkg="@clickhouse/datatype-parser" |
| 143 | + # Poll the registry for up to ~5 minutes. New versions usually surface |
| 144 | + # in seconds, but the registry CDN can lag. |
| 145 | + max_attempts=60 |
| 146 | + sleep_seconds=5 |
| 147 | + attempt=1 |
| 148 | + echo "Waiting for ${pkg}@${PUBLISHED_VERSION} to be available on npm..." |
| 149 | + while true; do |
| 150 | + if npm view "${pkg}@${PUBLISHED_VERSION}" version >/dev/null 2>&1; then |
| 151 | + echo " ${pkg}@${PUBLISHED_VERSION} is available." |
| 152 | + break |
| 153 | + fi |
| 154 | + if [ "$attempt" -ge "$max_attempts" ]; then |
| 155 | + echo "Timed out waiting for ${pkg}@${PUBLISHED_VERSION} on npm" >&2 |
| 156 | + exit 1 |
| 157 | + fi |
| 158 | + echo " attempt ${attempt}/${max_attempts}: not available yet, sleeping ${sleep_seconds}s..." |
| 159 | + attempt=$((attempt + 1)) |
| 160 | + sleep "$sleep_seconds" |
| 161 | + done |
| 162 | +
|
| 163 | + - name: Install and import the published package |
| 164 | + run: | |
| 165 | + set -euo pipefail |
| 166 | + work="$(mktemp -d)" |
| 167 | + cd "$work" |
| 168 | + npm init -y >/dev/null 2>&1 |
| 169 | + npm install "@clickhouse/datatype-parser@${PUBLISHED_VERSION}" |
| 170 | + # Verify the main barrel entry resolves and exposes the parser to a |
| 171 | + # downstream consumer. |
| 172 | + node --input-type=module -e " |
| 173 | + import * as dt from '@clickhouse/datatype-parser'; |
| 174 | + if (typeof dt.parseDataType !== 'function') throw new Error('parseDataType missing from main export'); |
| 175 | + console.log('OK: @clickhouse/datatype-parser@${PUBLISHED_VERSION} imports cleanly'); |
| 176 | + " |
0 commit comments