Skip to content

Commit

Permalink
ci: added skip-cache option
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed May 2, 2024
1 parent 210e333 commit 4e0b593
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .tekton/listeners/esm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
value: "true"
- name: context
value: "node-$(params.node-version)-esm"
- name: skip-cache
value: $(params.skip-cache)

---

Expand Down
4 changes: 3 additions & 1 deletion .tekton/listeners/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ spec:
- name: pl-name
value: $(event.after)
- name: pipeline-ref
value: "default-pipeline"
value: "default-pipeline"
- name: skip-cache
value: $(params.skip-cache)

---

Expand Down
2 changes: 2 additions & 0 deletions .tekton/listeners/node-x-manual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ spec:
value: "default-pipeline"
- name: esm
value: $(params.esm)
- name: skip-cache
value: $(params.skip-cache)

---

Expand Down
2 changes: 2 additions & 0 deletions .tekton/listeners/node-x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
value: "nightly-$(params.node-version)"
- name: pipeline-ref
value: "default-pipeline"
- name: skip-cache
value: $(params.skip-cache)

---

Expand Down
2 changes: 2 additions & 0 deletions .tekton/listeners/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ spec:
value: $(event.pull_request.number)
- name: pipeline-ref
value: "default-pipeline"
- name: skip-cache
value: $(params.skip-cache)

---

