Skip to content

Deploy

Deploy #161

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: [ Build ]
types: [ completed ]
push:
branches:
- 'build/**'
jobs:
Deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Merge Build Branches
run: |
CNAME='docs.commandapi.dev'
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
TARGET_BRANCH="deploy"
BASE_BRANCH="origin/build/master"
ORIGIN_URL=$(git remote get-url origin)
SUFFIX=".git"
TARGET_URL=${ORIGIN_URL%$SUFFIX}
git fetch origin
git checkout -b ${TARGET_BRANCH} ${BASE_BRANCH}
BRANCHES=$(git branch -r | grep 'origin/build/ver/')
for BRANCH in $BRANCHES; do
BRANCH_NAME=$(echo $BRANCH | sed 's|origin/||')
LOCAL_DIR=$(echo $BRANCH_NAME | sed 's|build/ver/||')
TARGET_ZIP="${TARGET_URL}/archive/refs/heads/${BRANCH_NAME}.zip"
echo "Branch: ${BRANCH_NAME}"
echo "URL: ${TARGET_ZIP}"
echo "Local: ${LOCAL_DIR}"
mkdir -p ${LOCAL_DIR}
wget --max-redirect=10 -O ${LOCAL_DIR}/dist.zip ${TARGET_ZIP}
TEMP_DIR=$(mktemp -d)
unzip ${LOCAL_DIR}/dist.zip -d ${TEMP_DIR}
mv ${TEMP_DIR}/*/* ${LOCAL_DIR}
rm ${LOCAL_DIR}/dist.zip
done
echo ${CNAME} > CNAME
git add .
git commit -m "GitHub Actions Auto Deploy"
git push -f origin "${TARGET_BRANCH}"