Skip to content

Commit

Permalink
Merge pull request #1 from sfc-gh-jszczerbinski/cache-deps
Browse files Browse the repository at this point in the history
Cache deps
  • Loading branch information
sfc-gh-jszczerbinski authored Nov 21, 2024
2 parents 64e0f71 + 37c51aa commit e64586f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,31 @@ jobs:
cloud_provider: [ 'AWS', 'AZURE', 'GCP' ]
steps:
- uses: actions/checkout@v1
- name: Restore cached deps
id: cache-restore-deps
uses: actions/cache/restore@v4
with:
path: |
dep-cache/
key: ${{ matrix.build_type }}-${{ github.event.pull_request.base.sha }}-dep-cache
if: github.event_name == 'pull_request'
- name: Build
shell: bash
env:
BUILD_TYPE: ${{ matrix.build_type }}
run: ci/build_linux.sh
- name: Cache deps
id: cache-save-deps
uses: actions/cache/save@v4
with:
path: dep-cache
key: ${{ matrix.build_type }}-${{ github.sha }}-dep-cache
if: github.ref_name == github.event.repository.default_branch
- uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: 'x64'
- name: Test
shell: bash
env:
BUILD_TYPE: ${{ matrix.build_type }}
CLOUD_PROVIDER: ${{ matrix.cloud_provider }}
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
run: ci/test_linux.sh

build-test-win:
name: Build-Test-Win
runs-on: windows-2019
Expand Down
13 changes: 12 additions & 1 deletion ci/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ function download_build_component()
local component_version=$($component_script -v)
local zip_file_name=$(get_zip_file_name $component_name $component_version $build_type)
if [[ -n "$GITHUB_ACTIONS" ]]; then
"$component_script" -t "$build_type"
if cp "$CACHE_DIR/$zip_file_name" "$ARTIFACTS_DIR";
then
echo "=== using cached: $component_name ==="
pushd $DEPENDENCY_DIR >& /dev/null
tar xvfz $ARTIFACTS_DIR/$zip_file_name
popd >& /dev/null
else
echo "=== building dep: $component_name ==="
"$component_script" -t "$build_type"
cache_dependency $component_name $component_version $build_type
fi
else
echo "=== download or build $component_name ==="
ret="$(check_directory $component_name $build_type)"
Expand Down Expand Up @@ -63,6 +73,7 @@ function build_component()
echo "=== build: $component_name ==="
"$component_script" -t "$build_type" "$other_args"
local component_version=$("$component_script" -v)

if [[ -z "$GITHUB_ACTIONS" ]] && [[ -n "$GIT_BRANCH" ]]; then
upload_to_sfc_jenkins $component_name $component_version $build_type
if [[ "$GIT_BRANCH" == "origin/master" || "$GIT_BRANCH" == "master" ]]; then
Expand Down
1 change: 1 addition & 0 deletions scripts/_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export TERM=vt100
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEPS_DIR=$(cd $DIR/../deps && pwd)
ARTIFACTS_DIR=$DIR/../artifacts
CACHE_DIR="$DIR/../dep-cache"
mkdir -p $ARTIFACTS_DIR

PLATFORM=$(echo $(uname) | tr '[:upper:]' '[:lower:]')
Expand Down
17 changes: 15 additions & 2 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function zip_file()

local zip_file_name=$(get_zip_file_name "$component_name" "$component_version" "$build_type")

if [[ -z "$GITHUB_ACTIONS" ]] && [[ -n "$GIT_BRANCH" ]]; then
if [[ -n "$GIT_BRANCH" ]]; then
local f=$UTILS_DIR/../artifacts/$zip_file_name
rm -f $f
pushd $DEPENDENCY_DIR/
Expand All @@ -85,7 +85,7 @@ function zip_files()

local zip_file_name=$(get_zip_file_name "$component_name" "$component_version" "$build_type")

if [[ -z "$GITHUB_ACTIONS" ]] && [[ -n "$GIT_BRANCH" ]]; then
if [[ -n "$GIT_BRANCH" ]]; then
local f=$UTILS_DIR/../artifacts/$zip_file_name
rm -f $f
pushd $DEPENDENCY_DIR/
Expand Down Expand Up @@ -117,6 +117,18 @@ function upload_to_sfc_dev1_data()
aws s3 cp --only-show-errors $UTILS_DIR/../artifacts/$zip_file_name $DEP_URL_PREFIX/$component_name/
}

function cache_dependency()
{

local component_name=$1
local component_version=$2
local build_type=$3

local zip_file_name=$(get_zip_file_name $component_name $component_version $build_type)
mkdir -p $CACHE_DIR
cp $UTILS_DIR/../artifacts/$zip_file_name "$CACHE_DIR/"
}

function upload_to_sfc_jenkins()
{
local component_name=$1
Expand Down Expand Up @@ -180,3 +192,4 @@ function set_parameters()
exit 1
fi
}

0 comments on commit e64586f

Please sign in to comment.