Skip to content

Commit

Permalink
Adapt Holonix automation to this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Jun 6, 2024
1 parent 218faa5 commit 58ba7b5
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 76 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
nix-check:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- name: Check out source code
uses: actions/checkout@v4
Expand All @@ -19,12 +23,42 @@ jobs:
with:
install_url: https://releases.nixos.org/nix/nix-2.22.1/install

- name: Use GitHub cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check Nix formatting
run: nix fmt . -- --check

- name: Check Nix flake
run: nix flake check --all-systems

script-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ludeeus/action-shellcheck@v2

- name: Test bump-holochain.sh
run: |
MINOR_VERSION=$(./scripts/bump.sh main-0.1 false | tail -n 1)
if [[ "$MINOR_VERSION" != "0.1.8" ]]; then
echo "bump.sh failed to find 0.1.8: [${MINOR_VERSION}]"
exit 1
fi
RC_VERSION=$(./scripts/bump.sh main-0.1-rc false | tail -n 1)
if [[ "$RC_VERSION" != "0.1.7-rc.0" ]]; then
echo "bump.sh failed to find 0.1.7-rc.0: [${RC_VERSION}]"
exit 1
fi
CURRENT_VERSION=$(./scripts/bump.sh main false | tail -n 1)
if [[ "$CURRENT_VERSION" != 0.4.*dev* ]]; then
echo "bump.sh failed to find current version: [${CURRENT_VERSION}]"
exit 1
fi
build:
strategy:
matrix:
Expand Down
74 changes: 53 additions & 21 deletions .github/workflows/command-listener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,75 @@ jobs:
echo "action=${COMMAND}" >> "$GITHUB_OUTPUT"
outputs:
action: ${{ steps.dispatch.outputs.action }}
holonix_update:
name: Holonix update
bump_holochain:
name: Bump Holochain
runs-on: ubuntu-latest
needs: [action_pr_comment]
if: ${{ startsWith(needs.action_pr_comment.outputs.action, 'holonix_update') }}
if: ${{ startsWith(needs.action_pr_comment.outputs.action, 'bump holochain') }}
steps:
- name: Configure
id: configure
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.22.1/install
- name: set up git config
run: |
./scripts/ci-git-config.sh
- name: Flake update
env:
ACTION: ${{ needs.action_pr_comment.outputs.action }}
PR_NUMBER: ${{ github.event.issue.number }}
RUN_ID: ${{ github.run_id }}
GH_TOKEN: ${{ secrets.HRA_GITHUB_TOKEN }}
run: |
set -euo pipefail
HOLONIX_VERSION=$(echo $ACTION | cut -b 16- | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
gh pr comment $PR_NUMBER --repo holochain/holochain --body "Got it, will try to update inputs for Holonix version \`$HOLONIX_VERSION\` - [Workflow](https://github.com/holochain/holochain/actions/runs/$RUN_ID)"
echo "holonix_version=${HOLONIX_VERSION}" >> "$GITHUB_OUTPUT"
gh pr checkout $PR_NUMBER --repo holochain/holonix
./scripts/bump-holochain.sh
git add flake.nix flake.lock
git commit -m "Bump Holochain version"
git pull --rebase
git push
bump_hc_launch:
name: Bump hc-launch
runs-on: ubuntu-latest
needs: [action_pr_comment]
if: ${{ startsWith(needs.action_pr_comment.outputs.action, 'bump hc-launch') }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: cachix/cachix-action@v14
- uses: cachix/install-nix-action@v27
with:
name: holochain-ci
install_url: https://releases.nixos.org/nix/nix-2.22.1/install
- name: set up git config
run: |
./scripts/ci-git-config.sh
- name: Flake update
env:
PR_NUMBER: ${{ github.event.issue.number }}
HOLONIX_VERSION: ${{ steps.configure.outputs.holonix_version }}
GH_TOKEN: ${{ secrets.HRA_GITHUB_TOKEN }}
run: |
set -euo pipefail
gh pr checkout $PR_NUMBER --repo holochain/holochain
nix run .#scripts-repo-flake-update $HOLONIX_VERSION
gh pr checkout $PR_NUMBER --repo holochain/holonix
nix flake update hc-launch
git add flake.lock
git commit -m "Bump hc-launch version"
git pull --rebase
git push
bump_hc_scaffold:
name: Bump hc-scaffold
runs-on: ubuntu-latest
needs: [ action_pr_comment ]
if: ${{ startsWith(needs.action_pr_comment.outputs.action, 'bump hc-scaffold') }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.22.1/install
- name: set up git config
run: |
./scripts/ci-git-config.sh
- name: Flake update
env:
PR_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.HRA_GITHUB_TOKEN }}
run: |
gh pr checkout $PR_NUMBER --repo holochain/holonix
nix flake update hc-scaffold
git add flake.lock
git commit -m "Bump hc-scaffold version"
git pull --rebase
git push
97 changes: 42 additions & 55 deletions .github/workflows/holonix-cache.yaml
Original file line number Diff line number Diff line change
@@ -1,92 +1,79 @@
name: "Holonix cache"

on:
# Assume pushes to these branches imply changes that should be cached. If not then the workflow run will be
# idempotent, so it won't do any harm.
push:
branches:
- develop
- main
- main-0.2
- main-0.3
# Because other things use the same cache, run once a day to make sure that the cache is up to date.
schedule:
- cron: "@daily" # run once a day
# Allow the cache update to be run manually.
workflow_dispatch:
inputs: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
# ensures the cache is regularly updated for the supported versions on multiple platforms
cache-update:
strategy:
fail-fast: false
matrix:
target:
- "github:holochain/holochain#packages.{0}.build-holonix-tests-integration"
- "github:holochain/holochain#devShells.{0}.holonix"
extra_args:
- ""
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_2"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_2_rc"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_3_rc"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/weekly"
platform:
- x86_64-darwin
- aarch64-darwin
- x86_64-linux
os: [ ubuntu-latest, macos-latest, macos-13 ]
branch: [ main, main-0.2, main-0.3 ]

runs-on: [self-hosted, multi-arch]
steps:
- name: Print matrix
env:
MATRIX: ${{ toJSON(matrix) }}
run: echo ${MATRIX}
runs-on: ${{ matrix.os }}

- name: "Cache packages ${{ matrix.extra_args }}"
steps:
- uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.22.1/install
- uses: cachix/cachix-action@v15
with:
name: holochain-ci
- name: Cache default Holonix flake on [${{ matrix.branch }}]
env:
NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
CACHIX_AUTH_TOKEN: "${{ secrets.CACHIX_AUTH_TOKEN_HOLOCHAIN_CI }}"
# NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
CACHIX_AUTH_TOKEN: "${{ secrets.CACHIX_AUTH_TOKEN }}"
run: |
set -xe
target=${{ matrix.target }}
# Create a workspace and initialise a new default Holonix flake
cd $(mktemp -d)
nix flake init -t "github:holochain/holonix/${{ matrix.branch }}#holonix-default" # TODO
# See https://docs.cachix.org/pushing#id1
nix develop --build -L --profile result-develop \
${{ matrix.extra_args }} \
${{ format(matrix.target, matrix.platform) }}
nix develop --build -L --profile result-develop
nix build -L --profile result-build \
${{ matrix.extra_args }} \
${{ format(matrix.target, matrix.platform) }}
nix build -L --profile result-build
# Don't exit if this fails so we can clean up the profile
# Push both results to the cache
for i in result-*; do
cachix push holochain-ci $i || true
cachix push holochain-ci $i
done
rm result*
cache-check:
needs:
- cache-update
strategy:
fail-fast: false
matrix:
target:
- "github:holochain/holochain#devShells.{0}.holonix"
- "github:holochain/holochain#packages.{0}.hc-scaffold"
extra_args:
- ""
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_2"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_2_rc"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/0_3_rc"
- "--refresh --override-input versions github:holochain/holochain?dir=versions/weekly"
platform:
- x86_64-darwin
- aarch64-darwin
- x86_64-linux
os: [ ubuntu-latest, macos-latest, macos-13 ]
branch: [ main, main-0.2, main-0.3 ]
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v26
- uses: cachix/cachix-action@v14
- uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.22.1/install
- uses: cachix/cachix-action@v15
with:
name: holochain-ci
- name: Check the Holonix cache
uses: holochain/nix-cache-check@v1
env:
NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
# env:
# NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
with:
derivation: ${{ format(matrix.target, matrix.platform) }}
extra_build_args: ${{ matrix.extra_args }}
derivation: "github:holochain/holonix/${{ matrix.branch }}" # The default shell in the Holonix flake
82 changes: 82 additions & 0 deletions scripts/bump-holochain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Bump script to update the Holochain version in flake.nix
# Usage: ./scripts/bump-holochain.sh [branch] [apply]
#
# The branch and apply arguments are only for testing. The branch can be set to any branch which would be expected to
# exist in this repository and the apply argument can be set to false to prevent modifications to the flake.nix file.
#
# Method:
# - Uses the current branch to work out what version of Holochain to look for.
# - Picks a search pattern for a Holochain tag based on the branch.
# - Searches for all Holochain tags and filters them by the search pattern.
# - Picks the latest matching tag.
# - If apply is not provided, or is true: Updates the flake.nix file to use the latest matching tag.
# - If apply is not provided, or is true: Updates the flake lock to match the new flake.nix file.
# - If apply is false: Prints the tag that would have been used to update the flake.

set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

if [ ! -f "./flake.nix" ]; then
echo "File not found: ./flake.nix"
exit 1
fi

CURRENT_BRANCH=${1:-$(git branch --show-current)}

SEARCH_PATTERN="no-tag"
case $CURRENT_BRANCH in
main)
SEARCH_PATTERN="^holochain-0.4.[0-9]+-dev.[0-9]+$"
;;
main-*-rc)
VERSION_STR=$(echo "$CURRENT_BRANCH" | awk -F '-' '{print $2}')

