From 82acf55b4f8120aa8517c1a79337c79f52cd50f7 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 20:17:22 +0300 Subject: [PATCH 1/5] Release the Linux binaries as .deb packages too A release now carries open-java-format__amd64.deb and open-java-format__arm64.deb next to the plain Linux binaries, signed and in checksums_sha256.txt like every other file. They install /usr/bin/open-java-format and are what the apt repository, openjavaformat/apt, serves (#153); `sudo apt install ./.deb` works without it. open-java-format-native/deb/build-deb.sh packages a binary. It reads the architecture and the libc6 dependency off the binary itself: the newest GLIBC_ symbol version it asks for, 2.34 today, so that a build on a newer image cannot reach an older system and fail to start there; apt refuses the package instead. The files take the time of the tag's commit, so a re-run makes the same bytes. The release builds each package on the runner its binary came from and installs it with apt on Ubuntu 22.04 and Debian 12 before the draft release collects it. CI does the same on every pull request, under the version the binary prints. --- .github/workflows/ci.yml | 12 +++ .github/workflows/release.yml | 77 +++++++++++++++--- ...pen-java-format.release-conventions.gradle | 22 ++++- open-java-format-native/deb/build-deb.sh | 80 +++++++++++++++++++ open-java-format-native/deb/copyright | 24 ++++++ open-java-format-native/deb/test-deb.sh | 26 ++++++ 6 files changed, 227 insertions(+), 14 deletions(-) create mode 100755 open-java-format-native/deb/build-deb.sh create mode 100644 open-java-format-native/deb/copyright create mode 100755 open-java-format-native/deb/test-deb.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9476b53e7..b49210742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,6 +237,18 @@ jobs: "$binary" --replace C.java printf 'import module java.base;\n\nrecord Box(int a, int b) {}\n\nvoid main() {\n Object o = new Box(1, 2);\n if (o instanceof Box(_, _)) {\n IO.println(List.of(1));\n }\n}\n' | diff - C.java + # As release.yml packages it for the GitHub release and the apt repository, under the version the binary + # prints, then installed with apt on the oldest Ubuntu it supports. + - name: Package and install the binary as a .deb + if: runner.os == 'Linux' + run: | + binary="$(ls open-java-format-native/build/native/nativeCompile/open-java-format-* | grep -v '\.txt$')" + version="$("$binary" --version 2>&1 | sed -n 's/^open-java-format: Version //p')" + open-java-format-native/deb/build-deb.sh "$binary" "$version" "$RUNNER_TEMP/deb-package" + docker run --rm --volume "$PWD/open-java-format-native/deb:/scripts:ro" \ + --volume "$RUNNER_TEMP/deb-package:/packages:ro" ubuntu:22.04 \ + sh /scripts/test-deb.sh "/packages/$(ls "$RUNNER_TEMP/deb-package")" "$version" + - name: Test the plugins against the image run: ./gradlew -PnativeImage=true :open-java-format-jdk-bootstrap:test :gradle-open-java-format:test env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03cef331a..4ba51b769 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,8 +11,8 @@ name: Release # Once Maven Central serves both, the Gradle plugins go to the Gradle Plugin Portal, signed with the same # release key, and the IntelliJ plugin goes to the JetBrains Marketplace, verified against the IDEs it # supports first. After publishing, a draft GitHub release on the tag collects the runnable jar, the Gradle -# and IDE plugins, the native binaries and the WebAssembly module, which a job of its own builds on Oracle -# GraalVM. +# and IDE plugins, the native binaries, the Linux binaries again as .deb packages, and the WebAssembly module, +# which a job of its own builds on Oracle GraalVM. # # The release notes, release-notes/.md, are on the tag before it is pushed: they are the text of # the GitHub release and the IntelliJ plugin's change notes, and a tag without them publishes nothing. @@ -176,6 +176,56 @@ jobs: if-no-files-found: error retention-days: 1 + # The Linux binaries as .deb packages, for the GitHub release and for the apt repository, openjavaformat/apt, + # which serves the packages of the newest release. Each is built on the runner its binary was built on and + # installed with apt on the oldest Ubuntu and Debian it supports before it goes into the release. The time of + # the tag's commit is the time of every file in a package, so a re-run makes the same bytes. + deb-packages: + name: deb package (${{ matrix.runner }}) + needs: native-images + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + runner: + - ubuntu-latest + - ubuntu-26.04-arm + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Collect the binary + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: native-image-${{ matrix.runner }} + path: native-image + + - name: Build the package + env: + VERSION: ${{ github.ref_name }} + run: | + SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)" open-java-format-native/deb/build-deb.sh \ + native-image/open-java-format-linux-glibc_* "$VERSION" deb-package + + - name: Install the package on Ubuntu 22.04 and Debian 12 + env: + VERSION: ${{ github.ref_name }} + run: | + for image in ubuntu:22.04 debian:12; do + docker run --rm --volume "$PWD/open-java-format-native/deb:/scripts:ro" \ + --volume "$PWD/deb-package:/packages:ro" "$image" \ + sh /scripts/test-deb.sh "/packages/$(ls deb-package)" "$VERSION" + done + + - name: Hand the package to the GitHub release + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: deb-package-${{ matrix.runner }} + path: deb-package/*.deb + if-no-files-found: error + retention-days: 1 + # Not `native`: ci.yml already has a job with that id, and `act --job native` could not tell them apart. native-deploy: name: native deploy @@ -433,14 +483,14 @@ jobs: JETBRAINS_MARKETPLACE_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }} # What Maven Central does not carry — the runnable formatter jar, the Gradle plugins' jar, the IntelliJ - # plugin zip, the Eclipse plugin jar, every platform's native binary as a plain download, and the - # WebAssembly module — goes into a draft GitHub release on the tag, each file signed with the release key. - # Its text is release-notes/.md, and the plugin zip has the same change notes as the one on the - # Marketplace. Only once both deployments are published and the module is built; publishing the draft is a - # click on GitHub, and a re-run fails while a release for the tag exists. + # plugin zip, the Eclipse plugin jar, every platform's native binary as a plain download, the .deb + # packages and the WebAssembly module — goes into a draft GitHub release on the tag, each file signed with + # the release key. Its text is release-notes/.md, and the plugin zip has the same change notes as + # the one on the Marketplace. Only once both deployments are published and the packages and the module are + # built; publishing the draft is a click on GitHub, and a re-run fails while a release for the tag exists. github-release: name: draft GitHub release - needs: [publish, wasm, release-notes] + needs: [publish, deb-packages, wasm, release-notes] runs-on: ubuntu-latest permissions: contents: write @@ -463,6 +513,13 @@ jobs: pattern: native-image-* merge-multiple: true + - name: Collect the .deb packages + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + path: deb-packages + pattern: deb-package-* + merge-multiple: true + - name: Collect the WebAssembly module uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -477,8 +534,8 @@ jobs: - name: Build the plugins and open the draft release run: >- - ./gradlew -PreleaseTarget=github -PnativeImages=native-images -PwasmModule=wasm-module - -PchangeNotes=change-notes/change-notes.html jreleaserRelease + ./gradlew -PreleaseTarget=github -PnativeImages=native-images -PdebPackages=deb-packages + -PwasmModule=wasm-module -PchangeNotes=change-notes/change-notes.html jreleaserRelease env: JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }} diff --git a/buildSrc/src/main/groovy/open-java-format.release-conventions.gradle b/buildSrc/src/main/groovy/open-java-format.release-conventions.gradle index 6b0c772f1..b9f68601d 100644 --- a/buildSrc/src/main/groovy/open-java-format.release-conventions.gradle +++ b/buildSrc/src/main/groovy/open-java-format.release-conventions.gradle @@ -14,8 +14,8 @@ plugins { // `-PreleaseTarget=github` deploys nothing. It is for `jreleaserRelease`, which opens a draft GitHub // release on the tag with what Maven Central does not carry — the runnable formatter jar, the Gradle // plugins' jar, the IntelliJ plugin zip, the Eclipse plugin jar, every platform's native binary as a -// plain download and the WebAssembly module for openjavaformat.dev's playground — each file signed, plus a -// checksum file. Its text is release-notes/.md. +// plain download, the Linux binaries as .deb packages, and the WebAssembly module for openjavaformat.dev's +// playground — each file signed, plus a checksum file. Its text is release-notes/.md. // // Publishing is a run of its own: with JRELEASER_MAVENCENTRAL_DEPLOYMENT_ID set, JReleaser publishes that // deployment, which an earlier run uploaded and the Portal validated, and nothing is built. The ID has to @@ -47,8 +47,10 @@ def stagingRepositories = releasedProjects.collect { path -> } // The GitHub release takes the binaries the per-platform jobs collected from -PnativeImages=, exactly -// as the native deployment does, and the WebAssembly module's zip that the wasm job built from -PwasmModule=. +// as the native deployment does, the .deb packages built from the Linux ones from -PdebPackages=, and the +// WebAssembly module's zip that the wasm job built from -PwasmModule=. def nativeBinaries = [] +def debPackages = [] def wasmModules = [] if (releaseTarget == 'github') { def collectedNativeImages = providers.gradleProperty('nativeImages').getOrNull() @@ -63,6 +65,18 @@ if (releaseTarget == 'github') { throw new GradleException("No native images to release in ${collectedNativeImages}") } + def collectedDebPackages = providers.gradleProperty('debPackages').getOrNull() + if (collectedDebPackages == null) { + throw new GradleException('-PreleaseTarget=github needs -PdebPackages= holding the .deb packages') + } + debPackages = fileTree(file(collectedDebPackages)) { + include 'open-java-format_*.deb' + }.files.sort { it.name } + // One per Linux binary: the apt repository serves both architectures or neither. + if (debPackages*.name.collect { it.replaceAll(/.*_/, '') } != ['amd64.deb', 'arm64.deb']) { + throw new GradleException("Expected an amd64 and an arm64 .deb package in ${collectedDebPackages}, found ${debPackages*.name}") + } + def collectedWasmModule = providers.gradleProperty('wasmModule').getOrNull() if (collectedWasmModule == null) { throw new GradleException('-PreleaseTarget=github needs -PwasmModule= holding open-java-format-wasm-.zip') @@ -123,7 +137,7 @@ jreleaser { // Name templates, not Gradle's version: the root project sets its version only after applying this // plugin. The jars and the zip are built by the tasks jreleaserRelease depends on below. files { - (nativeBinaries + wasmModules).each { file -> + (nativeBinaries + debPackages + wasmModules).each { file -> artifact { path = file.absolutePath } diff --git a/open-java-format-native/deb/build-deb.sh b/open-java-format-native/deb/build-deb.sh new file mode 100755 index 000000000..e8cb34de9 --- /dev/null +++ b/open-java-format-native/deb/build-deb.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Usage: open-java-format-native/deb/build-deb.sh +# +# Packages a Linux native binary as open-java-format__.deb in , for the GitHub release +# and the apt repository that serves it, openjavaformat/apt. The package installs /usr/bin/open-java-format. +# +# The architecture, amd64 or arm64, is read off the binary's ELF header. So is the libc6 dependency: the newest +# GLIBC_ symbol version that the binary asks for, so that a build on a newer image cannot slip past older +# systems. apt refuses the package there instead of installing a binary that does not start. +# +# SOURCE_DATE_EPOCH, when set, is the modification time of every file in the package, which makes it the same +# bytes on every run. +# +# Needs dpkg-deb, readelf and du, which GitHub's Ubuntu runners have. +set -euo pipefail + +if [ $# -ne 3 ]; then + echo "Usage: $0 " >&2 + exit 2 +fi +binary=$1 +version=$2 +out=$3 +here=$(cd "$(dirname "$0")" && pwd) + +# Debian's rule for an upstream version, without an epoch: a digit first, then these characters. +if ! [[ $version =~ ^[0-9][A-Za-z0-9.+~-]*$ ]]; then + echo "Not a Debian package version: $version" >&2 + exit 1 +fi + +machine=$(readelf --file-header "$binary" | sed -n 's/^ *Machine: *//p') +case $machine in + 'Advanced Micro Devices X86-64') arch=amd64 ;; + AArch64) arch=arm64 ;; + *) + echo "$binary is not a Linux binary for x86-64 or AArch64: $machine" >&2 + exit 1 + ;; +esac + +glibc=$(readelf --version-info --wide "$binary" | grep -o 'GLIBC_[0-9][0-9.]*' | sed 's/^GLIBC_//' | sort -uV \ + | tail -n 1) +if [ -z "$glibc" ]; then + echo "$binary asks for no GLIBC_ symbol version: not a glibc binary?" >&2 + exit 1 +fi + +# The modes of the package's directories, mktemp's 0700 included, are those of what it installs. +umask 022 +root=$(mktemp -d) +trap 'rm -rf "$root"' EXIT +chmod 0755 "$root" + +install -D --mode 0755 "$binary" "$root/usr/bin/open-java-format" +install -D --mode 0644 "$here/copyright" "$root/usr/share/doc/open-java-format/copyright" +mkdir -p "$root/DEBIAN" +cat > "$root/DEBIAN/control" < +Installed-Size: $(du -sk --apparent-size "$root/usr" | cut -f 1) +Depends: libc6 (>= $glibc), zlib1g +Section: devel +Priority: optional +Homepage: https://openjavaformat.dev +Description: modern, lambda-friendly, 120-character Java formatter + open-java-format reformats Java source files to one consistent style. This + package is its native command-line binary, which needs no JDK. +CONTROL + +epoch=${SOURCE_DATE_EPOCH:-$(date +%s)} +find "$root" -exec touch --no-dereference --date "@$epoch" {} + + +mkdir -p "$out" +deb=$out/open-java-format_${version}_$arch.deb +# xz, which every dpkg reads: dpkg-deb's default, zstd, needs dpkg 1.21.18 or later. +SOURCE_DATE_EPOCH=$epoch dpkg-deb --root-owner-group -Zxz --build "$root" "$deb" +dpkg-deb --info "$deb" control diff --git a/open-java-format-native/deb/copyright b/open-java-format-native/deb/copyright new file mode 100644 index 000000000..33d7c4ee4 --- /dev/null +++ b/open-java-format-native/deb/copyright @@ -0,0 +1,24 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: open-java-format +Upstream-Contact: https://github.com/openjavaformat/open-java-format/issues +Source: https://github.com/openjavaformat/open-java-format + +Files: * +Copyright: open-java-format contributors, palantir-java-format contributors, google-java-format contributors +License: Apache-2.0 + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + . + On Debian systems, the complete text of the Apache License, Version 2.0 + can be found in "/usr/share/common-licenses/Apache-2.0". diff --git a/open-java-format-native/deb/test-deb.sh b/open-java-format-native/deb/test-deb.sh new file mode 100755 index 000000000..b1f836adc --- /dev/null +++ b/open-java-format-native/deb/test-deb.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Usage: open-java-format-native/deb/test-deb.sh +# +# Runs as root in a fresh Ubuntu or Debian container: installs the package with apt, which brings its +# dependencies, then checks that /usr/bin/open-java-format runs and prints , and formats a file. +set -eu + +if [ $# -ne 2 ]; then + echo "Usage: $0 " >&2 + exit 2 +fi +deb=$1 +version=$2 + +export DEBIAN_FRONTEND=noninteractive +apt-get update -qq +set -x +apt-get install -qq --no-install-recommends "$deb" + +test "$(command -v open-java-format)" = /usr/bin/open-java-format +# It prints the version on stderr. +test "$(open-java-format --version 2>&1)" = "open-java-format: Version $version" +cd "$(mktemp -d)" +printf 'class A{int x;}\n' > A.java +open-java-format --replace A.java +printf 'class A {\n int x;\n}\n' | diff - A.java From e44e3c1bed936882435c77c9db0b3c976389f39a Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 20:27:59 +0300 Subject: [PATCH 2/5] Build Linux on Ubuntu 24.04, and package in a workflow action The Linux binaries came from ubuntu-latest and ubuntu-26.04-arm, the newest images. A binary linked against a newer glibc can need that glibc to start, so the newest image is the one most likely to leave older systems behind. CI and the release now build Linux on the previous LTS, ubuntu-24.04 and ubuntu-24.04-arm; the other platforms stay on the newest images. The packaging moves from two shell scripts into a composite action, .github/actions/deb-package, which both workflows call: it builds the package and installs it on Ubuntu 22.04 and Debian 12. The package is the same bytes as before. --- .github/actions/deb-package/action.yml | 119 ++++++++++++++++++ .../actions/deb-package}/copyright | 0 .github/workflows/ci.yml | 30 +++-- .github/workflows/release.yml | 39 +++--- open-java-format-native/deb/build-deb.sh | 80 ------------ open-java-format-native/deb/test-deb.sh | 26 ---- 6 files changed, 156 insertions(+), 138 deletions(-) create mode 100644 .github/actions/deb-package/action.yml rename {open-java-format-native/deb => .github/actions/deb-package}/copyright (100%) delete mode 100755 open-java-format-native/deb/build-deb.sh delete mode 100755 open-java-format-native/deb/test-deb.sh diff --git a/.github/actions/deb-package/action.yml b/.github/actions/deb-package/action.yml new file mode 100644 index 000000000..9be130e04 --- /dev/null +++ b/.github/actions/deb-package/action.yml @@ -0,0 +1,119 @@ +name: Package the Linux binary as a .deb +description: >- + Packages a Linux native binary as open-java-format__.deb, which installs + /usr/bin/open-java-format, and installs it with apt on the oldest Ubuntu and Debian it supports. ci.yml runs it + on every pull request, release.yml for the GitHub release and the apt repository, openjavaformat/apt. + +inputs: + binary: + description: The native binary, for Linux on x86-64 or AArch64 + required: true + version: + description: The package version, which the binary must print as its own + required: true + out-dir: + description: The directory to write the package into + required: true + +outputs: + package: + description: The path of the package + value: ${{ steps.build.outputs.package }} + +runs: + using: composite + steps: + # The architecture is read off the binary's ELF header, and so is the libc6 dependency: the newest GLIBC_ + # symbol version that the binary asks for. A binary built on a newer image than the one release.yml names + # then cannot slip past older systems: apt refuses the package there instead of installing a binary that + # does not start. SOURCE_DATE_EPOCH, when the caller sets it, is the time of every file in the package, + # which makes a rebuild the same bytes. + - name: Build the package + id: build + shell: bash + env: + BINARY: ${{ inputs.binary }} + VERSION: ${{ inputs.version }} + OUT_DIR: ${{ inputs.out-dir }} + COPYRIGHT: ${{ github.action_path }}/copyright + run: | + set -euo pipefail + # Debian's rule for an upstream version without an epoch: a digit first, then these characters. + if ! [[ $VERSION =~ ^[0-9][A-Za-z0-9.+~-]*$ ]]; then + echo "Not a Debian package version: $VERSION" >&2 + exit 1 + fi + + machine=$(readelf --file-header "$BINARY" | sed -n 's/^ *Machine: *//p') + case $machine in + 'Advanced Micro Devices X86-64') arch=amd64 ;; + AArch64) arch=arm64 ;; + *) + echo "$BINARY is not a Linux binary for x86-64 or AArch64: $machine" >&2 + exit 1 + ;; + esac + glibc=$(readelf --version-info --wide "$BINARY" | grep -o 'GLIBC_[0-9][0-9.]*' | sed 's/^GLIBC_//' \ + | sort -uV | tail -n 1) + if [ -z "$glibc" ]; then + echo "$BINARY asks for no GLIBC_ symbol version: not a glibc binary?" >&2 + exit 1 + fi + + # The modes of the package's directories, mktemp's 0700 included, are those of what it installs. + umask 022 + root=$(mktemp -d) + chmod 0755 "$root" + install -D --mode 0755 "$BINARY" "$root/usr/bin/open-java-format" + install -D --mode 0644 "$COPYRIGHT" "$root/usr/share/doc/open-java-format/copyright" + mkdir "$root/DEBIAN" + cat > "$root/DEBIAN/control" < + Installed-Size: $(du -sk --apparent-size "$root/usr" | cut -f 1) + Depends: libc6 (>= $glibc), zlib1g + Section: devel + Priority: optional + Homepage: https://openjavaformat.dev + Description: modern, lambda-friendly, 120-character Java formatter + open-java-format reformats Java source files to one consistent style. This + package is its native command-line binary, which needs no JDK. + CONTROL + + epoch=${SOURCE_DATE_EPOCH:-$(date +%s)} + find "$root" -exec touch --no-dereference --date "@$epoch" {} + + mkdir -p "$OUT_DIR" + package=$OUT_DIR/open-java-format_${VERSION}_$arch.deb + # xz, which every dpkg reads: dpkg-deb's default, zstd, needs dpkg 1.21.18 or later. + SOURCE_DATE_EPOCH=$epoch dpkg-deb --root-owner-group -Zxz --build "$root" "$package" + rm -rf "$root" + dpkg-deb --info "$package" control + echo "package=$package" >> "$GITHUB_OUTPUT" + + # In a fresh container each: apt brings the dependencies, then the binary must run from /usr/bin, print the + # version, and format a file. + - name: Install the package on Ubuntu 22.04 and Debian 12 + shell: bash + env: + PACKAGE: ${{ steps.build.outputs.package }} + VERSION: ${{ inputs.version }} + run: | + set -euo pipefail + for image in ubuntu:22.04 debian:12; do + echo "::group::$image" + docker run --rm --env VERSION --volume "$(realpath "$PACKAGE"):/open-java-format.deb:ro" "$image" sh -euxc ' + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get install -qq --no-install-recommends /open-java-format.deb + test "$(command -v open-java-format)" = /usr/bin/open-java-format + # It prints the version on stderr. + test "$(open-java-format --version 2>&1)" = "open-java-format: Version $VERSION" + cd "$(mktemp -d)" + printf "class A{int x;}\n" > A.java + open-java-format --replace A.java + printf "class A {\n int x;\n}\n" | diff - A.java + ' + echo "::endgroup::" + done diff --git a/open-java-format-native/deb/copyright b/.github/actions/deb-package/copyright similarity index 100% rename from open-java-format-native/deb/copyright rename to .github/actions/deb-package/copyright diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b49210742..5b3155f52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,11 +170,13 @@ jobs: strategy: fail-fast: false matrix: - # The newest images. Arm Linux and Intel macOS have no free -latest label, so their images are + # Linux on the previous Ubuntu LTS: a binary built against a newer glibc may need that glibc to + # start, and the older one keeps the binaries running on older systems. release.yml builds on the + # same images. Elsewhere the newest images; Intel macOS has no free -latest label, so its image is # named. runner: - - ubuntu-latest - - ubuntu-26.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm # macOS on Apple silicon is built for a release only, in release.yml. # - macos-latest - macos-26-intel @@ -237,17 +239,23 @@ jobs: "$binary" --replace C.java printf 'import module java.base;\n\nrecord Box(int a, int b) {}\n\nvoid main() {\n Object o = new Box(1, 2);\n if (o instanceof Box(_, _)) {\n IO.println(List.of(1));\n }\n}\n' | diff - C.java - # As release.yml packages it for the GitHub release and the apt repository, under the version the binary - # prints, then installed with apt on the oldest Ubuntu it supports. - - name: Package and install the binary as a .deb + # Packaged as release.yml packages it for the GitHub release and the apt repository, under the version + # the binary prints. + - name: Find the binary and its version + id: binary if: runner.os == 'Linux' run: | binary="$(ls open-java-format-native/build/native/nativeCompile/open-java-format-* | grep -v '\.txt$')" - version="$("$binary" --version 2>&1 | sed -n 's/^open-java-format: Version //p')" - open-java-format-native/deb/build-deb.sh "$binary" "$version" "$RUNNER_TEMP/deb-package" - docker run --rm --volume "$PWD/open-java-format-native/deb:/scripts:ro" \ - --volume "$RUNNER_TEMP/deb-package:/packages:ro" ubuntu:22.04 \ - sh /scripts/test-deb.sh "/packages/$(ls "$RUNNER_TEMP/deb-package")" "$version" + echo "path=$binary" >> "$GITHUB_OUTPUT" + echo "version=$("$binary" --version 2>&1 | sed -n 's/^open-java-format: Version //p')" >> "$GITHUB_OUTPUT" + + - name: Package and install the binary as a .deb + if: runner.os == 'Linux' + uses: $/.github/actions/deb-package + with: + binary: ${{ steps.binary.outputs.path }} + version: ${{ steps.binary.outputs.version }} + out-dir: ${{ runner.temp }}/deb-package - name: Test the plugins against the image run: ./gradlew -PnativeImage=true :open-java-format-jdk-bootstrap:test :gradle-open-java-format:test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ba51b769..804252ecc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -132,10 +132,10 @@ jobs: strategy: fail-fast: false matrix: - # The newest images, as in ci.yml. + # The images of ci.yml: Linux on the previous Ubuntu LTS, for the oldest glibc, the rest the newest. runner: - - ubuntu-latest - - ubuntu-26.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm - macos-latest - macos-26-intel - windows-latest @@ -178,8 +178,9 @@ jobs: # The Linux binaries as .deb packages, for the GitHub release and for the apt repository, openjavaformat/apt, # which serves the packages of the newest release. Each is built on the runner its binary was built on and - # installed with apt on the oldest Ubuntu and Debian it supports before it goes into the release. The time of - # the tag's commit is the time of every file in a package, so a re-run makes the same bytes. + # installed with apt on the oldest Ubuntu and Debian it supports before it goes into the release, by the + # deb-package action that ci.yml runs too. The time of the tag's commit is the time of every file in a + # package, so a re-run makes the same bytes. deb-packages: name: deb package (${{ matrix.runner }}) needs: native-images @@ -188,8 +189,8 @@ jobs: fail-fast: false matrix: runner: - - ubuntu-latest - - ubuntu-26.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -201,22 +202,18 @@ jobs: name: native-image-${{ matrix.runner }} path: native-image - - name: Build the package - env: - VERSION: ${{ github.ref_name }} + - name: Find the binary + id: binary run: | - SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)" open-java-format-native/deb/build-deb.sh \ - native-image/open-java-format-linux-glibc_* "$VERSION" deb-package + echo "path=$(ls native-image/open-java-format-linux-glibc_*)" >> "$GITHUB_OUTPUT" + echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV" - - name: Install the package on Ubuntu 22.04 and Debian 12 - env: - VERSION: ${{ github.ref_name }} - run: | - for image in ubuntu:22.04 debian:12; do - docker run --rm --volume "$PWD/open-java-format-native/deb:/scripts:ro" \ - --volume "$PWD/deb-package:/packages:ro" "$image" \ - sh /scripts/test-deb.sh "/packages/$(ls deb-package)" "$VERSION" - done + - name: Package and install the binary + uses: $/.github/actions/deb-package + with: + binary: ${{ steps.binary.outputs.path }} + version: ${{ github.ref_name }} + out-dir: deb-package - name: Hand the package to the GitHub release uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/open-java-format-native/deb/build-deb.sh b/open-java-format-native/deb/build-deb.sh deleted file mode 100755 index e8cb34de9..000000000 --- a/open-java-format-native/deb/build-deb.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash -# Usage: open-java-format-native/deb/build-deb.sh -# -# Packages a Linux native binary as open-java-format__.deb in , for the GitHub release -# and the apt repository that serves it, openjavaformat/apt. The package installs /usr/bin/open-java-format. -# -# The architecture, amd64 or arm64, is read off the binary's ELF header. So is the libc6 dependency: the newest -# GLIBC_ symbol version that the binary asks for, so that a build on a newer image cannot slip past older -# systems. apt refuses the package there instead of installing a binary that does not start. -# -# SOURCE_DATE_EPOCH, when set, is the modification time of every file in the package, which makes it the same -# bytes on every run. -# -# Needs dpkg-deb, readelf and du, which GitHub's Ubuntu runners have. -set -euo pipefail - -if [ $# -ne 3 ]; then - echo "Usage: $0 " >&2 - exit 2 -fi -binary=$1 -version=$2 -out=$3 -here=$(cd "$(dirname "$0")" && pwd) - -# Debian's rule for an upstream version, without an epoch: a digit first, then these characters. -if ! [[ $version =~ ^[0-9][A-Za-z0-9.+~-]*$ ]]; then - echo "Not a Debian package version: $version" >&2 - exit 1 -fi - -machine=$(readelf --file-header "$binary" | sed -n 's/^ *Machine: *//p') -case $machine in - 'Advanced Micro Devices X86-64') arch=amd64 ;; - AArch64) arch=arm64 ;; - *) - echo "$binary is not a Linux binary for x86-64 or AArch64: $machine" >&2 - exit 1 - ;; -esac - -glibc=$(readelf --version-info --wide "$binary" | grep -o 'GLIBC_[0-9][0-9.]*' | sed 's/^GLIBC_//' | sort -uV \ - | tail -n 1) -if [ -z "$glibc" ]; then - echo "$binary asks for no GLIBC_ symbol version: not a glibc binary?" >&2 - exit 1 -fi - -# The modes of the package's directories, mktemp's 0700 included, are those of what it installs. -umask 022 -root=$(mktemp -d) -trap 'rm -rf "$root"' EXIT -chmod 0755 "$root" - -install -D --mode 0755 "$binary" "$root/usr/bin/open-java-format" -install -D --mode 0644 "$here/copyright" "$root/usr/share/doc/open-java-format/copyright" -mkdir -p "$root/DEBIAN" -cat > "$root/DEBIAN/control" < -Installed-Size: $(du -sk --apparent-size "$root/usr" | cut -f 1) -Depends: libc6 (>= $glibc), zlib1g -Section: devel -Priority: optional -Homepage: https://openjavaformat.dev -Description: modern, lambda-friendly, 120-character Java formatter - open-java-format reformats Java source files to one consistent style. This - package is its native command-line binary, which needs no JDK. -CONTROL - -epoch=${SOURCE_DATE_EPOCH:-$(date +%s)} -find "$root" -exec touch --no-dereference --date "@$epoch" {} + - -mkdir -p "$out" -deb=$out/open-java-format_${version}_$arch.deb -# xz, which every dpkg reads: dpkg-deb's default, zstd, needs dpkg 1.21.18 or later. -SOURCE_DATE_EPOCH=$epoch dpkg-deb --root-owner-group -Zxz --build "$root" "$deb" -dpkg-deb --info "$deb" control diff --git a/open-java-format-native/deb/test-deb.sh b/open-java-format-native/deb/test-deb.sh deleted file mode 100755 index b1f836adc..000000000 --- a/open-java-format-native/deb/test-deb.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Usage: open-java-format-native/deb/test-deb.sh -# -# Runs as root in a fresh Ubuntu or Debian container: installs the package with apt, which brings its -# dependencies, then checks that /usr/bin/open-java-format runs and prints , and formats a file. -set -eu - -if [ $# -ne 2 ]; then - echo "Usage: $0 " >&2 - exit 2 -fi -deb=$1 -version=$2 - -export DEBIAN_FRONTEND=noninteractive -apt-get update -qq -set -x -apt-get install -qq --no-install-recommends "$deb" - -test "$(command -v open-java-format)" = /usr/bin/open-java-format -# It prints the version on stderr. -test "$(open-java-format --version 2>&1)" = "open-java-format: Version $version" -cd "$(mktemp -d)" -printf 'class A{int x;}\n' > A.java -open-java-format --replace A.java -printf 'class A {\n int x;\n}\n' | diff - A.java From bdd465e641768b096a8e00c8a32c0302ace90de8 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 20:29:33 +0300 Subject: [PATCH 3/5] Build Linux on Ubuntu 22.04 The packages, the apt repository and the docs say the binaries run on glibc 2.34 or later, Ubuntu 22.04 and newer. Building on 22.04, glibc 2.35, keeps that true by construction rather than by luck of which symbols a newer glibc versioned. --- .github/workflows/ci.yml | 11 +++++------ .github/workflows/release.yml | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b3155f52..fae36f2da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,13 +170,12 @@ jobs: strategy: fail-fast: false matrix: - # Linux on the previous Ubuntu LTS: a binary built against a newer glibc may need that glibc to - # start, and the older one keeps the binaries running on older systems. release.yml builds on the - # same images. Elsewhere the newest images; Intel macOS has no free -latest label, so its image is - # named. + # Linux on Ubuntu 22.04, the oldest system the binaries promise to run on (glibc 2.34 or later): a + # binary built against a newer glibc may need that glibc to start. release.yml builds on the same + # images. Elsewhere the newest images; Intel macOS has no free -latest label, so its image is named. runner: - - ubuntu-24.04 - - ubuntu-24.04-arm + - ubuntu-22.04 + - ubuntu-22.04-arm # macOS on Apple silicon is built for a release only, in release.yml. # - macos-latest - macos-26-intel diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 804252ecc..98b22d066 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -132,10 +132,10 @@ jobs: strategy: fail-fast: false matrix: - # The images of ci.yml: Linux on the previous Ubuntu LTS, for the oldest glibc, the rest the newest. + # The images of ci.yml: Linux on Ubuntu 22.04, the oldest system the binaries support, the rest the newest. runner: - - ubuntu-24.04 - - ubuntu-24.04-arm + - ubuntu-22.04 + - ubuntu-22.04-arm - macos-latest - macos-26-intel - windows-latest @@ -189,8 +189,8 @@ jobs: fail-fast: false matrix: runner: - - ubuntu-24.04 - - ubuntu-24.04-arm + - ubuntu-22.04 + - ubuntu-22.04-arm steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: From 4ea983701bd34840527efa89ad8898e8e0810630 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 20:33:03 +0300 Subject: [PATCH 4/5] Build Linux on Ubuntu 24.04 after all GitHub retires ubuntu-22.04 and ubuntu-22.04-arm on April 17, 2027, with failing brownouts from March 23 (actions/runner-images#14254), and Ubuntu 22.04's standard support ends then too. The previous LTS, 24.04, is the image that stays. The packages' libc6 dependency is still read off each binary, so a higher glibc need shows in the package instead of in a binary that does not start. --- .github/workflows/ci.yml | 11 ++++++----- .github/workflows/release.yml | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fae36f2da..f4d78e5dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,12 +170,13 @@ jobs: strategy: fail-fast: false matrix: - # Linux on Ubuntu 22.04, the oldest system the binaries promise to run on (glibc 2.34 or later): a - # binary built against a newer glibc may need that glibc to start. release.yml builds on the same - # images. Elsewhere the newest images; Intel macOS has no free -latest label, so its image is named. + # Linux on the previous Ubuntu LTS, not the newest: a binary built against a newer glibc may need that + # glibc to start, and the older one keeps the binaries running on older systems. GitHub retires an + # image once two newer ones are out. release.yml builds on the same images. Elsewhere the newest + # images; Intel macOS has no free -latest label, so its image is named. runner: - - ubuntu-22.04 - - ubuntu-22.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm # macOS on Apple silicon is built for a release only, in release.yml. # - macos-latest - macos-26-intel diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 98b22d066..4546aa7ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -132,10 +132,10 @@ jobs: strategy: fail-fast: false matrix: - # The images of ci.yml: Linux on Ubuntu 22.04, the oldest system the binaries support, the rest the newest. + # The images of ci.yml: Linux on the previous Ubuntu LTS, for an older glibc, the rest the newest. runner: - - ubuntu-22.04 - - ubuntu-22.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm - macos-latest - macos-26-intel - windows-latest @@ -189,8 +189,8 @@ jobs: fail-fast: false matrix: runner: - - ubuntu-22.04 - - ubuntu-22.04-arm + - ubuntu-24.04 + - ubuntu-24.04-arm steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: From 72e97889da1997692f45e3a0bb5941231dbf8a17 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Sat, 28 Nov 2026 20:48:31 +0300 Subject: [PATCH 5/5] Package a CI binary whose version starts with a letter Outside a tag the binary prints a bare commit hash as its version, such as 244d57b, and a Debian version must start with a digit: about six hashes in sixteen would have failed the native job. Such a version now gets 0~ in front, which sorts below every release; a release version is unchanged. --- .github/actions/deb-package/action.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/actions/deb-package/action.yml b/.github/actions/deb-package/action.yml index 9be130e04..6c513d689 100644 --- a/.github/actions/deb-package/action.yml +++ b/.github/actions/deb-package/action.yml @@ -9,7 +9,7 @@ inputs: description: The native binary, for Linux on x86-64 or AArch64 required: true version: - description: The package version, which the binary must print as its own + description: The version that the binary prints, which is the package version too (with 0~ in front when it does not start with a digit) required: true out-dir: description: The directory to write the package into @@ -38,9 +38,15 @@ runs: COPYRIGHT: ${{ github.action_path }}/copyright run: | set -euo pipefail - # Debian's rule for an upstream version without an epoch: a digit first, then these characters. - if ! [[ $VERSION =~ ^[0-9][A-Za-z0-9.+~-]*$ ]]; then - echo "Not a Debian package version: $VERSION" >&2 + # Debian's rule for an upstream version without an epoch: a digit first, then these characters. Outside + # a tag the binary's version can be a bare commit hash, which may start with a letter: 0~ in front makes + # it a version that sorts below every release. + deb_version=$VERSION + if ! [[ $deb_version =~ ^[0-9] ]]; then + deb_version=0~$deb_version + fi + if ! [[ $deb_version =~ ^[0-9][A-Za-z0-9.+~-]*$ ]]; then + echo "Not a Debian package version: $deb_version" >&2 exit 1 fi @@ -69,7 +75,7 @@ runs: mkdir "$root/DEBIAN" cat > "$root/DEBIAN/control" < Installed-Size: $(du -sk --apparent-size "$root/usr" | cut -f 1) @@ -85,7 +91,7 @@ runs: epoch=${SOURCE_DATE_EPOCH:-$(date +%s)} find "$root" -exec touch --no-dereference --date "@$epoch" {} + mkdir -p "$OUT_DIR" - package=$OUT_DIR/open-java-format_${VERSION}_$arch.deb + package=$OUT_DIR/open-java-format_${deb_version}_$arch.deb # xz, which every dpkg reads: dpkg-deb's default, zstd, needs dpkg 1.21.18 or later. SOURCE_DATE_EPOCH=$epoch dpkg-deb --root-owner-group -Zxz --build "$root" "$package" rm -rf "$root"