|
| 1 | +name: Publish Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + npm_tag: |
| 10 | + description: 'NPM tag to publish as (overrides default)' |
| 11 | + required: false |
| 12 | + default: 'latest' |
| 13 | + dry_run: |
| 14 | + description: 'Set to "true" to skip publishing and release upload (dry run)' |
| 15 | + required: false |
| 16 | + default: 'false' |
| 17 | + |
| 18 | +env: |
| 19 | + NPM_TAG: "latest" |
| 20 | + NPM_PACKAGES: canvas,canvas-babylon,canvas-media,canvas-phaser,canvas-phaser-ce,canvas-pixi,canvas-polyfill,canvas-three,canvas-svg |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-linux: |
| 24 | + name: Build Linux native artifacts |
| 25 | + runs-on: ubuntu-22.04 |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + - name: Setup Node |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: 22 |
| 32 | + |
| 33 | + - name: Cache node modules |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: | |
| 37 | + ~/.npm |
| 38 | + ~/.cache |
| 39 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-node- |
| 42 | +
|
| 43 | + - name: Install Rust |
| 44 | + run: | |
| 45 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal |
| 46 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 47 | +
|
| 48 | + - name: Use Rust nightly |
| 49 | + run: rustup default nightly |
| 50 | + - name: Install deps (root) |
| 51 | + run: npm ci |
| 52 | + |
| 53 | + - name: Cache cargo |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: | |
| 57 | + ~/.cargo/registry |
| 58 | + ~/.cargo/git |
| 59 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 60 | + restore-keys: | |
| 61 | + ${{ runner.os }}-cargo- |
| 62 | +
|
| 63 | + - name: Build Android (make android) |
| 64 | + run: | |
| 65 | + set -e |
| 66 | + make android |
| 67 | +
|
| 68 | + - name: Copy AAR into package |
| 69 | + run: | |
| 70 | + set -e |
| 71 | + ./tools/scripts/copy-android.sh |
| 72 | +
|
| 73 | + - name: Upload Android platforms |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: android-platforms |
| 77 | + path: packages/canvas/platforms/android |
| 78 | + |
| 79 | + build-macos: |
| 80 | + name: Build macOS native artifacts |
| 81 | + runs-on: macos-14 |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v4 |
| 84 | + - name: Setup Node |
| 85 | + uses: actions/setup-node@v4 |
| 86 | + with: |
| 87 | + node-version: 22 |
| 88 | + |
| 89 | + - name: Cache node modules |
| 90 | + uses: actions/cache@v4 |
| 91 | + with: |
| 92 | + path: | |
| 93 | + ~/.npm |
| 94 | + ~/.cache |
| 95 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }} |
| 96 | + restore-keys: | |
| 97 | + ${{ runner.os }}-node- |
| 98 | +
|
| 99 | + - name: Install Rust |
| 100 | + run: | |
| 101 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal |
| 102 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 103 | +
|
| 104 | + - name: Use Rust nightly |
| 105 | + run: rustup default nightly |
| 106 | + - name: Install root deps |
| 107 | + run: npm ci |
| 108 | + |
| 109 | + - name: Cache cargo |
| 110 | + uses: actions/cache@v4 |
| 111 | + with: |
| 112 | + path: | |
| 113 | + ~/.cargo/registry |
| 114 | + ~/.cargo/git |
| 115 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 116 | + restore-keys: | |
| 117 | + ${{ runner.os }}-cargo- |
| 118 | +
|
| 119 | + - name: Build iOS (make ios) |
| 120 | + run: | |
| 121 | + set -e |
| 122 | + make ios |
| 123 | +
|
| 124 | + - name: Build and copy iOS XCFramework |
| 125 | + run: | |
| 126 | + set -e |
| 127 | + ./tools/scripts/canvas-build.sh |
| 128 | +
|
| 129 | + - name: Upload iOS platforms |
| 130 | + uses: actions/upload-artifact@v4 |
| 131 | + with: |
| 132 | + name: ios-platforms |
| 133 | + path: packages/canvas/platforms/ios |
| 134 | + |
| 135 | + publish: |
| 136 | + name: Publish to npm |
| 137 | + runs-on: ubuntu-22.04 |
| 138 | + needs: [ build-linux, build-macos ] |
| 139 | + steps: |
| 140 | + - uses: actions/checkout@v4 |
| 141 | + |
| 142 | + - name: Download linux artifacts |
| 143 | + uses: actions/download-artifact@v4 |
| 144 | + with: |
| 145 | + name: napi-linux-artifacts |
| 146 | + path: ./artifacts/linux |
| 147 | + |
| 148 | + - name: Cache cargo |
| 149 | + uses: actions/cache@v4 |
| 150 | + with: |
| 151 | + path: | |
| 152 | + ~/.cargo/registry |
| 153 | + ~/.cargo/git |
| 154 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 155 | + restore-keys: | |
| 156 | + ${{ runner.os }}-cargo- |
| 157 | +
|
| 158 | + - name: Download mac artifacts |
| 159 | + uses: actions/download-artifact@v4 |
| 160 | + with: |
| 161 | + name: napi-macos-artifacts |
| 162 | + path: ./artifacts/macos |
| 163 | + |
| 164 | + - name: Setup Node |
| 165 | + uses: actions/setup-node@v4 |
| 166 | + with: |
| 167 | + node-version: 22 |
| 168 | + |
| 169 | + - name: Install root deps |
| 170 | + run: npm ci |
| 171 | + |
| 172 | + - name: Compute NPM_VERSION |
| 173 | + run: | |
| 174 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 175 | + TAG=${GITHUB_REF#refs/tags/} |
| 176 | + echo "Detected tag $TAG" |
| 177 | + echo "NPM_VERSION=$TAG" >> $GITHUB_ENV |
| 178 | + # set NPM_TAG to prefix of tag (e.g. rc/, beta) or the tag itself |
| 179 | + echo "NPM_TAG=${TAG%%-*}" >> $GITHUB_ENV |
| 180 | + else |
| 181 | + if [ -n "${{ github.event.inputs.npm_tag }}" ]; then |
| 182 | + NT="${{ github.event.inputs.npm_tag }}" |
| 183 | + else |
| 184 | + NT="$NPM_TAG" |
| 185 | + fi |
| 186 | + echo "NPM_TAG=$NT" >> $GITHUB_ENV |
| 187 | + echo "NPM_VERSION=$(node -e \"console.log(require('./packages/canvas/package.json').version)\")-$NT-$(date +\"%Y%m%d\")-$GITHUB_RUN_ID" >> $GITHUB_ENV |
| 188 | + fi |
| 189 | +
|
| 190 | + - name: Bump packages (no git tags) |
| 191 | + run: | |
| 192 | + for pkg in packages/canvas packages/canvas-babylon packages/canvas-media packages/canvas-phaser packages/canvas-phaser-ce packages/canvas-pixi packages/canvas-polyfill packages/canvas-three packages/canvas-svg; do |
| 193 | + if [ -f "$pkg/package.json" ]; then |
| 194 | + (cd "$pkg" && npm --no-git-tag-version version "$NPM_VERSION") |
| 195 | + fi |
| 196 | + done |
| 197 | +
|
| 198 | + - name: Create project .npmrc (in-repo) |
| 199 | + if: ${{ secrets.NPM_PUBLISH_TOKEN != '' }} |
| 200 | + run: | |
| 201 | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > .npmrc |
| 202 | +
|
| 203 | + - name: Build all packages |
| 204 | + run: | |
| 205 | + npx nx run canvas:build.all |
| 206 | +
|
| 207 | + - name: Publish packages |
| 208 | + if: ${{ github.event.inputs.dry_run != 'true' }} |
| 209 | + env: |
| 210 | + NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} |
| 211 | + run: | |
| 212 | + if [ -z "$NPM_TOKEN" ]; then |
| 213 | + echo "NPM token missing. Set secrets.NPM_PUBLISH_TOKEN to proceed." && exit 1 |
| 214 | + fi |
| 215 | + echo "Publishing packages with version $NPM_VERSION and tag $NPM_TAG" |
| 216 | + npm run publish-packages --name "$NPM_PACKAGES" --verify true --version "$NPM_VERSION" --tag "$NPM_TAG" |
| 217 | +
|
| 218 | + - name: Clean up .npmrc |
| 219 | + if: always() |
| 220 | + run: rm -f .npmrc || true |
| 221 | + |
| 222 | + - name: Create release tarball |
| 223 | + if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true' |
| 224 | + run: | |
| 225 | + set -e |
| 226 | + TAR_NAME=release-${NPM_VERSION}.tar.gz |
| 227 | + tar -czf ${TAR_NAME} dist packages/canvas/platforms || true |
| 228 | + echo "Created ${TAR_NAME}" |
| 229 | +
|
| 230 | + - name: Create GitHub release and upload assets |
| 231 | + if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true' |
| 232 | + uses: softprops/action-gh-release@v1 |
| 233 | + with: |
| 234 | + files: release-${NPM_VERSION}.tar.gz |
| 235 | + env: |
| 236 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments