Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Created May 26, 2023 04:49
Show Gist options
  • Save sadiqsalau/a734a9f51ce2eb12e36e068000d06672 to your computer and use it in GitHub Desktop.
Save sadiqsalau/a734a9f51ce2eb12e36e068000d06672 to your computer and use it in GitHub Desktop.
Cpanel Download Github Release
---
deployment:
tasks:
# If .deploy.conf doesn't exist, create it from .deploy.example.conf
- |
if [ ! -f .deploy.conf ]
then
cp .deploy.example.conf .deploy.conf
exit
else
source .deploy.conf
fi
# Set variables
- |
GH_API="https://api.github.com"
GH_API_REPO="$GH_API/repos/$GITHUB_OWNER/$GITHUB_REPO"
GH_API_AUTH="Authorization: Bearer $GITHUB_TOKEN"
# Fetch the latest release information from the GitHub repository
- |
RELEASE_JSON=$(
curl \
-H "$GH_API_AUTH" \
-H "Accept: application/vnd.github.v3+json" \
"$GH_API_REPO/releases/latest"
)
# Extract asset id
- |
ASSET_ID=$(
echo "$RELEASE_JSON" |
grep -C3 "\"name\": \"$RELEASE_ASSET_NAME\"" |
grep -w "\"id\"" |
cut -d':' -f2 |
tr -d '[:space:],'
)
# Download build
- |
curl \
-H "$GH_API_AUTH" \
-H "Accept: application/octet-stream" \
-LJO "$GH_API_REPO/releases/assets/$ASSET_ID"
# Create deployment path if it doesn't exist
- if [ ! -d "$DEPLOY_PATH" ]; then mkdir -p "$DEPLOY_PATH"; fi
# Unzip the downloaded asset
- unzip -o "$RELEASE_ASSET_NAME" -d $DEPLOY_PATH
# Clean up the downloaded file
- rm "$RELEASE_ASSET_NAME"
export GITHUB_TOKEN=
export GITHUB_OWNER=
export GITHUB_REPO=
export RELEASE_ASSET_NAME="build.zip"
export DEPLOY_PATH=~/public_html
.deploy.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment