Skip to content

Commit

Permalink
[CI] Bundling demos as release asset (#5550)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniels290813 committed May 15, 2024
1 parent 6a5d8eb commit b7053f4
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,24 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: mlrun-tutorials.tar
prerelease: ${{ needs.prepare-inputs.outputs.is_stable_version == 'false' }}

update-demos:
name: Bundle demos
needs: [ prepare-inputs, create-releases ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install prerequisits
run: |
pip install gitpython
- name: Create mlrun demos tar
run: |
python automation/scripts/bundle_demos.py
- name: Add mlrun-demos tar to release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: v${{ needs.prepare-inputs.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: mlrun-demos.tar
prerelease: ${{ needs.prepare-inputs.outputs.is_stable_version == 'false' }}
61 changes: 61 additions & 0 deletions automation/scripts/bundle_demos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2019 Iguazio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import shutil
import tarfile

from git import Repo

# List of repositories to archive
repos = [
{"url": "https://github.com/mlrun/demo-azure-ML.git", "name": "demo-azure-ML"},
{"url": "https://github.com/mlrun/demo-fraud.git", "name": "demo-fraud"},
{
"url": "https://github.com/mlrun/demo-mask-detection.git",
"name": "demo-mask-detection",
},
# Add more repositories as needed
]

# Directory where repositories will be cloned and extracted
temp_dir = "demos"

# Create the temporary directory if it doesn't exist
os.makedirs(temp_dir, exist_ok=True)

# Clone each repository and extract its contents to the temporary directory
for repo_info in repos:
print(f"cloning {repo_info['url']} with name {repo_info['name']} to {temp_dir}")
repo_url = repo_info["url"]
repo_name = repo_info["name"]

# Clone the repository
try:
repo = Repo.clone_from(repo_url, os.path.join(temp_dir, repo_name))
except Exception as e:
print(f"could not clone repo {repo_url}")
print(e)

# Copying update_demos.sh from mlrun
shutil.copyfile("automation/scripts/update_demos.sh", "demos/update_demos.sh")

# Create a tar archive of the temporary directory
with tarfile.open("mlrun-demos.tar", "w") as tar:
tar.add(temp_dir, arcname=os.path.basename(temp_dir))

print("Archive created successfully!")

# Cleanup: Delete the temporary directory
shutil.rmtree(temp_dir)
64 changes: 64 additions & 0 deletions automation/scripts/update_demos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 Iguazio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
error_exit()
{

# ----------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument:
# string containing descriptive error message
# ----------------------------------------------------------------
echo "${SCRIPT}: ${1:-"Unknown Error"}" 1>&2
exit 1
}

user=${V3IO_USERNAME}
demos_dir=$(echo "/v3io/users/${user}")
pip_mlrun=$(pip show mlrun | grep Version)

# Grepping mlrun version
if [ -z "${pip_mlrun}" ]; then
error_exit "MLRun version not found. Aborting..."
fi

# Extracting mlrun version and adding "-" between version prefix and rc
mlrun_version=$(echo "${pip_mlrun##Version: }" | sed 's/\([0-9]\)rc/\1-rc/')
echo "Detected MLRun version: ${mlrun_version}"

# Verifying mlrun >= 1.7
tag_prefix=`echo ${mlrun_version} | cut -d . -f1-2`
if [[ "${tag_prefix}" < "1.7" ]]; then
error_exit "MLRun version must be 1.7 or above, for older updates run: sh https://raw.githubusercontent.com/mlrun/demos/v1.6.0/update_demos.sh .Aborting..."
fi

# copy & remove old demos folder
dt=$(date '+%Y%m%d%H%M%S');
old_demos_dir="${HOME}/demos.old/${dt}"
demos_dir="${HOME}/demos"
echo "Moving existing '${demos_dir}' to ${old_demos_dir}'..."
mkdir -p "${old_demos_dir}"
cp -r "${demos_dir}/." "${old_demos_dir}" && rm -rf "${demos_dir}"

# Making of git url that holds tar asset
# e.g. https://github.com/mlrun/mlrun/releases/download/v1.7.0-rc3/mlrun-demos.tar
tar_url=$(echo "https://github.com/mlrun/mlrun/releases/download/v${mlrun_version}/mlrun-demos.tar")

# Downloading & extracting tar
wget ${tar_url}
mkdir ${demos_dir}
tar -xvf mlrun-demos.tar -C ${demos_dir} --strip-components 1

# Cleaning
rm -rf demos.tar

0 comments on commit b7053f4

Please sign in to comment.