# Protect against this code trying to bump 1.2.3 versions if one of those shows up.
SEP_COUNT=$(echo "$VERSION_STR" | tr -d -c '.' | awk '{ print length; }')
if [ "$SEP_COUNT" -ne "1" ]; then
echo "Invalid version format: $VERSION_STR"
exit 1
fi

SEARCH_PATTERN=$(echo "$VERSION_STR" | awk -F '.' 'BEGIN { OFS="" } {print "^holochain-", $1, ".", $2, ".[0-9]+-rc.[0-9]+$"}')
;;
main-*)
VERSION_STR=$(echo "$CURRENT_BRANCH" | awk -F '-' '{print $2}')

# Protect against this code trying to bump 1.2.3 versions if one of those shows up.
SEP_COUNT=$(echo "$VERSION_STR" | tr -d -c '.' | awk '{ print length; }')
if [ "$SEP_COUNT" -ne "1" ]; then
echo "Invalid version format: $VERSION_STR"
exit 1
fi

SEARCH_PATTERN=$(echo "$VERSION_STR" | awk -F '.' 'BEGIN { OFS="" } {print "^holochain-", $1, ".", $2, ".[0-9]+$"}')
;;
*)
echo "Not on branch main or main-X.Y, skipping for branch [${CURRENT_BRANCH}]"
exit 0
;;
esac

