generated from BCDevOps/opendev-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·137 lines (108 loc) · 4.34 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
130
131
132
133
134
135
#!/bin/bash -l
echo "Input parameters: $*"
if [[ $* =~ "publish" ]] || [ "$INPUT_PUBLISH" == "true" ]; then
echo "Content will be published after it is generated."
PUBLISH=true
fi
if [[ $* =~ "preview" ]]; then
echo "Previewer will be started for content after it is generated."
PREVIEW=true
fi
# activate the python virtualenv which is where we have our python dependencies installed
source /.virtualenvs/techdocs/bin/activate
cd /github/workspace
cp /mkpatcher_scripts/* /github/workspace
CATALOG_FILE=$(find . -type f -name catalog-info.yaml -o -type f -name catalog-info.yml)
if [ -z "${CATALOG_FILE}" ]
then
echo "No catalog-info file found in repo. Cannot continue."
exit 1
fi
# read the entity name and kind from the catalog-info file so we don't need to have these as inputs or vars.
ENTITY_NAME=$(cat "$CATALOG_FILE" | yq -r .metadata.name)
ENTITY_KIND=$(cat "$CATALOG_FILE" | yq -r .kind)
# map the local variables from the inputs provided by the Action
ENTITY_NAMESPACE="default"
TECHDOCS_S3_BUCKET_NAME="$INPUT_BUCKET_NAME"
TECHDOCS_S3_DEV_ROOT_PATH="dev"
AWS_ENDPOINT="$INPUT_S3_ENDPOINT"
export AWS_ACCESS_KEY_ID="$INPUT_S3_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="$INPUT_S3_SECRET_ACCESS_KEY"
export AWS_REGION="$INPUT_S3_REGION"
ENTITY_PATH="$ENTITY_NAMESPACE/$ENTITY_KIND/$ENTITY_NAME"
echo "Adjusting ownership of repo contents so git metadata can be read by 'git-revision-date-localized' mkdocs plugin..."
chown -R root /github/workspace
echo "Building TechDocs from Markdown for entity '$ENTITY_NAMESPACE/$ENTITY_KIND/$ENTITY_NAME'"
techdocs-cli build --verbose --no-docker
if [ $? -eq 0 ]; then
echo "Successfully built content. Continuing."
else
echo "Failed to build content. Abandoning. Please fix errors and try again."
exit 1
fi
HTMLTEST_CONFIG_FILE=$(find . -type f -name .htmltest.yml -o -type f -name .htmltest.yaml)
if [ -f "${HTMLTEST_CONFIG_FILE}" ]; then
echo "Using provided htmltest configuration file: '${HTMLTEST_CONFIG_FILE}'."
else
echo "Using default htmltest configuration file."
HTMLTEST_CONFIG_FILE="/.htmltest.yml"
fi
/htmltest -c $HTMLTEST_CONFIG_FILE ./site
if [ $? -eq 0 ]; then
HTMLTEST_SUCCEEDED="true"
else
HTMLTEST_SUCCEEDED="false"
fi
if [ "$HTMLTEST_SUCCEEDED" == "false" ]; then
if [ "${INPUT_STRICT_VALIDATION}" == "true" ]; then
echo "Link validation with 'htmltest' failed. The workflow will be terminated because strict validation is enabled. Please fix errors and try again. Please refer to documentation at https://github.com/bcgov/devhub-techdocs-publish/blob/main/docs/index.md and https://github.com/wjdp/htmltest for assistance fixing errors or configuring htmltest."
exit 1
else
echo "Link validation with 'htmltest' failed. The workflow will continue because strict validation is not enabled. Please refer to documentation at https://github.com/bcgov/devhub-techdocs-publish/blob/main/docs/index.md and https://github.com/wjdp/htmltest for assistance fixing errors or configuring htmltest."
fi
fi
if [ $PREVIEW ]; then
techdocs-cli serve --verbose --no-docker
fi
if [ $PUBLISH ]
then
echo "Publishing TechDocs to DevHub..."
echo "Bucket : $TECHDOCS_S3_BUCKET_NAME"
echo "Dev root path(var): $TECHDOCS_S3_DEV_ROOT_PATH"
echo "Entity path: $ENTITY_PATH"
echo "Endpoint: $AWS_ENDPOINT"
echo "Region: $AWS_REGION"
if [ -z "$AWS_ACCESS_KEY_ID" ]
then
echo "AWS_ACCESS_KEY_ID is NOT set!"
exit 1
else
echo "AWS_ACCESS_KEY_ID is set!"
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]
then
echo "AWS_SECRET_ACCESS_KEY is NOT set!"
exit 1
else
echo "AWS_SECRET_ACCESS_KEY is set!"
fi
echo "Publishing TechDocs to DEV..."
techdocs-cli publish --publisher-type awsS3 \
--storage-name "$TECHDOCS_S3_BUCKET_NAME" \
--entity "$ENTITY_PATH" \
--awsEndpoint "$AWS_ENDPOINT" \
--awsS3ForcePathStyle true \
--awsBucketRootPath "$TECHDOCS_S3_DEV_ROOT_PATH"
# only publish to prod (root) folder of bucket if PRODUCTION input is true
if [ "$INPUT_PRODUCTION" == "true" ]
then
echo "Publishing TechDocs to PROD..."
techdocs-cli publish --publisher-type awsS3 \
--storage-name "$TECHDOCS_S3_BUCKET_NAME" \
--entity "$ENTITY_PATH" \
--awsEndpoint "$AWS_ENDPOINT" \
--awsS3ForcePathStyle true
else
echo "Not publishing TechDocs to PROD."
fi
fi