Skip to content

Deploy

Deploy #12

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: [Build]
types: [completed]
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Merge Build Branches
run: |
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}
if git ls-remote --heads origin ${TARGET_BRANCH} | grep ${TARGET_BRANCH}; then
git push origin --delete ${TARGET_BRANCH}
fi
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}
unzip ${LOCAL_DIR}/dist.zip -d ${LOCAL_DIR}
rm ${LOCAL_DIR}/dist.zip
done
git add .
git commit -m "GitHub Actions Auto Deploy"
git push origin "${TARGET_BRANCH}"