|
| 1 | +name: Publish Desktop UI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to publish (e.g., 1.2.3)' |
| 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-desktop-ui-${{ github.workflow }}-${{ inputs.version }}-${{ inputs.dist_tag }} |
| 37 | + cancel-in-progress: false |
| 38 | + |
| 39 | +jobs: |
| 40 | + publish_desktop_ui: |
| 41 | + name: Publish @comfyorg/desktop-ui |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + env: |
| 46 | + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' |
| 47 | + steps: |
| 48 | + - name: Validate inputs |
| 49 | + env: |
| 50 | + VERSION: ${{ inputs.version }} |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | + SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$' |
| 55 | + if [[ ! "$VERSION" =~ $SEMVER_REGEX ]]; then |
| 56 | + echo "::error title=Invalid version::Version '$VERSION' must follow semantic versioning (x.y.z[-suffix][+build])" >&2 |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Determine ref to checkout |
| 61 | + id: resolve_ref |
| 62 | + env: |
| 63 | + REF: ${{ inputs.ref }} |
| 64 | + VERSION: ${{ inputs.version }} |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + if [ -n "$REF" ]; then |
| 69 | + if ! git check-ref-format --allow-onelevel "$REF"; then |
| 70 | + echo "::error title=Invalid ref::Ref '$REF' fails git check-ref-format validation." >&2 |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + echo "ref=$REF" >> "$GITHUB_OUTPUT" |
| 74 | + else |
| 75 | + echo "ref=refs/tags/v$VERSION" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Checkout repository |
| 79 | + uses: actions/checkout@v5 |
| 80 | + with: |
| 81 | + ref: ${{ steps.resolve_ref.outputs.ref }} |
| 82 | + fetch-depth: 1 |
| 83 | + persist-credentials: false |
| 84 | + |
| 85 | + - name: Install pnpm |
| 86 | + uses: pnpm/action-setup@v4 |
| 87 | + with: |
| 88 | + version: 10 |
| 89 | + |
| 90 | + - name: Setup Node.js |
| 91 | + uses: actions/setup-node@v5 |
| 92 | + with: |
| 93 | + node-version: '24.x' |
| 94 | + cache: 'pnpm' |
| 95 | + registry-url: https://registry.npmjs.org |
| 96 | + |
| 97 | + - name: Install dependencies |
| 98 | + run: pnpm install --frozen-lockfile --ignore-scripts |
| 99 | + |
| 100 | + - name: Build Desktop UI |
| 101 | + run: pnpm build:desktop |
| 102 | + |
| 103 | + - name: Prepare npm package |
| 104 | + id: pkg |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + APP_PKG=apps/desktop-ui/package.json |
| 109 | + ROOT_PKG=package.json |
| 110 | +
|
| 111 | + NAME=$(jq -r .name "$APP_PKG") |
| 112 | + APP_VERSION=$(jq -r .version "$APP_PKG") |
| 113 | + ROOT_LICENSE=$(jq -r .license "$ROOT_PKG") |
| 114 | + REPO=$(jq -r .repository "$ROOT_PKG") |
| 115 | +
|
| 116 | + if [ -z "$NAME" ] || [ "$NAME" = "null" ]; then |
| 117 | + echo "::error title=Missing name::apps/desktop-ui/package.json is missing 'name'" >&2 |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | +
|
| 121 | + INPUT_VERSION="${{ inputs.version }}" |
| 122 | + if [ "$APP_VERSION" != "$INPUT_VERSION" ]; then |
| 123 | + echo "::error title=Version mismatch::apps/desktop-ui version $APP_VERSION does not match input $INPUT_VERSION" >&2 |
| 124 | + exit 1 |
| 125 | + fi |
| 126 | +
|
| 127 | + if [ ! -d apps/desktop-ui/dist ]; then |
| 128 | + echo "::error title=Missing build::apps/desktop-ui/dist not found. Did build succeed?" >&2 |
| 129 | + exit 1 |
| 130 | + fi |
| 131 | +
|
| 132 | + PUBLISH_DIR=apps/desktop-ui/.npm-publish |
| 133 | + rm -rf "$PUBLISH_DIR" |
| 134 | + mkdir -p "$PUBLISH_DIR" |
| 135 | + cp -R apps/desktop-ui/dist "$PUBLISH_DIR/dist" |
| 136 | +
|
| 137 | + INPUT_VERSION="${{ inputs.version }}" |
| 138 | + jq -n \ |
| 139 | + --arg name "$NAME" \ |
| 140 | + --arg version "$INPUT_VERSION" \ |
| 141 | + --arg description "Static assets for the ComfyUI Desktop UI" \ |
| 142 | + --arg license "$ROOT_LICENSE" \ |
| 143 | + --arg repository "$REPO" \ |
| 144 | + '{ |
| 145 | + name: $name, |
| 146 | + version: $version, |
| 147 | + description: $description, |
| 148 | + license: $license, |
| 149 | + repository: $repository, |
| 150 | + type: "module", |
| 151 | + private: false, |
| 152 | + files: ["dist"], |
| 153 | + publishConfig: { access: "public" } |
| 154 | + }' > "$PUBLISH_DIR/package.json" |
| 155 | +
|
| 156 | + if [ -f apps/desktop-ui/README.md ]; then |
| 157 | + cp apps/desktop-ui/README.md "$PUBLISH_DIR/README.md" |
| 158 | + fi |
| 159 | +
|
| 160 | + echo "publish_dir=$PUBLISH_DIR" >> "$GITHUB_OUTPUT" |
| 161 | + echo "name=$NAME" >> "$GITHUB_OUTPUT" |
| 162 | +
|
| 163 | + - name: Pack (preview only) |
| 164 | + shell: bash |
| 165 | + working-directory: ${{ steps.pkg.outputs.publish_dir }} |
| 166 | + run: | |
| 167 | + set -euo pipefail |
| 168 | + npm pack --json | tee pack-result.json |
| 169 | +
|
| 170 | + - name: Upload package tarball artifact |
| 171 | + uses: actions/upload-artifact@v4 |
| 172 | + with: |
| 173 | + name: desktop-ui-npm-tarball-${{ inputs.version }} |
| 174 | + path: ${{ steps.pkg.outputs.publish_dir }}/*.tgz |
| 175 | + if-no-files-found: error |
| 176 | + |
| 177 | + - name: Check if version already on npm |
| 178 | + id: check_npm |
| 179 | + env: |
| 180 | + NAME: ${{ steps.pkg.outputs.name }} |
| 181 | + VER: ${{ inputs.version }} |
| 182 | + shell: bash |
| 183 | + run: | |
| 184 | + set -euo pipefail |
| 185 | + STATUS=0 |
| 186 | + OUTPUT=$(npm view "${NAME}@${VER}" --json 2>&1) || STATUS=$? |
| 187 | + if [ "$STATUS" -eq 0 ]; then |
| 188 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 189 | + echo "::warning title=Already published::${NAME}@${VER} already exists on npm. Skipping publish." |
| 190 | + else |
| 191 | + if echo "$OUTPUT" | grep -q "E404"; then |
| 192 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 193 | + else |
| 194 | + echo "::error title=Registry lookup failed::$OUTPUT" >&2 |
| 195 | + exit "$STATUS" |
| 196 | + fi |
| 197 | + fi |
| 198 | +
|
| 199 | + - name: Publish package |
| 200 | + if: steps.check_npm.outputs.exists == 'false' |
| 201 | + env: |
| 202 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 203 | + DIST_TAG: ${{ inputs.dist_tag }} |
| 204 | + run: pnpm publish --access public --tag "$DIST_TAG" --no-git-checks --ignore-scripts |
| 205 | + working-directory: ${{ steps.pkg.outputs.publish_dir }} |
0 commit comments