diff --git a/.github/workflows/brew-tarball.yml b/.github/workflows/brew-tarball.yml new file mode 100644 index 0000000..e881ac5 --- /dev/null +++ b/.github/workflows/brew-tarball.yml @@ -0,0 +1,72 @@ +name: Generate Homebrew tarball and Release + +on: + schedule: + - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC + merge_group: + pull_request: + paths: + - ./Justfile + +jobs: + generate_and_push: + name: Generate homebrew tarball and release + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + - name: Setup Just + uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2 + + - name: Generate Homebrew tarball + id: generate_tarball + run: | + set -euox pipefail + just=$(which just) + + OUTDIR="./brew-out" + SHASUM_DIR="./brew-sum" + TARBALL_FILENAME="homebrew-$(arch).tar.zst" + + $just generate-homebrew-tarball ${OUTDIR} ${TARBALL_FILENAME} + + mkdir -p $SHASUM_DIR + for spice in 1 256 512 ; do + "sha${spice}sum" "$OUTDIR/$TARBALL_FILENAME" | tee "$SHASUM_DIR/homebrew-$(arch).sha${spice}" + done + + echo "outdir=$(realpath $OUTDIR)" >> "$GITHUB_OUTPUT" + echo "tarball_file=$(realpath $OUTDIR)/$TARBALL_FILENAME" >> "$GITHUB_OUTPUT" + echo "shasum_dir=$(realpath $SHASUM_DIR)" >> "$GITHUB_OUTPUT" + + - name: Upload to Job Artifacts + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4 + with: + # FIXME: use matrix.platform once homebrew for aarch64 is done + name: brew-tarball-amd64 + if-no-files-found: error + path: | + ${{ steps.generate_tarball.outputs.tarball_file }} + + - name: Get current date + if: github.event_name != 'pull_request' + id: date + run: | + set -x + echo "date=$(date -u +%Y\-%m\-%d\ %H\:%M\:%S)" >> $GITHUB_OUTPUT + echo "tag_date=$(date -u +%Y\-%m\-%d-%H-%M-%S)" >> $GITHUB_OUTPUT + + - name: Create Release + if: github.event_name != 'pull_request' + uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2 + with: + name: Homebrew Tarball (${{ steps.date.outputs.date }}) + tag_name: "homebrew-${{ steps.date.outputs.tag_date }}" + body: | + This is a homebrew tarball generated for the [ublue-brew](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/ublue/brew/ublue-brew.spec) package. + It exists so that images can have a consistent tarball to base to install homebrew + make_latest: true + files: | + ${{ steps.generate_tarball.outputs.tarball_file }} + ${{ steps.generate_tarball.outputs.shasum_dir }}/* diff --git a/.gitignore b/.gitignore index e0fa512..b0af106 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ output/ mock/ -rpmbuild +rpmbuild/ +brew-out/ diff --git a/Justfile b/Justfile index 6cbdb19..492da3f 100644 --- a/Justfile +++ b/Justfile @@ -33,3 +33,23 @@ build $spec *MOCK_ARGS: --group-entry "mock:x:135:$(id -nu)" \ $mock_image \ $spec {{ MOCK_ARGS }} + +generate-homebrew-tarball $OUTDIR="./brew-out" $TARBALL_FILENAME="homebrew.tar.zst": + #!/usr/bin/env bash + + set -x + + mkdir -p $OUTDIR + + podman run --rm -it \ + -v "$OUTDIR:/outdir:Z" \ + cgr.dev/chainguard/wolfi-base:latest \ + /bin/sh -c " + set -o xtrace + apk add curl git zstd posix-libc-utils uutils + curl --retry 3 -Lo /tmp/brew-install https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh + chmod +x /tmp/brew-install + touch /.dockerenv + ln -s /bin/bash /usr/bin/bash + env --ignore-environment PATH=/usr/bin:/bin:/usr/sbin:/sbin HOME=/home/linuxbrew NONINTERACTIVE=1 /usr/bin/bash /tmp/brew-install + tar -cvf /dev/stdout /home/linuxbrew | zstd -v -T0 -10 -f -o /outdir/{{ TARBALL_FILENAME }}"