Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 20 additions & 53 deletions .github/build-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
# Usage: .github/build-repository.sh <version> <release-dir> <site-dir>
#
# Builds the apt repository for one open-java-format release into <site-dir>, which must not exist yet.
# <release-dir> 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.
# <release-dir> holds the release's open-java-format_<version>_amd64.deb, open-java-format_<version>_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
Expand Down Expand Up @@ -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" <<CONTROL
Package: open-java-format
Version: $version
Architecture: $arch
Maintainer: Alexey Abashev <alexey@openjavaformat.dev>
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
Expand Down
50 changes: 34 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
24 changes: 0 additions & 24 deletions debian/copyright

This file was deleted.

Loading