Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add homebrew tarball generating action #173

Merged
merged 17 commits into from
Feb 16, 2025
Merged
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
72 changes: 72 additions & 0 deletions .github/workflows/brew-tarball.yml
Original file line number Diff line number Diff line change
@@ -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 }}/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
output/
mock/
rpmbuild
rpmbuild/
brew-out/
20 changes: 20 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"