-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
64 lines (45 loc) · 1.85 KB
/
Copy pathentrypoint.sh
File metadata and controls
64 lines (45 loc) · 1.85 KB
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
61
62
63
64
#!/bin/bash
source="main-local"
destination="deploy-local"
local="${GITHUB_ACTOR}/deploy"
git config --global user.name "actions-bot"
git config --global user.email "actions-bot@no-reply.github.com"
git_base="https://actions-bot:${INPUT_TOKEN}@github.com"
# Clone src repo
git clone --branch "${INPUT_MAIN}" "${git_base}/${INPUT_REPOSITORY}.git" ${source}
# Checkout main branch
cd ${source}
# Build deployment
npm ci
npm run build
cd ..
# Clone sync-ing repository
git clone --branch "${INPUT_DEPLOY}" "${git_base}/${INPUT_REPOSITORY}.git" ${destination}
# Checkout branch
cd ${destination}
git checkout -q -f -b ${local}
# Delete old contents
rm -rf ./*
cd ..
# Copy files from template repo
cp -rf ${source}/${INPUT_BUILDFOLDER}/* ${destination} || true
# Navigate to sync-ing repo
cd ${destination}
git add -f --all > /dev/null
git commit -q -m "Deploy files from ${INPUT_MAIN} branch to ${INPUT_DEPLOY} branch"
# Push changes to remote repository
git push -f -q -u origin ${local}
commit="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
API_ENDPOINT="${GITHUB_API_URL}/repos/${INPUT_REPOSITORY}/pulls"
AUTH="Authorization: token ${INPUT_TOKEN}"
ACCEPT="Accept: application/vnd.github+json"
PR_BODY="Deployment PR created for @${GITHUB_ACTOR} at ${commit}"
POST_PAYLOAD="{\"title\": \"${INPUT_PRTITLE}\", \"body\": \"${PR_BODY}\", \"base\": \"${INPUT_DEPLOY}\", \"head\": \"${local}\"}"
PATCH_PAYLOAD="{\"title\": \"${INPUT_PRTITLE}\", \"body\": \"Updated: ${PR_BODY}\"}"
curl -s -H "${AUTH}" -H "${ACCEPT}" -X POST -d "${POST_PAYLOAD}" "${API_ENDPOINT}" > /dev/null ||\
PR=$(curl -s -H "${AUTH}" -H "${ACCEPT}" "${API_ENDPOINT}?head=${local}" | jq .[0].number) &&\
echo "Found PR ${PR} on branch ${local}" &&\
curl -s -H "${AUTH}" -H "${ACCEPT}" -X PATCH -d "${PATCH_PAYLOAD}" "${API_ENDPOINT}/${PR}" > /dev/null
cd ..
rm -rf ${source}
rm -rf ${destination}