diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..3e8c454 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,32 @@ +version: 2.1 + +jobs: + release: + parameters: + resource_class: + type: string + machine: + image: ubuntu-2204:2023.04.2 + resource_class: <> + steps: + - checkout: + path: silkworm-go + - run: + command: ./silkworm-go/ci/release.sh "$CIRCLE_WORKING_DIRECTORY" 16 <> + +workflows: + version: 2 + release_linux_builder: + jobs: + - release: + name: release-x64 + resource_class: 2xlarge + filters: + tags: { only: /^release\/.+-base$/ } + branches: { ignore: /.*/ } + - release: + name: release-arm64 + resource_class: arm.2xlarge + filters: + tags: { only: /^release\/.+-base$/ } + branches: { ignore: /.*/ } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5b7ba80 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,19 @@ +name: Release + +on: + workflow_dispatch: + # push: + # tags: + # - release/*-base + +jobs: + release: + runs-on: macos-13 + # runs-on: macos-13-xlarge # M1 CPU runner requires billing setup + steps: + - uses: actions/checkout@v3 + - run: ./ci/release_branch.sh + - name: release-macos + run: | + sudo xcode-select -s /Applications/Xcode_15.0.app + ./ci/release.sh "${{runner.workspace}}" 2 $(git branch --show-current)-base diff --git a/ci/release.sh b/ci/release.sh new file mode 100755 index 0000000..b608a7b --- /dev/null +++ b/ci/release.sh @@ -0,0 +1,161 @@ +#!/bin/bash + +set -e +set -u +set -o pipefail + +SRC_GIT_URL="https://github.com/battlmonstr/silkworm.git" +TARGET="silkworm_capi" +FINAL_LIB_COUNT=3 + +function release_tag { + base_tag="$1" + base_tag=${base_tag#release/} # cut prefix + base_tag=${base_tag%-base} # cut suffix + echo "$base_tag" +} + +function os_name { + value=$(uname -s) + case $value in + Linux) + echo linux;; + Darwin) + echo macos;; + *) + echo "unsupported OS: $value" + exit 1;; + esac +} + +function arch_name { + value=$(uname -m) + case $value in + arm64) + echo arm64;; + aarch64) + echo arm64;; + x86_64) + echo x64;; + *) + echo "unsupported CPU architecture: $value" + exit 1;; + esac +} + +work_dir="$1" +make_jobs="$2" +base_tag="$3" + +checkout_dir="$work_dir/silkworm-go" +project_dir="$work_dir/silkworm" +build_dir="$work_dir/build" +product_dir="$build_dir/silkworm/capi" +tag=$(release_tag "$base_tag") + +function checkout { + src_tag="capi-$tag" + echo "checkout tag $src_tag to $project_dir ..." + git clone --branch "$src_tag" --depth 1 \ + --recurse-submodules \ + --config submodule.ethereum-tests.update=none \ + --config submodule.LegacyTests.update=none \ + "$SRC_GIT_URL" "$project_dir" + echo "checkout done" + echo +} + +function build_setup { + echo "build_setup..." + pip3 install --user --disable-pip-version-check conan==1.62.0 chardet + conan_path="$(python3 -m site --user-base)/bin" + export "PATH=$conan_path:$PATH" + conan --version + echo "build_setup done" + echo +} + +function build { + echo "build target $TARGET in $build_dir ..." + cmake -B "$build_dir" -S "$project_dir" + cmake --build "$build_dir" --target "$TARGET" --parallel "$make_jobs" + ls -l "$product_dir/"*$TARGET* + echo "build done" + echo +} + +function build_fake { + echo "build_fake target $TARGET in $build_dir ..." + case $(os_name) in + linux) + product_file_ext=so ;; + macos) + product_file_ext=dylib ;; + esac + mkdir -p "$product_dir" + echo hello > "$product_dir/lib${TARGET}.$product_file_ext" + ls -l "$product_dir/"*$TARGET* + echo "build_fake done" + echo +} + +function upload { + product_path=$(echo "$product_dir/"*$TARGET*) + product_file_name=$(basename "$product_path") + release_branch="release/$tag" + echo "upload $product_file_name to $release_branch branch ..." + + product_file_name_base=${product_file_name%.*} + product_file_ext=${product_file_name##*.} + upload_file_name="${product_file_name_base}_$(os_name)_$(arch_name).$product_file_ext" + cp "$product_path" "$checkout_dir/lib/$upload_file_name" + + cd "$checkout_dir" + git fetch origin "$release_branch" + if ! git branch | grep "$release_branch" > /dev/null + then + git checkout --track "origin/$release_branch" + fi + git pull + git add "lib/$upload_file_name" + git commit -m "$upload_file_name" + git push + + echo "upload done" + echo +} + +function finalize { + echo "finalize..." + cd "$checkout_dir" + + lib_count=$(($(ls -1 lib | wc -l) - 1)) + if [[ $lib_count != $FINAL_LIB_COUNT ]] + then + echo "finalize skipped, waiting for $(( $FINAL_LIB_COUNT - $lib_count )) more builder(s)" + echo + return + fi + + cp "$project_dir/silkworm/capi/silkworm.h" include/ + git add include + git commit -m 'include' + git push + + git tag --delete "$base_tag" + git push --delete origin "$base_tag" + git push --delete origin "release/$tag" + + git tag "$tag" + git push --tags + + echo "finalize done" + echo +} + +checkout +build_setup +#build +build_fake +upload +finalize diff --git a/ci/release_branch.sh b/ci/release_branch.sh new file mode 100755 index 0000000..ff69135 --- /dev/null +++ b/ci/release_branch.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +SRC_GIT_URL="https://github.com/battlmonstr/silkworm.git" + +function release_tag { + git ls-remote --tags "$SRC_GIT_URL" | grep 'capi-' | cut -d '-' -f 2 | while read tag + do + if ! git ls-remote --heads | grep "release/$tag" > /dev/null + then + echo $tag + break + fi + done +} + +tag=$(release_tag) + +if [[ -z "$tag" ]] +then + echo "release tag not found" + exit 1 +fi + +branch="release/$tag" +base_tag="${branch}-base" + +echo "release tag: $tag" +echo "release branch: $branch" +echo "release base tag: $base_tag" + +git checkout -b "$branch" +git push --set-upstream origin "$branch" + +git tag "$base_tag" +git push --tags diff --git a/include/readme.txt b/include/readme.txt new file mode 100644 index 0000000..337a2b4 --- /dev/null +++ b/include/readme.txt @@ -0,0 +1 @@ +header files diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..1aa3ee1 --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1 @@ +libraries