-
Notifications
You must be signed in to change notification settings - Fork 1
60 lines (46 loc) · 1.76 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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}"