name: parcel3 on: workflow_dispatch: inputs: version: description: 'Version to publish, e.g. 3.0.0-alpha.1' required: true type: string publish: description: 'Publish to npm once every target has built successfully' required: false default: false type: boolean tag: description: 'npm dist-tag for every package published. Defaults to the prerelease identifier (e.g. alpha), or latest for a stable version' required: false type: string permissions: contents: read env: NODE_VERSION: '24' ZIG_VERSION: '0.14.0' jobs: # Publishes Parcel 3 twice, from the same platform packages: as `parcel`, and # as `@parcel/parcel3` with a `parcel3` command, so that it can be installed # beside Parcel 2 (see .github/scripts/parcel3/pack-main.mjs). # # The target list lives in .github/scripts/native-plugin/targets.mjs, shared # with the plugin workflow: Parcel and the plugins it loads are built for the # same targets, so adding one should mean editing one file. matrix: name: Read targets runs-on: ubuntu-latest outputs: matrix: ${{ steps.matrix.outputs.matrix }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - id: matrix run: node .github/scripts/parcel3/matrix.mjs build: name: ${{ matrix.target }} needs: matrix runs-on: ${{ matrix.runner }} strategy: # One broken target should still report the others, rather than cancelling # them and hiding whether they would have built. fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: yarn # crates/plugin-js builds its Node builtin shims from node_modules at # compile time, so the workspace has to be installed before cargo runs. - run: yarn --immutable - uses: dtolnay/rust-toolchain@master with: toolchain: stable targets: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2 with: shared-key: parcel3-${{ matrix.target }} # crates/parcel-plugin-abi generates its FFI bindings with bindgen, which # needs libclang on the machine doing the building - including when that # machine is cross compiling. - name: Install libclang if: ${{ runner.os == 'Linux' }} run: sudo apt-get update && sudo apt-get install -y libclang-dev # LLVM ships with the Windows runner image, but bindgen does not look there # on its own. Set through the environment file rather than on the build # step, because clang-sys searches only this directory when the variable is # set at all - an empty value on the other runners would break the search. - name: Point bindgen at LLVM if: ${{ runner.os == 'Windows' }} shell: bash run: echo 'LIBCLANG_PATH=C:\Program Files\LLVM\bin' >> "$GITHUB_ENV" - name: Install Zig if: ${{ matrix.builder == 'zig' }} uses: goto-bus-stop/setup-zig@v1 with: version: ${{ env.ZIG_VERSION }} - name: Install cargo-zigbuild if: ${{ matrix.builder == 'zig' }} uses: taiki-e/install-action@v2 env: GITHUB_TOKEN: ${{ github.token }} with: tool: cargo-zigbuild - name: Build shell: bash env: TARGET: ${{ matrix.target }} ZIG_TARGET: ${{ matrix.zigTarget }} BUILDER: ${{ matrix.builder }} EXTRA_RUSTFLAGS: ${{ matrix.rustflags }} # Compiled in as the version plugins' engines.parcel ranges are checked against. PARCEL_VERSION: ${{ inputs.version }} # Matches the deployment target the rest of Parcel's macOS builds use. MACOSX_DEPLOYMENT_TARGET: ${{ runner.os == 'macOS' && '11.0' || '' }} # Lets the stable compiler accept the -Z flags below. Only release # builds opt in; the source itself never uses unstable features. RUSTC_BOOTSTRAP: '1' run: | set -euo pipefail # Without this, every crate that uses a generic function compiles its # own copy, and fat LTO never merges them: ~5MB of duplicate code. # Debug builds already do this by default. UNSTABLE_RUSTFLAGS='-Zshare-generics=y' # Setting RUSTFLAGS at all shadows the config in .cargo/config.toml, so # only export it for the targets that actually need extra flags. The # per-target variable is joined with the config instead. if [ -n "$EXTRA_RUSTFLAGS" ]; then export RUSTFLAGS="$EXTRA_RUSTFLAGS $UNSTABLE_RUSTFLAGS" echo "RUSTFLAGS=$RUSTFLAGS" else TARGET_VAR="CARGO_TARGET_$(echo "$TARGET" | tr 'a-z-' 'A-Z_')_RUSTFLAGS" export "$TARGET_VAR=$UNSTABLE_RUSTFLAGS" echo "$TARGET_VAR=$UNSTABLE_RUSTFLAGS" fi # zig cc explicitly disables evex512 for the baseline x86_64 CPU, which # breaks AVX-512 functions declared with target attributes, e.g. in # libdeflate (https://github.com/ziglang/zig/issues/20414). evex512 # only permits 512-bit vectors where AVX-512 is already enabled, so # this does not raise the baseline CPU requirement. if [ "$BUILDER" = 'zig' ] && [[ "$TARGET" == x86_64-* ]]; then export "CFLAGS_${TARGET//-/_}=-mevex512" fi if [ "$BUILDER" = 'zig' ]; then cargo zigbuild --release --target "$ZIG_TARGET" -p parcel --bin parcel else cargo build --release --target "$TARGET" -p parcel --bin parcel fi - name: Pack ${{ matrix.package }} shell: bash env: TARGET: ${{ matrix.target }} PACKAGE: ${{ matrix.package }} VERSION: ${{ inputs.version }} PKG_OS: ${{ matrix.os }} PKG_CPU: ${{ matrix.cpu }} PKG_LIBC: ${{ matrix.libc }} run: | set -euo pipefail # cargo-zigbuild encodes the minimum glibc version in the target it is # given, but still writes to the plain triple's directory. BINARY="target/$TARGET/release/parcel" if [ "$PKG_OS" = 'win32' ]; then BINARY="$BINARY.exe" fi node .github/scripts/parcel3/pack-platform.mjs \ --package "$PACKAGE" \ --version "$VERSION" \ --binary "$BINARY" \ --os "$PKG_OS" \ --cpu "$PKG_CPU" \ --libc "$PKG_LIBC" \ --target "$TARGET" \ --out "$RUNNER_TEMP/artifacts" - uses: actions/upload-artifact@v4 with: name: parcel3-platform-${{ matrix.target }} path: ${{ runner.temp }}/artifacts/* if-no-files-found: error pack: name: Pack parcel and @parcel/parcel3 needs: build runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} # Merging is safe: the files inside are named after the target, so they are # unique across the matrix. - name: Download platform packages uses: actions/download-artifact@v4 with: pattern: parcel3-platform-* path: ${{ runner.temp }}/artifacts merge-multiple: true - name: Pack parcel and @parcel/parcel3 run: | node .github/scripts/parcel3/pack-main.mjs \ --version "${{ inputs.version }}" \ --artifacts "$RUNNER_TEMP/artifacts" \ --out "$RUNNER_TEMP/main" - uses: actions/upload-artifact@v4 with: name: parcel3-main path: ${{ runner.temp }}/main/*.tgz if-no-files-found: error # The pure JS workspace packages (@parcel/plugin, the transformers, ...) are # versioned, packed and published with Yarn. @parcel/parcel3 is private: the # parcel and @parcel/parcel3 npm packages are assembled from the native builds # by the jobs above instead. pack-js: name: Pack JS packages runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: yarn - run: yarn --immutable - run: yarn build - run: yarn check-ts - name: Set version env: VERSION: ${{ inputs.version }} # Bumping the workspace versions rewrites the lockfile, which Yarn # otherwise refuses to do on CI. YARN_ENABLE_IMMUTABLE_INSTALLS: 'false' run: yarn workspaces foreach --all --no-private --exclude @parcel/parcel3 version "$VERSION" - name: Pack run: yarn workspaces foreach --all --no-private --exclude @parcel/parcel3 pack --out "$RUNNER_TEMP/js/%s-%v.tgz" - uses: actions/upload-artifact@v4 with: name: parcel3-js path: ${{ runner.temp }}/js/*.tgz if-no-files-found: error publish-js: name: Publish JS packages to npm if: ${{ inputs.publish }} # Also wait for the native packages and plugins, so nothing is published # unless the whole release built. needs: [pack, pack-js, plugins] runs-on: ubuntu-latest permissions: contents: read id-token: write # npm trusted publishing steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} registry-url: 'https://registry.npmjs.org' # Trusted publishing, and the provenance attestation it generates, needs # npm 11.5.1 or later. - name: Update npm run: npm install -g npm@latest # Published with npm rather than `yarn npm publish`, whose Sigstore client # fails the publish whenever a retried transparency log upload finds its # first attempt already recorded (409). yarn pack has already replaced the # workspace: ranges with real versions. - name: Download JS packages uses: actions/download-artifact@v4 with: name: parcel3-js path: ${{ runner.temp }}/js # Ordered by dependencies, so @parcel/plugin is published before the # packages that depend on it, and skipping versions already on npm, so a # failed run can be retried. A prerelease never becomes latest (see # dist-tag.mjs): these package names were used by Parcel 2, whose users # would otherwise get v3. - name: Publish env: TAG: ${{ inputs.tag }} run: node .github/scripts/native-plugin/publish.mjs --tag "$TAG" "$RUNNER_TEMP"/js/*.tgz # The Rust plugin SDK is versioned on its own rather than in lockstep with # Parcel, so most releases leave it unchanged. Publishes only when the # version in crates/parcel-plugin/Cargo.toml is not on crates.io yet. publish-crate: name: Publish parcel-plugin to crates.io if: ${{ inputs.publish }} # Like the npm packages, nothing is published unless the whole release built. needs: [pack, pack-js, plugins] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: stable - name: Check crates.io id: check run: | set -euo pipefail CRATE_VERSION="$(cargo metadata --no-deps --format-version 1 \ | jq -r '.packages[] | select(.name == "parcel-plugin") | .version')" # crates.io rejects API requests without a User-Agent. STATUS="$(curl -s -o /dev/null -w '%{http_code}' \ -A 'parcel-release (https://github.com/parcel-bundler/parcel)' \ "https://crates.io/api/v1/crates/parcel-plugin/$CRATE_VERSION")" case "$STATUS" in 200) echo "parcel-plugin $CRATE_VERSION is already on crates.io" echo "publish=false" >> "$GITHUB_OUTPUT" ;; 404) echo "Publishing parcel-plugin $CRATE_VERSION" echo "publish=true" >> "$GITHUB_OUTPUT" ;; *) echo "::error::Unexpected HTTP $STATUS checking crates.io for parcel-plugin $CRATE_VERSION" exit 1 ;; esac - name: Publish if: ${{ steps.check.outputs.publish == 'true' }} env: CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} run: cargo publish -p parcel-plugin # Native plugins that live in this repo but are installed separately, so # that projects without those file types do not download them. Released in # lockstep with Parcel, through the same workflow third-party native plugins # use (.github/scripts/native-plugin/README.md). # # Waits for Parcel's own builds so that a broken target stops the plugins # being published too, rather than leaving half a release on npm. plugins: name: Plugins needs: build permissions: contents: read id-token: write # npm trusted publishing uses: ./.github/workflows/native-plugin.yml with: paths: | crates/sass version: ${{ inputs.version }} tag: ${{ inputs.tag }} publish: ${{ inputs.publish }} # The workspace builds with panic = 'abort', which would turn a panic in a # plugin into a crash of the whole build. The SDK catches panics and # reports them as diagnostics, but only if they unwind. cargo-args: --config profile.release.panic="unwind" publish: name: Publish to npm if: ${{ inputs.publish }} needs: [pack, plugins] runs-on: ubuntu-latest permissions: contents: read id-token: write # npm trusted publishing steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} registry-url: 'https://registry.npmjs.org' # Trusted publishing, and the provenance attestation it generates, needs # npm 11.5.1 or later. - name: Update npm run: npm install -g npm@latest - name: Download platform packages uses: actions/download-artifact@v4 with: pattern: parcel3-platform-* path: ${{ runner.temp }}/artifacts merge-multiple: true - name: Download parcel and @parcel/parcel3 uses: actions/download-artifact@v4 with: name: parcel3-main path: ${{ runner.temp }}/main # Platform packages first: the optionalDependencies of parcel and # @parcel/parcel3 pin exact versions of them, so neither must ever be # resolvable before they are. - name: Publish platform packages env: TAG: ${{ inputs.tag }} run: node .github/scripts/native-plugin/publish.mjs --tag "$TAG" "$RUNNER_TEMP"/artifacts/*.tgz - name: Publish parcel and @parcel/parcel3 env: TAG: ${{ inputs.tag }} run: node .github/scripts/native-plugin/publish.mjs --tag "$TAG" "$RUNNER_TEMP"/main/*.tgz # Tags the commit the release was built from once everything is on npm, so # the SDKs installed from git can depend on a release rather than a branch: # v for Cargo, SwiftPM and the native plugin workflow, and # plugin-go/v for the Go module, which lives in a subdirectory. git-tag: name: Tag release if: ${{ inputs.publish }} needs: [publish, publish-js] runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v4 # A retried run finds its own tags already there. A tag on a different # commit means the version was already released from elsewhere. - name: Push tags env: VERSION: ${{ inputs.version }} run: | set -euo pipefail for TAG in "v$VERSION" "plugin-go/v$VERSION"; do EXISTING="$(git ls-remote --tags origin "refs/tags/$TAG" | cut -f1)" if [ -z "$EXISTING" ]; then git tag "$TAG" "$GITHUB_SHA" git push origin "refs/tags/$TAG" elif [ "$EXISTING" = "$GITHUB_SHA" ]; then echo "$TAG already points at $GITHUB_SHA" else echo "::error::$TAG already exists at $EXISTING, not $GITHUB_SHA" exit 1 fi done