Skip to content

Commit

Permalink
ci: rework CI script for more extensibility
Browse files Browse the repository at this point in the history
Rework script for more flexibility and extensibility:

* Run any command in a container with `--docker` or in the current
  environment without this parameter.
* Split compiling circuits and producing constraint & table, because
  further work with proof market requires the constraint only.
  Run each command as a separate step in CI.
* Use single script for all commands. New commands with the
  proof-market-toolchain will use the same syntax.

The new script syntax is heavily inspired by
https://github.com/NilFoundation/dbms/blob/master/scripts/ci.sh

Follow-up to #5
  • Loading branch information
NickVolynkin committed Jun 15, 2023
1 parent cb2d4cb commit d64c5f9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 56 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ concurrency:
format('{0}/{1}', github.workflow, github.ref) }}
cancel-in-progress: true

env:
SCRIPT_NAME: docker-run.sh

jobs:
test-ll-workflow:
test-zkllvm-workflow:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Run the workflow script
run: scripts/${{ env.SCRIPT_NAME }}
- name: Compile a circuit
run: scripts/ci.sh --docker compile

- name: Make constraint and assignment table
run: scripts/ci.sh --docker run_assigner
31 changes: 0 additions & 31 deletions scripts/build-circuit-ll.sh

This file was deleted.

95 changes: 95 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -euxo pipefail

# define dirs so that we can run scripts from any directory without shifting filesystem paths
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REPO_ROOT="$SCRIPT_DIR/.."

# podman is a safer option for using on CI machines
if ! command -v podman; then
DOCKER="docker"
DOCKER_OPTS=""
else
DOCKER="podman"
DOCKER_OPTS='--detach-keys= --userns=keep-id'
fi

# checking files that should be produced
# on all steps of the pipeline
check_file_exists() {
FILE1="${1}"
if [ ! -e "$FILE1" ]
then
echo "File $FILE1 was not created" >&2
exit 1
else
echo "File $FILE1 created successfully"
fi
}

compile() {
if [ "$USE_DOCKER" = true ] ; then
cd "$REPO_ROOT"
$DOCKER run $DOCKER_OPTS \
--rm \
--platform=linux/amd64 \
--user $(id -u ${USER}):$(id -g ${USER}) \
--volume $(pwd):/opt/zkllvm-template \
ghcr.io/nilfoundation/zkllvm-template:latest \
sh -c "bash ./scripts/ci.sh compile"
cd -
else
rm -rf "$REPO_ROOT/build"
mkdir -p "$REPO_ROOT/build"
cd "$REPO_ROOT/build"
cmake -DCIRCUIT_ASSEMBLY_OUTPUT=TRUE ..
make template
cd -
check_file_exists "$REPO_ROOT/build/src/template.ll"
fi
}

run_assigner() {
if [ "$USE_DOCKER" = true ] ; then
cd "$REPO_ROOT"
$DOCKER run $DOCKER_OPTS \
--rm \
--platform=linux/amd64 \
--user $(id -u ${USER}):$(id -g ${USER}) \
--volume $(pwd):/opt/zkllvm-template \
ghcr.io/nilfoundation/zkllvm-template:latest \
sh -c "bash ./scripts/ci.sh run_assigner"
cd -
else
cd "$REPO_ROOT/build"
assigner \
-b src/template.ll \
-i ../src/main.inp \
-c template.crct \
-t template.tbl \
-e pallas
cd -
check_file_exists "$REPO_ROOT/build/template.crct"
check_file_exists "$REPO_ROOT/build/template.tbl"
fi
}


USE_DOCKER=false
SUBCOMMAND=run_all

while [[ "$#" -gt 0 ]]; do
case $1 in
-d|--docker) USE_DOCKER=true ;;
all) SUBCOMMAND=run_all ;;
compile) SUBCOMMAND=compile ;;
run_assigner) SUBCOMMAND=run_assigner ;;
make_statement) SUBCOMMAND=make_statement ;;
prove) SUBCOMMAND=prove ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

echo "Running ${SUBCOMMAND}"
$SUBCOMMAND
19 changes: 0 additions & 19 deletions scripts/docker-run.sh

This file was deleted.

0 comments on commit d64c5f9

Please sign in to comment.