-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
129 lines (111 loc) · 3.51 KB
/
entrypoint.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
set -eu
YES_VAL="yes"
PUSH_TO_BRANCH="$INPUT_PUSH_TO_BRANCH"
BEFORE_CMD="$INPUT_BEFORE_CMD"
AFTER_CMD="$INPUT_AFTER_CMD"
AUTO_PUSH="$INPUT_AUTO_PUSH"
OUTPUT_FOLDER="$INPUT_OUTPUT_FOLDER"
SOURCE_FOLDER="$INPUT_SOURCE_FOLDER"
CACHED_APIGEN="$INPUT_CACHED_APIGEN"
echo " "
if [ -z "$GITHUB_TOKEN" ]; then
echo "🚩 Set the GITHUB_TOKEN env variable"
exit 1
fi
if [ -z "$PUSH_TO_BRANCH" ]; then
echo "🚩 Set the PUSH_TO_BRANCH Variable"
exit 1
fi
if [ -z "$SOURCE_FOLDER" ]; then
SOURCE_FOLDER=""
fi
if [ -z "$CACHED_APIGEN" ]; then
CACHED_APIGEN="yes"
fi
if [ ! -z "$BEFORE_CMD" ]; then
echo "⚡️ Running BEFORE_CMD"
echo "---------------------------------------------------------------"
eval "$BEFORE_CMD"
echo "---------------------------------------------------------------"
echo " "
fi
FULL_SOURCE_FOLDER="$GITHUB_WORKSPACE/$SOURCE_FOLDER"
cd ../
echo " "
echo "------------------------------------"
echo "🏗 Doing Groud Work"
mkdir apigen
mkdir apigen_ouput
cd apigen
if [ "$CACHED_APIGEN" == "$YES_VAL" ]; then
echo "##[group] ✨ Using Local Cache"
cp -r /cached-apigen/* ./
ls -lah
chmod 777 -R ./
echo "##[endgroup]"
else
echo "✨ Installing Composer"
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer >>/dev/null 2>&1
echo "##[group] ✨ Installing ApiGen"
echo '{ "require" : { "apigen/apigen" : "4.1.2" } }' >>composer.json
composer update
echo "##[endgroup]"
fi
echo "##[group] 🚀 Running ApiGen"
echo "--- 📈 Source Folder : $FULL_SOURCE_FOLDER"
echo " "
chmod +x ./vendor/bin/apigen
./vendor/bin/apigen generate -s $FULL_SOURCE_FOLDER --destination ../apigen_ouput
echo "##[endgroup]"
cd $GITHUB_WORKSPACE
if [ ! -z "$AFTER_CMD" ]; then
echo "##[group] ⚡️Running AFTER_CMD"
eval "$AFTER_CMD"
echo "##[endgroup]"
fi
echo "##[group] ✅ Validating Output"
cd ../apigen_ouput/ && ls -lah
echo "##[endgroup]"
if [ "$AUTO_PUSH" == "$YES_VAL" ]; then
echo " "
echo "🚚 Pushing To Github"
git config --global user.email "githubactionbot+apigen@gmail.com" && git config --global user.name "ApiGen Github Bot"
cd ../
if [ -z "$(git ls-remote --heads https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git ${PUSH_TO_BRANCH})" ]; then
echo "##[group] $PUSH_TO_BRANCH Create Log"
git clone --quiet https://x-access-token:$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY}.git $PUSH_TO_BRANCH >/dev/null
cd $PUSH_TO_BRANCH
git checkout --orphan $PUSH_TO_BRANCH >/dev/null
git rm -rf . >/dev/null
echo "$GITHUB_REPOSITORY" >README.md
git add README.md
git commit -a -m "➕ Create $PUSH_TO_BRANCH Branch"
git push origin $PUSH_TO_BRANCH
cd ..
echo "##[endgroup]"
echo "🗃 $PUSH_TO_BRANCH Created"
else
echo "##[group] 👌 $PUSH_TO_BRANCH Clone Log"
git clone --quiet --branch=$PUSH_TO_BRANCH https://x-access-token:$GITHUB_TOKEN@github.com/${GITHUB_REPOSITORY}.git $PUSH_TO_BRANCH
echo "##[endgroup]"
fi
cp -r apigen_ouput/* $PUSH_TO_BRANCH/
cd $PUSH_TO_BRANCH/
if [ "$(git status --porcelain)" != "" ]; then
echo "##[group] 👌 Docs Published"
git add .
git commit -m " :book: #$GITHUB_RUN_NUMBER - ApiGen Code Docs Regenerated / :zap: Triggered By $GITHUB_SHA"
git push origin $PUSH_TO_BRANCH
echo "##[endgroup]"
else
echo "✅ Nothing To Push"
fi
else
cd $GITHUB_WORKSPACE
cp -r ../apigen_ouput/* $OUTPUT_FOLDER
cd $OUTPUT_FOLDER
ls -lah
rm -rf ../apigen_ouput
echo "✅ Docs Copied To $OUTPUT_FOLDER"
fi