Skip to content

Commit

Permalink
Wrap the apicurio-client-gen distribution mechanism (Apicurio#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored Sep 6, 2023
1 parent f3c74ea commit ca64cdf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
1 change: 1 addition & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ yarn-error.log
node_modules
dist
node
resources/client-gen*
Binary file removed ui/resources/client-gen-0.1.0.zip
Binary file not shown.
53 changes: 45 additions & 8 deletions ui/resources/download-client-gen-dist.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
#!/bin/bash
set -euo pipefail

VERSION="0.1.0"

URL="https://github.com/Apicurio/apicurio-client-gen/releases/download/$VERSION/dist.zip"
# Usage:
# - no env vars exported -> download from public GH releases
# - `APICURIO_CLIENT_GEN_VERSION` -> Use a specific version instead of the default
# - `APICURIO_CLIENT_GEN_URL` -> completely override the download URL diregarding the version
# - `APICURIO_CLIENT_GEN_FRESH` -> forcefully download from remote the distribution archive

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

OUTPUT_FILE="$SCRIPT_DIR/client-gen-$VERSION.zip"
VERSION="${APICURIO_CLIENT_GEN_VERSION-"0.1.2"}"
echo "Using version: ${VERSION}"

UPSTREAM_DIST_URL="https://github.com/Apicurio/apicurio-client-gen/releases/download/${VERSION}/dist.tar.gz"

if [[ -z "${APICURIO_CLIENT_GEN_URL-}" ]]; then
echo "Downloading from upstream github"
URL="${UPSTREAM_DIST_URL}"
else
echo "Downloading using custom url"
URL="${APICURIO_CLIENT_GEN_URL}"
fi

if [[ -z "${APICURIO_CLIENT_GEN_FRESH-}" ]]; then
echo "Attempting to use cached resources"
else
echo "Running a fresh download"
rm -f $SCRIPT_DIR/client-gen.tar.gz
fi

if [ -f "$SCRIPT_DIR/client-gen.tar.gz" ]; then
echo "Using cached version of client-gen.tar.gz"
else
echo "Fetching archive from ${URL}"

OUTPUT_FILE="$SCRIPT_DIR/client-gen.tar.gz"

STATUS_CODE=$(curl -sLS -o "$OUTPUT_FILE" --write-out "%{http_code}" "$URL")
STATUS_CODE=$(curl -sLS -o "$OUTPUT_FILE" --write-out "%{http_code}" "$URL")

if [[ "$STATUS_CODE" -lt 200 || ${STATUS_CODE} -gt 299 ]]; then
echo "Could not download $URL. Got HTTP code $STATUS_CODE."
exit 1
if [[ "${STATUS_CODE}" -lt 200 || "${STATUS_CODE}" -gt 299 ]]; then
echo "Could not download $URL. Got HTTP code $STATUS_CODE."
exit 1
fi
fi

echo "Deleting client-gen/dist ..."
rm -rf "$SCRIPT_DIR/../client-gen/dist"

echo "Extracting client-gen.tar.gz ..."

tar -xvf "$SCRIPT_DIR/client-gen.tar.gz" -C "$SCRIPT_DIR/../client-gen"

echo "Done!"
12 changes: 3 additions & 9 deletions ui/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ process.argv.forEach(arg => {

module.exports = (env, argv) => {
const isProduction = argv && argv.mode === "production";
const clientGenVersion = "0.1.0" // Use resources/download-client-gen-dist.sh to update
console.info("Is production build? %o", isProduction);
return {
entry: {
Expand Down Expand Up @@ -91,16 +90,11 @@ module.exports = (env, argv) => {
plugins: [
new WebpackShellPluginNext({
onBuildStart:{
scripts: [
'echo Deleting client-gen/dist...',
'rm -rf client-gen/dist',
'echo Unzipping client-gen-' + clientGenVersion + '.zip...',
'unzip -q resources/client-gen-' + clientGenVersion + '.zip -d client-gen',
'echo Done!'
],
scripts: [ 'resources/download-client-gen-dist.sh' ],
blocking: true,
parallel: false
}
},
safe: true,
}),
new CopyPlugin({
patterns: [
Expand Down

0 comments on commit ca64cdf

Please sign in to comment.