forked from micronaut-projects/github-pages-deploy-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·164 lines (140 loc) · 4.29 KB
/
entrypoint.sh
File metadata and controls
executable file
·164 lines (140 loc) · 4.29 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -e
if [ -z "$GH_TOKEN" ]
then
echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy."
exit 1
fi
if [ -z "$BRANCH" ]
then
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
exit 1
fi
if [ -z "$DOC_FOLDER" ];
then
DOC_FOLDER=$BRANCH
fi
if [ -z "$SKIP_SNAPSHOT" ]; then
SKIP_SNAPSHOT="$BETA"
fi
if [ -z "$SKIP_LATEST" ]; then
SKIP_LATEST="$SKIP_SNAPSHOT"
fi
if [ -z "$FOLDER" ]
then
echo "You must provide the action with the folder name in the repository where your compiled page lives."
exit 1
fi
case "$FOLDER" in /*|./*)
echo "The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly."
exit 1
esac
if [ -z "$COMMIT_EMAIL" ]
then
COMMIT_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com"
fi
if [ -z "$COMMIT_NAME" ]
then
COMMIT_NAME="${GITHUB_ACTOR}"
fi
if [ -z "$TARGET_REPOSITORY" ]
then
TARGET_REPOSITORY="${GITHUB_REPOSITORY}"
fi
# Directs the action to the the Github workspace.
cd $GITHUB_WORKSPACE && \
# Configures Git.
git init && \
git config --global user.email "${COMMIT_EMAIL}" && \
git config --global user.name "${COMMIT_NAME}" && \
git config --global http.version HTTP/1.1 && \
git config --global http.version HTTP/1.1
git config --global http.postBuffer 157286400
## Initializes the repository path using the access token.
REPOSITORY_PATH="https://${GH_TOKEN}@github.com/${TARGET_REPOSITORY}.git" && \
# Checks to see if the remote exists prior to deploying.
# If the branch doesn't exist it gets created here as an orphan.
if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "$BRANCH" | wc -l)" -eq 0 ];
then
echo "Creating remote branch ${BRANCH} as it doesn't exist..."
mkdir $DOC_FOLDER && \
cd $DOC_FOLDER && \
git init && \
git checkout -b $BRANCH && \
git remote add origin $REPOSITORY_PATH && \
touch README.md && \
git add README.md && \
git commit -m "Initial ${BRANCH} commit" && \
git push $REPOSITORY_PATH $BRANCH
else
## Clone the target repository
git clone "$REPOSITORY_PATH" $DOC_FOLDER --branch $BRANCH --single-branch && \
cd $DOC_FOLDER
fi
# Builds the project if a build script is provided.
echo "Running build scripts... $BUILD_SCRIPT" && \
eval "$BUILD_SCRIPT" && \
if [ -n "$CNAME" ]; then
echo "Generating a CNAME file in in the $PWD directory..."
echo $CNAME > CNAME
git add CNAME
fi
# Update gh-pages root index page
if [ -f "../$FOLDER/ghpages.html" ]; then
cp "../$FOLDER/ghpages.html" index.html
git add index.html
fi
# Commits the data to Github.
if [ -z "$VERSION" ]
then
if [ -z "$SKIP_SNAPSHOT" ] || [ "$SKIP_SNAPSHOT" == "false" ]; then
echo "No Version. Publishing Snapshot of Docs"
if [ -n "${DOC_SUB_FOLDER}" ]; then
mkdir -p snapshot/$DOC_SUB_FOLDER
cp -r "../$FOLDER/." ./snapshot/$DOC_SUB_FOLDER/
git add snapshot/$DOC_SUB_FOLDER/*
else
mkdir -p snapshot
cp -r "../$FOLDER/." ./snapshot/
git add snapshot/*
fi
fi
else
if [ -z "$SKIP_LATEST" ] || [ "$SKIP_LATEST" == "false" ]
then
echo "Publishing Latest Docs"
if [ -n "${DOC_SUB_FOLDER}" ]; then
mkdir -p latest/$DOC_SUB_FOLDER
cp -r "../$FOLDER/." ./latest/$DOC_SUB_FOLDER/
git add latest/$DOC_SUB_FOLDER/*
else
mkdir -p latest
cp -r "../$FOLDER/." ./latest/
git add latest/*
fi
fi
echo "Publishing $VERSION of Docs"
majorVersion=${VERSION:0:4}
majorVersion="${majorVersion}x"
if [ -n "${DOC_SUB_FOLDER}" ]; then
mkdir -p "$VERSION/$DOC_SUB_FOLDER"
cp -r "../$FOLDER/." "./$VERSION/$DOC_SUB_FOLDER"
git add "$VERSION/$DOC_SUB_FOLDER/*"
else
mkdir -p "$VERSION"
cp -r "../$FOLDER/." "./$VERSION/"
git add "$VERSION/*"
fi
if [ -n "${DOC_SUB_FOLDER}" ]; then
mkdir -p "$majorVersion/$DOC_SUB_FOLDER"
cp -r "../$FOLDER/." "./$majorVersion/$DOC_SUB_FOLDER"
git add "$majorVersion/$DOC_SUB_FOLDER/*"
else
mkdir -p "$majorVersion"
cp -r "../$FOLDER/." "./$majorVersion/"
git add "$majorVersion/*"
fi
fi
git commit -m "Deploying to ${BRANCH} - $(date +"%T")" --quiet && \
git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$TARGET_REPOSITORY.git" gh-pages || true && \
echo "Deployment successful!"