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

ci: add auto pin script #181

Merged
merged 7 commits into from
Nov 23, 2024
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
3 changes: 2 additions & 1 deletion hyprpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ commit_pins = [
["f044e4c9514ec89c4c1fc8a523ca90b8cb907fb7", "070ca398300bf5b9e1a636ca057882c0312c228d"], # CMonitor* -> PHLMONITOR
["a425fbebe4cf4238e48a42f724ef2208959d66cf", "a86ed5581498186ed31241c0c246629ef771d1e6"], # v0.45.0
["500d2a3580388afc8b620b0a3624147faa34f98b", "cb929099477407116031010905ce439db771dd62"], # v0.45.1
["12f9a0d0b93f691d4d9923716557154d74777b0a", "47f6fea6d297dbee8a9c5dea905783bde506fe79"], # v0.45.2
["12f9a0d0b93f691d4d9923716557154d74777b0a", "cb929099477407116031010905ce439db771dd62"], # v0.45.2
## DO NOT EDIT THIS LINE: for auto pin script ##
]

[hyprgrass]
Expand Down
9 changes: 9 additions & 0 deletions scripts/ci/latest-hyprland-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

## Usage
## -----
## Prints the tag name of the latest Hyprland release

# if anyone knows jq help me rewrite this
gh release list --repo hyprwm/Hyprland --json tagName,isLatest | \
nix eval --impure --raw --expr 'with builtins; (head (filter (x: x.isLatest) (fromJSON (readFile /dev/stdin)))).tagName'
57 changes: 57 additions & 0 deletions scripts/ci/pin-latest-hyprland
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

set -eu

usage() {
echoerr "Usage:"
echoerr ""
echoerr " pin-latest-hyprland [HYPRGRASS_REV]"
echoerr ""
echoerr "Pins the latest hyprland release to HYPRGRASS_REV (default HEAD) in hyprpm.toml."
echoerr "Does nothing if a pin on the hyprland release already exists."
}

HYPRGRASS_REV=${1:-HEAD}

echoerr() {
echo $@ >&2
}

findHyprpmPin() {
local hlCommit="$1"
nix eval --raw --impure --expr '
with builtins; let
hyprpm = fromTOML (readFile ./hyprpm.toml);
hlCommits = map head hyprpm.repository.commit_pins;
in
concatStringsSep "\n" hlCommits
' | grep "$hlCommit" > /dev/null
}

getHyprlandCommitFromRev() {
git ls-remote https://github.com/hyprwm/Hyprland.git "$1" \
| cut -f 1
}

SCRIPT_DIR="$(dirname "$0")"

hlTag="$("$SCRIPT_DIR/latest-hyprland-tag")"
echoerr "found latest Hyprland release: $hlTag"

hlCommit="$(getHyprlandCommitFromRev "$hlTag")"
echoerr "-> commit: $hlCommit"

if findHyprpmPin "$hlCommit"; then
echoerr "pin for tag $hlTag already found in hyprpm.toml"
exit 0
fi

echoerr "building and testing..."
commitPin="$("$SCRIPT_DIR/test-pin.sh" "$hlTag" "$HYPRGRASS_REV")"

echoerr "pin tests passed: $commitPin"
echoerr 'updating hyprpm.toml'

sed -i "/## DO NOT EDIT THIS LINE: for auto pin script ##/ i $commitPin" \
hyprpm.toml

4 changes: 1 addition & 3 deletions scripts/test-pin.sh → scripts/ci/test-pin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ hyprgrassRev=${2:-main}
hyprlandCommit="$(git ls-remote https://github.com/hyprwm/Hyprland.git "${hyprlandRev}" | cut -f 1)"
hyprgrassCommit="$(git rev-parse "${hyprgrassRev}")"

git stash
git checkout "${hyprgrassRev}"
nix build --no-link .#hyprgrassWithTests \
nix build --no-link "git+file://$(pwd)?rev=${hyprgrassRev}#hyprgrassWithTests" \
--override-input hyprland "github:hyprwm/Hyprland/${hyprlandRev}" \

echo "[\"${hyprlandCommit}\", \"${hyprgrassCommit}\"], # ${hyprlandRev}"
Loading