diff --git a/.github/build-repository.sh b/.github/build-repository.sh index c77c46f..0a4e0e4 100755 --- a/.github/build-repository.sh +++ b/.github/build-repository.sh @@ -2,20 +2,15 @@ # Usage: .github/build-repository.sh # # Builds the apt repository for one open-java-format release into , which must not exist yet. -# holds the release's open-java-format-linux-glibc_x86-64, open-java-format-linux-glibc_aarch64 -# and checksums_sha256.txt; a binary that does not match its checksum fails the script. +# holds the release's open-java-format__amd64.deb, open-java-format__arm64.deb +# and checksums_sha256.txt; a package that does not match its checksum fails the script. The release workflow of +# openjavaformat/open-java-format builds and tests the packages; here they are only checked and indexed. # -# Each binary becomes a .deb that installs /usr/bin/open-java-format. Its libc6 dependency is the newest -# GLIBC_ symbol version that the binary asks for, read off the binary itself, so 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. The indexes are written by apt-ftparchive, and Release is signed, as InRelease and Release.gpg, with -# the only secret key in the gpg keyring, whose public key is published as key.asc. +# The indexes are written by apt-ftparchive, and Release is signed, as InRelease and Release.gpg, with the only +# secret key in the gpg keyring, whose public key is published as key.asc. # -# SOURCE_DATE_EPOCH, when set, is the modification time of every file in the packages, which makes them the -# same bytes on every run. -# -# Needs dpkg-deb, apt-ftparchive, readelf, gpg and sha256sum: GitHub's Ubuntu runners lack only apt-ftparchive, -# which is in apt-utils. +# Needs dpkg-deb, apt-ftparchive, gpg and sha256sum: GitHub's Ubuntu runners lack only apt-ftparchive, which is +# in apt-utils. set -euo pipefail if [ $# -ne 3 ]; then @@ -47,48 +42,20 @@ key=$(awk -F: '$1 == "fpr" { print $10; exit }' <<< "$secret_keys") work=$(mktemp -d) trap 'rm -rf "$work"' EXIT -mkdir -p "$site/pool/main/o/open-java-format" -epoch=${SOURCE_DATE_EPOCH:-$(date +%s)} - +pool=$site/pool/main/o/open-java-format +mkdir -p "$pool" for arch in amd64 arm64; do - case $arch in - amd64) binary=open-java-format-linux-glibc_x86-64 ;; - arm64) binary=open-java-format-linux-glibc_aarch64 ;; - esac - - (cd "$release" && grep -E "^[0-9a-f]{64}[ *]+$binary\$" checksums_sha256.txt | sha256sum --check --strict -) - - glibc=$(readelf --version-info --wide "$release/$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 - - root=$work/$arch - install -D --mode 0755 "$release/$binary" "$root/usr/bin/open-java-format" - install -D --mode 0644 "$here/debian/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 - find "$root" -exec touch --no-dereference --date "@$epoch" {} + - - deb=$site/pool/main/o/open-java-format/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 + deb=open-java-format_${version}_$arch.deb + (cd "$release" && grep -E "^[0-9a-f]{64}[ *]+$deb\$" checksums_sha256.txt | sha256sum --check --strict -) + # The package must be what its name says. + for field in Package:open-java-format Version:"$version" Architecture:"$arch"; do + actual=$(dpkg-deb --field "$release/$deb" "${field%%:*}") + if [ "$actual" != "${field#*:}" ]; then + echo "$deb has ${field%%:*} $actual, not ${field#*:}" >&2 + exit 1 + fi + done + cp "$release/$deb" "$pool/$deb" done dists=$site/dists/stable diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1c3fcd9..8ef0638 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,15 @@ name: Publish # Builds the apt repository for the newest release of openjavaformat/open-java-format, installs from it on -# every supported system, and deploys it to GitHub Pages, at https://apt.openjavaformat.dev. The packages -# go up as a Pages artifact only, so no binary lands in Git history. +# every supported system, and deploys it to GitHub Pages, at https://apt.openjavaformat.dev. The .deb +# packages are the release's own, which its release workflow built and signed: here they are checked +# against the release's checksums and indexed. They go up as a Pages artifact only, so no binary lands in +# Git history. # -# Once an hour it compares the version that the live repository serves with the newest release, and does -# the rest only when they differ: that is how a release reaches `apt upgrade`. A push to main rebuilds and -# redeploys the newest release, and a pull request builds and tests without deploying, signed by a -# throwaway key. Run by hand, it can publish a given release, an older one too. +# Once an hour it compares the version that the live repository serves with the newest release that has +# packages, and does the rest only when they differ: that is how a release reaches `apt upgrade`. A push to +# main rebuilds and redeploys that release, and a pull request builds and tests without deploying, signed by +# a throwaway key. Run by hand, it can publish a given release, an older one too. # # Needs one repository secret, APT_SIGNING_KEY: the ASCII-armored secret key that signs the repository, # without a passphrase. Its public half is key.asc on the site. @@ -53,13 +55,33 @@ jobs: EVENT: ${{ github.event_name }} REQUESTED: ${{ inputs.version }} run: | + has_packages() { + local assets + assets=$(gh release view "$1" --repo openjavaformat/open-java-format --json assets --jq '.assets[].name') + grep -qx "open-java-format_$1_amd64.deb" <<< "$assets" && grep -qx "open-java-format_$1_arm64.deb" <<< "$assets" + } if [ -n "${REQUESTED:-}" ]; then version=$REQUESTED + if ! has_packages "$version"; then + echo "Release $version has no .deb packages" >&2 + exit 1 + fi else # The highest version, not the release published last: a fix for an older line can come out - # after a newer line started. - version=$(gh release list --repo openjavaformat/open-java-format --exclude-drafts --exclude-pre-releases \ - --limit 100 --json tagName --jq '.[].tagName' | sort -V | tail -n 1) + # after a newer line started. Releases up to 21.1.1 have no packages. + version= + for tag in $(gh release list --repo openjavaformat/open-java-format --exclude-drafts \ + --exclude-pre-releases --limit 100 --json tagName --jq '.[].tagName' | sort -rV); do + if has_packages "$tag"; then + version=$tag + break + fi + echo "::notice::Release $tag has no .deb packages" + done + if [ -z "$version" ]; then + echo "No release has .deb packages yet." + exit 0 + fi fi if [ "$EVENT" = schedule ]; then site=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq .html_url) @@ -84,19 +106,15 @@ jobs: with: persist-credentials: false - - name: Download the Linux binaries + - name: Download the packages env: GH_TOKEN: ${{ github.token }} VERSION: ${{ needs.version.outputs.version }} run: | gh release download "$VERSION" --repo openjavaformat/open-java-format --dir "$RUNNER_TEMP/release" \ --pattern checksums_sha256.txt \ - --pattern open-java-format-linux-glibc_x86-64 \ - --pattern open-java-format-linux-glibc_aarch64 - # The release's publication time, as the time of every file in the packages, makes a rebuild of the - # same release the same bytes. - date -d "$(gh release view "$VERSION" --repo openjavaformat/open-java-format --json publishedAt \ - --jq .publishedAt)" +SOURCE_DATE_EPOCH=%s >> "$GITHUB_ENV" + --pattern "open-java-format_${VERSION}_amd64.deb" \ + --pattern "open-java-format_${VERSION}_arm64.deb" - name: Import the signing key env: diff --git a/README.md b/README.md index 170eec6..f8d6b42 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ The repository is signed by a key of its own, not by the release key. Its finger ## How it keeps up -[Publish](.github/workflows/publish.yml) runs once an hour. When the newest release is not the version that the -repository serves, it downloads the release's two Linux binaries, checks them against its -`checksums_sha256.txt`, builds the packages and the signed indexes with -[build-repository.sh](.github/build-repository.sh), installs from the result on every system above, on amd64 and -arm64, and deploys it to GitHub Pages. The packages go up as a Pages artifact, so no binary lands in Git history. +The packages are files of the GitHub release: the release workflow of open-java-format builds them from the Linux +binaries and tests them. [Publish](.github/workflows/publish.yml) runs once an hour. When the newest release is not +the version that the repository serves, it downloads the release's two packages, checks them against its +`checksums_sha256.txt`, writes and signs the indexes with [build-repository.sh](.github/build-repository.sh), +installs from the result on every system above, on amd64 and arm64, and deploys it to GitHub Pages. The packages go up as a Pages artifact, so no binary lands in Git history. A push to main and a pull request do the same, except that a pull request deploys nothing. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 33d7c4e..0000000 --- a/debian/copyright +++ /dev/null @@ -1,24 +0,0 @@ -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".