forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·65 lines (52 loc) · 1.87 KB
/
publish.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
#!/bin/bash
# This is run on every commit that Azure Pipelines picks up. It assumes that docs have already been built
# via docs/build.sh. The push behavior differs depending on the nature of the commit and non/dev `VERSION.txt`:
# * Main commit (dev):
# pushes docs to https://www.envoyproxy.io/docs/envoy/latest/.
# * Main or release branch commit (non-dev):
# pushes docs to versioned location, e.g.
# https://www.envoyproxy.io/docs/envoy/v1.6.0/.
# * Otherwise: noop.
set -e
DOCS_DIR=generated/docs
CHECKOUT_DIR=envoy-docs
BUILD_SHA=$(git rev-parse HEAD)
VERSION="$(cat VERSION.txt)"
MAIN_BRANCH="refs/heads/main"
RELEASE_BRANCH_REGEX="^refs/heads/release/v.*"
DEV_VERSION_REGEX="-dev$"
if [[ "$VERSION" =~ $DEV_VERSION_REGEX ]]; then
if [[ "$AZP_BRANCH" == "${MAIN_BRANCH}" ]]; then
if [[ -n "$NETLIFY_TRIGGER_URL" ]]; then
echo "Triggering netlify docs build for (${BUILD_SHA})"
curl -X POST -d "$BUILD_SHA" "$NETLIFY_TRIGGER_URL"
fi
else
echo "Ignoring docs push"
fi
exit 0
else
PUBLISH_DIR="${CHECKOUT_DIR}/docs/envoy/v${VERSION}"
fi
if [[ "${AZP_BRANCH}" != "${MAIN_BRANCH}" ]] && ! [[ "${AZP_BRANCH}" =~ ${RELEASE_BRANCH_REGEX} ]]; then
# Most likely a tag, do nothing.
echo 'Ignoring non-release branch for docs push.'
exit 0
fi
DOCS_MAIN_BRANCH="main"
echo 'cloning'
git clone [email protected]:envoyproxy/envoy-website "${CHECKOUT_DIR}" -b "${DOCS_MAIN_BRANCH}" --depth 1
if [[ -e "$PUBLISH_DIR" ]]; then
# Defense against the unexpected.
echo 'Docs version already exists, not continuing!.'
exit 1
fi
mkdir -p "$PUBLISH_DIR"
cp -r "$DOCS_DIR"/* "$PUBLISH_DIR"
cd "${CHECKOUT_DIR}"
git config user.name "envoy-docs(Azure Pipelines)"
git config user.email [email protected]
set -x
git add .
git commit -m "docs envoy@$BUILD_SHA"
git push origin "${DOCS_MAIN_BRANCH}"