mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-01 03:36:04 +08:00
ci: add release build script
Signed-off-by: andy.lee <andy.lee@suse.com>
This commit is contained in:
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -x
|
||||
|
||||
BUILD_DEBUG="${BUILD_DEBUG:-}"
|
||||
if [[ -n "${BUILD_DEBUG}" ]]; then
|
||||
set -x
|
||||
env
|
||||
fi
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
echo "Bootstrapping..."
|
||||
yarn --pure-lockfile install
|
||||
|
||||
source scripts/version
|
||||
echo "BRANCH: ${COMMIT_BRANCH:-<none>}"
|
||||
echo "TAG: ${GIT_TAG:-<none>}"
|
||||
DIR=${GIT_TAG:-$COMMIT_BRANCH}
|
||||
|
||||
OUTPUT_DIR=dist/${DIR}-embedded
|
||||
|
||||
echo "Building..."
|
||||
COMMIT=${COMMIT} VERSION=${VERSION} OUTPUT_DIR=$OUTPUT_DIR ROUTER_BASE='/dashboard/' RESOURCE_BASE='/dashboard/' RANCHER_ENV=harvester yarn run build
|
||||
|
||||
if [ -v EMBED_PKG ]; then
|
||||
echo "Build and embed plugin from: $EMBED_PKG"
|
||||
PKG_FILE_NAME=${EMBED_PKG##*/}
|
||||
echo PKG_FILE_NAME: $PKG_FILE_NAME
|
||||
|
||||
PKG_NAME="${PKG_FILE_NAME/.tar.gz/""}"
|
||||
echo "Plugin name: '$PKG_NAME'"
|
||||
|
||||
# Fetch file, unpack and move to dist
|
||||
curl $EMBED_PKG --output $PKG_FILE_NAME
|
||||
OUTPUT_DIR_PKG=$OUTPUT_DIR/$PKG_NAME
|
||||
mkdir -p $OUTPUT_DIR_PKG
|
||||
tar xvfz $PKG_FILE_NAME -C $OUTPUT_DIR/$PKG_NAME
|
||||
echo "Plugin contents that will be served from $PKG_NAME"
|
||||
ls -alR $OUTPUT_DIR/$PKG_NAME
|
||||
fi
|
||||
|
||||
echo "Destroying..."
|
||||
find $OUTPUT_DIR -name "index.html" -mindepth 2 -exec rm {} \;
|
||||
find $OUTPUT_DIR -type d -empty -depth -exec rmdir {} \;
|
||||
|
||||
TARBALL=${DIR}.tar.gz
|
||||
TARBALL_FILE_PATH=dist/${TARBALL}
|
||||
|
||||
ENV_OUTPUT="${GITHUB_OUTPUT:-"temp-env"}"
|
||||
echo "BUILD_EMBEDED_TGZ=${TARBALL_FILE_PATH}" >> "$ENV_OUTPUT"
|
||||
|
||||
echo "Compressing to ${TARBALL}..."
|
||||
tar -czf ${TARBALL_FILE_PATH} $OUTPUT_DIR/
|
||||
|
||||
echo "Cleaning up..."
|
||||
rm -r $OUTPUT_DIR
|
||||
|
||||
ls -alR dist/
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BUILD_DEBUG="${BUILD_DEBUG:-}"
|
||||
if [[ -n "${BUILD_DEBUG}" ]]; then
|
||||
set -x
|
||||
env
|
||||
fi
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
echo "Bootstrapping..."
|
||||
yarn --pure-lockfile install
|
||||
|
||||
source scripts/version
|
||||
echo "BRANCH: ${COMMIT_BRANCH:-<none>}"
|
||||
echo "TAG: ${GIT_TAG:-<none>}"
|
||||
DIR=${GIT_TAG:-$COMMIT_BRANCH}
|
||||
|
||||
if [[ "${DIR}" == "master" ]]; then
|
||||
DIR="latest"
|
||||
fi
|
||||
|
||||
BASE=${BASE:-https://releases.rancher.com/harvester-ui/dashboard/${DIR}}
|
||||
|
||||
echo "Building for ${BASE}..."
|
||||
|
||||
OUTPUT_DIR=dist/${DIR}
|
||||
|
||||
ENV_OUTPUT="${GITHUB_OUTPUT:-"temp-env"}"
|
||||
echo "BUILD_HOSTED_DIR=${OUTPUT_DIR}" >> "$ENV_OUTPUT"
|
||||
echo "BUILD_HOSTED_LOCATION=${DIR}" >> "$ENV_OUTPUT"
|
||||
|
||||
COMMIT=${COMMIT} VERSION=${VERSION} OUTPUT_DIR=${OUTPUT_DIR} ROUTER_BASE="/dashboard/" RESOURCE_BASE="${BASE}" RANCHER_ENV=harvester yarn run build
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)/..
|
||||
|
||||
BUILD_DEBUG="${BUILD_DEBUG:-}"
|
||||
if [[ -n "${BUILD_DEBUG}" ]]; then
|
||||
set -x
|
||||
env
|
||||
fi
|
||||
|
||||
if [[ -n "$CI_BUILD_TAG" ]]; then
|
||||
echo "Build has been triggered by a tag. Skipping gate"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z "$CI_BRANCH" ]]; then
|
||||
echo "No branch detected. Skipping gate"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z "$GIT_REPO" ]]; then
|
||||
echo "No repository detected. Unable to gate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$GIT_COMMIT" ]]; then
|
||||
echo "No commit detected. Unable to gate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Repo: $GIT_REPO"
|
||||
echo "Branch: $CI_BRANCH"
|
||||
echo "Build Commit: $GIT_COMMIT"
|
||||
|
||||
tmp=$(mktemp -u)
|
||||
STATUS_CODE=$(curl -w "%{http_code}" -s -o $tmp https://api.github.com/repos/$GIT_REPO/branches/$CI_BRANCH)
|
||||
|
||||
if [ "$STATUS_CODE" == "403" ]; then
|
||||
RATE_LIMIT_REMAINING=$(curl -s https://api.github.com/rate_limit | ./scripts/jq-nano - rate remaining)
|
||||
echo "Remaining GITHUB requests available: $RATE_LIMIT_REMAINING"
|
||||
RATE_LIMIT_REMAINING=${RATE_LIMIT_REMAINING:-0}
|
||||
if ((RATE_LIMIT_REMAINING < 1)); then
|
||||
echo "Github Rate Limit has been hit, skipping gate"
|
||||
exit 0
|
||||
fi
|
||||
# Fall through to the normal path like any other failed status code
|
||||
fi
|
||||
|
||||
LATEST_BRANCH_COMMIT=$(cat $tmp | ./scripts/jq-nano - commit sha)
|
||||
rm $tmp
|
||||
echo "Latest Branch Commit: $LATEST_BRANCH_COMMIT"
|
||||
if [ -z "$LATEST_BRANCH_COMMIT" ]; then
|
||||
echo "Unable to determine latest commit, failing gate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$LATEST_BRANCH_COMMIT" == "$GIT_COMMIT" ]; then
|
||||
echo "Build was created from latest commit, passed upload gate"
|
||||
else
|
||||
echo "Build was not created from latest commit, failing gate"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user