Skip to content

Commit

Permalink
release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr committed Nov 23, 2023
1 parent e6b0679 commit 3acc6db
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2.1

jobs:
release:
parameters:
resource_class:
type: string
machine:
image: ubuntu-2204:2023.04.2
resource_class: <<parameters.resource_class>>
steps:
- checkout:
path: silkworm-go
- run:
command: ./silkworm-go/ci/release.sh "$CIRCLE_WORKING_DIRECTORY" 16 <<pipeline.git.tag>>

workflows:
version: 2
release_linux_builder:
jobs:
- release:
name: release-x86_64
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: /.*/ }
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
129 changes: 129 additions & 0 deletions ci/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

set -e
set -u
set -o pipefail

SRC_GIT_URL="https://github.com/battlmonstr/silkworm.git"
TARGET="silkworm_capi"

function release_tag {
base_tag="$1"
base_tag=${base_tag#release/} # cut prefix
base_tag=${base_tag%-base} # cut suffix
echo "capi-$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 {
echo "checkout tag $tag to $project_dir ..."
git clone --branch "$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"
# TODO

echo "upload done"
echo
}

function finalize {
echo "finalize..."
echo "finalize done"
echo
}

checkout
build_setup
build
#build_fake
upload
finalize
35 changes: 35 additions & 0 deletions ci/release_branch.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions include/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
header files
1 change: 1 addition & 0 deletions lib/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libraries

0 comments on commit 3acc6db

Please sign in to comment.