|
| 1 | +name: Publish Design System |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to publish (e.g., 1.0.1)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + dist_tag: |
| 11 | + description: 'npm dist-tag to use' |
| 12 | + required: true |
| 13 | + default: latest |
| 14 | + type: string |
| 15 | + ref: |
| 16 | + description: 'Git ref to checkout (commit SHA, tag, or branch)' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + workflow_call: |
| 20 | + inputs: |
| 21 | + version: |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + dist_tag: |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + default: latest |
| 28 | + ref: |
| 29 | + required: false |
| 30 | + type: string |
| 31 | + secrets: |
| 32 | + NPM_TOKEN: |
| 33 | + required: true |
| 34 | + |
| 35 | +concurrency: |
| 36 | + group: publish-design-system-${{ inputs.version }} |
| 37 | + cancel-in-progress: false |
| 38 | + |
| 39 | +jobs: |
| 40 | + publish_design_system: |
| 41 | + name: Publish @comfyorg/design-system |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + steps: |
| 46 | + - name: Determine ref to checkout |
| 47 | + id: resolve_ref |
| 48 | + env: |
| 49 | + REF: ${{ inputs.ref }} |
| 50 | + DEFAULT_REF: ${{ github.ref_name }} |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | + if [ -z "$REF" ]; then |
| 55 | + REF="$DEFAULT_REF" |
| 56 | + fi |
| 57 | + if ! git check-ref-format --allow-onelevel "$REF"; then |
| 58 | + echo "::error title=Invalid ref::Ref '$REF' fails git check-ref-format validation." >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + echo "ref=$REF" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Checkout repository |
| 64 | + uses: actions/checkout@v6 |
| 65 | + with: |
| 66 | + ref: ${{ steps.resolve_ref.outputs.ref }} |
| 67 | + fetch-depth: 1 |
| 68 | + persist-credentials: false |
| 69 | + |
| 70 | + - name: Install pnpm |
| 71 | + uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0 |
| 72 | + |
| 73 | + - name: Setup Node.js |
| 74 | + uses: actions/setup-node@v6 |
| 75 | + with: |
| 76 | + node-version-file: '.nvmrc' |
| 77 | + cache: 'pnpm' |
| 78 | + registry-url: https://registry.npmjs.org |
| 79 | + |
| 80 | + - name: Install dependencies |
| 81 | + run: pnpm install --frozen-lockfile --ignore-scripts |
| 82 | + env: |
| 83 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' |
| 84 | + |
| 85 | + - name: Validate dist-tag |
| 86 | + env: |
| 87 | + DIST_TAG: ${{ inputs.dist_tag }} |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + set -euo pipefail |
| 91 | + if [ -z "$DIST_TAG" ]; then |
| 92 | + echo "::error title=Invalid dist-tag::dist_tag must not be empty" >&2 |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + if ! node -e "process.exit(require('semver').validRange(process.argv[1]) ? 1 : 0)" "$DIST_TAG"; then |
| 96 | + echo "::error title=Invalid dist-tag::Tag '$DIST_TAG' must not parse as a valid SemVer version or range (npm rejects such tags)" >&2 |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Verify package |
| 101 | + id: pkg |
| 102 | + env: |
| 103 | + INPUT_VERSION: ${{ inputs.version }} |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + set -euo pipefail |
| 107 | + PACKAGE_JSON=packages/design-system/package.json |
| 108 | + NAME=$(node -p "require('./${PACKAGE_JSON}').name") |
| 109 | + VERSION=$(node -p "require('./${PACKAGE_JSON}').version") |
| 110 | + if [ "$NAME" != "@comfyorg/design-system" ]; then |
| 111 | + echo "::error title=Package name mismatch::${PACKAGE_JSON} name '$NAME' is not '@comfyorg/design-system'" >&2 |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + if [ "$VERSION" != "$INPUT_VERSION" ]; then |
| 115 | + echo "::error title=Version mismatch::${PACKAGE_JSON} version $VERSION does not match input $INPUT_VERSION" >&2 |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + echo "name=$NAME" >> "$GITHUB_OUTPUT" |
| 119 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 120 | +
|
| 121 | + - name: Check if version already on npm |
| 122 | + id: check_npm |
| 123 | + env: |
| 124 | + NAME: ${{ steps.pkg.outputs.name }} |
| 125 | + VER: ${{ steps.pkg.outputs.version }} |
| 126 | + shell: bash |
| 127 | + run: | |
| 128 | + set -euo pipefail |
| 129 | + STATUS=0 |
| 130 | + OUTPUT=$(npm view "${NAME}@${VER}" --json 2>&1) || STATUS=$? |
| 131 | + if [ "$STATUS" -eq 0 ]; then |
| 132 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 133 | + echo "::warning title=Already published::${NAME}@${VER} already exists on npm. Skipping publish." |
| 134 | + else |
| 135 | + if echo "$OUTPUT" | grep -q "E404"; then |
| 136 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 137 | + else |
| 138 | + echo "::error title=Registry lookup failed::$OUTPUT" >&2 |
| 139 | + exit "$STATUS" |
| 140 | + fi |
| 141 | + fi |
| 142 | +
|
| 143 | + - name: Publish package |
| 144 | + if: steps.check_npm.outputs.exists == 'false' |
| 145 | + env: |
| 146 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 147 | + DIST_TAG: ${{ inputs.dist_tag }} |
| 148 | + run: pnpm publish --access public --tag "$DIST_TAG" --no-git-checks --ignore-scripts |
| 149 | + working-directory: packages/design-system |
0 commit comments