Expand Down
2 changes: 2 additions & 0 deletions .tekton/pipeline/currency-bot-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ spec:
value: $(params.node-version)
- name: npm-version
value: $(params.npm-version)
- name: skip-cache
value: "false"
workspaces:
- name: output
workspace: artifacts
Expand Down
6 changes: 5 additions & 1 deletion .tekton/pipeline/default-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
value: $(params.coverage)
- name: context
value: $(params.context)
- name: skip-cache
value: $(params.skip-cache)
workspaces:
- name: artifacts
tasks:
Expand Down Expand Up @@ -124,7 +126,9 @@ spec:
- name: node-version
value: $(params.node-version)
- name: npm-version
value: $(params.npm-version)
value: $(params.npm-version)
- name: skip-cache
value: $(params.skip-cache)
workspaces:
- name: output
workspace: artifacts
Expand Down
7 changes: 6 additions & 1 deletion .tekton/pipeline/trigger-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ spec:
- name: coverage
default: "false"
value: $(params.coverage)
- name: skip-cache
default: "false"
value: $(params.skip-cache)
- name: context
default: "node-$(params.node-version)"
value: $(params.context)
Expand Down Expand Up @@ -116,4 +119,6 @@ spec:
- name: coverage
value: $(params.coverage)
- name: context
value: $(params.context)
value: $(params.context)
- name: skip-cache
value: $(params.skip-cache)
148 changes: 78 additions & 70 deletions .tekton/tasks/install-npm-dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ spec:
- name: node-version
value: $(params.node-version)
- name: npm-version
value: $(params.npm-version)
value: $(params.npm-version)
- name: skip-cache
value: $(params.skip-cache)
workspaces:
- name: output
mountPath: /artifacts
Expand All @@ -34,109 +36,115 @@ spec:
if [ -n "$(params.npm-version)" ]; then
npm install npm@$(params.npm-version) -g
fi
fi
echo "Restoring node_modules cache..."
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud plugin install cloud-object-storage -f -r 'IBM Cloud'
ibmcloud login -a https://cloud.ibm.com -r eu-de --apikey $API_KEY
apt-get update -y
apt-get install zstd -y
checksum=$(sha256sum package-lock.json | awk '{print $1}')
ibmcloud cos download --bucket npm-cache --key node-modules-$(params.target-branch)-$(params.node-version)-$checksum ./node-modules.tar.zst
# Check the exit code of the download command
if [ $? -eq 0 ]; then
npmInstall=false
echo "Download successful."
zstd -d node-modules.tar.zst -o node-modules.tar
tar -xf node-modules.tar
# Iterate over packages/*/ directories
for package_dir in packages/*; do
if [ -d "$ARTIFACTS_PATH/$package_dir" ]; then
cd $ARTIFACTS_PATH/$package_dir
package_name=$(basename "$package_dir")
# Download the cache for the specific package
pkg_name="node-modules-$(params.target-branch)-$(params.node-version)-$package_name-$checksum"
echo "Downloading cache for $pkg_name"
ibmcloud cos download --bucket npm-cache --key $pkg_name $pkg_name.tar.zst
if [ $? -eq 0 ]; then
# Decompress and extract the cache
echo "Download successful."
zstd -d $pkg_name.tar.zst -o "node-modules.tar"
tar -xf "node-modules.tar"
else
npmInstall=true
fi
fi
done
cd $ARTIFACTS_PATH
echo "npm install: $npmInstall"
if [ "$npmInstall" == true ]; then
npm install
if [ "$(params.skip-cache)" == "true" ]; then
echo "Skipping npm cache..."
echo "Installing npm dependencies..."
npm install --loglevel verbose
else
echo "Restoring node_modules cache..."
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud plugin install cloud-object-storage -f -r 'IBM Cloud'
ibmcloud login -a https://cloud.ibm.com -r eu-de --apikey $API_KEY
rm -rf node-modules.tar.zst
rm -rf node-modules.tar
fi
apt-get update -y
apt-get install zstd -y
echo "Restored node_modules cache..."
else
ibmcloud cos download --bucket npm-cache --key node-modules-main-$(params.node-version)-$checksum ./node-modules.tar.zst
checksum=$(sha256sum package-lock.json | awk '{print $1}')
ibmcloud cos download --bucket npm-cache --key node-modules-$(params.target-branch)-$(params.node-version)-$checksum ./node-modules.tar.zst
# Check the exit code of the download command
if [ $? -eq 0 ]; then
npmInstall=false
echo "Download successful. Restoring node_modules cache..."
npmInstall=false
echo "Download successful."
zstd -d node-modules.tar.zst -o node-modules.tar
tar -xf node-modules.tar
# Iterate over packages/*/ directories
for package_dir in packages/*; do
if [ -d "$ARTIFACTS_PATH/$package_dir" ]; then
cd $ARTIFACTS_PATH/$package_dir
package_name=$(basename "$package_dir")
# Download the cache for the specific package
pkg_name="node-modules-$(params.target-branch)-$(params.node-version)-$package_name-$checksum"
echo "Downloading cache for $pkg_name"
ibmcloud cos download --bucket npm-cache --key $pkg_name $pkg_name.tar.zst
echo "Downloading cache for $pkg_name"
ibmcloud cos download --bucket npm-cache --key $pkg_name $pkg_name.tar.zst
if [ $? -eq 0 ]; then
# Decompress and extract the cache
echo "Download successful."
zstd -d $pkg_name.tar.zst -o "node-modules.tar"
tar -xf "node-modules.tar"
else
npmInstall=true
fi
fi
fi
done
cd $ARTIFACTS_PATH
rm -rf node-modules.tar.zst
rm -rf node-modules.tar
echo "npm install: $npmInstall"
if [ "$npmInstall" == true ]; then
npm install --loglevel verbose
rm -rf node-modules.tar.zst
rm -rf node-modules.tar
fi
echo "Restored node_modules cache..."
else
echo "Download from main was not successful. Installing node_modules..."
npm install --loglevel verbose
ibmcloud cos download --bucket npm-cache --key node-modules-main-$(params.node-version)-$checksum ./node-modules.tar.zst
if [ $? -eq 0 ]; then
npmInstall=false
echo "Download successful. Restoring node_modules cache..."
zstd -d node-modules.tar.zst -o node-modules.tar
tar -xf node-modules.tar
# Iterate over packages/*/ directories
for package_dir in packages/*; do
if [ -d "$ARTIFACTS_PATH/$package_dir" ]; then
cd $ARTIFACTS_PATH/$package_dir
package_name=$(basename "$package_dir")
# Download the cache for the specific package
pkg_name="node-modules-$(params.target-branch)-$(params.node-version)-$package_name-$checksum"
echo "Downloading cache for $pkg_name"
ibmcloud cos download --bucket npm-cache --key $pkg_name $pkg_name.tar.zst
if [ $? -eq 0 ]; then
# Decompress and extract the cache
echo "Download successful."
zstd -d $pkg_name.tar.zst -o "node-modules.tar"
tar -xf "node-modules.tar"
else
npmInstall=true
fi
fi
done
cd $ARTIFACTS_PATH
rm -rf node-modules.tar.zst
rm -rf node-modules.tar
if [ "$npmInstall" == true ]; then
npm install --loglevel verbose
fi
echo "Restored node_modules cache..."
else
echo "Download from main was not successful. Installing node_modules..."
npm install --loglevel verbose
fi
fi
fi
fi
6 changes: 5 additions & 1 deletion .tekton/templates/default-pipeline.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
value: $(params.coverage)
- name: context
value: $(params.context)
- name: skip-cache
value: $(params.skip-cache)
workspaces:
- name: artifacts
tasks:
Expand Down Expand Up @@ -124,7 +126,9 @@ spec:
- name: node-version
value: $(params.node-version)
- name: npm-version
value: $(params.npm-version)
value: $(params.npm-version)
- name: skip-cache
value: $(params.skip-cache)
workspaces:
- name: output
workspace: artifacts
Expand Down

0 comments on commit 4e0b593

Please sign in to comment.