echo "Looking for tags matching pattern: $SEARCH_PATTERN"

ALL_HOLOCHAIN_TAGS=$(git -c 'versionsort.suffix=-beta-dev' -c 'versionsort.suffix=-dev' -c 'versionsort.suffix=-rc' ls-remote -q --tags --sort='v:refname' https://github.com/holochain/holochain.git | cut --delimiter='/' --fields=3)
LATEST_MATCHING_TAG=$(echo "$ALL_HOLOCHAIN_TAGS" | grep -E "$SEARCH_PATTERN" | tail -n 1)

if [ -z "$LATEST_MATCHING_TAG" ]; then
echo "No matching tag found for: $VERSION_STR"
exit 1
fi

echo "Latest matching tag: $LATEST_MATCHING_TAG"

APPLY=${2:-true}
if [ "$APPLY" == "true" ]; then
sed --in-place "s#url = \"github:holochain/holochain/.*\";#url = \"github:holochain/holochain/${LATEST_MATCHING_TAG}\";#" ./flake.nix
nix flake update holochain
else
printf "Would have updated flake.nix to use: \n%s\n" "$LATEST_MATCHING_TAG"
fi
11 changes: 11 additions & 0 deletions scripts/ci-git-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -eu

if ! (
(git config --global user.email && git config --global user.name) ||
(git config --local user.email && git config --local user.name)
); then
git config --local user.email "[email protected]"
git config --local user.name "Holochain Release Automation"
fi

0 comments on commit 58ba7b5

Please sign in to comment.