-
Notifications
You must be signed in to change notification settings - Fork 150
172 lines (148 loc) · 7.52 KB
/
main.yml
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
165
166
167
168
169
170
171
172
on:
push:
branches:
- '**'
jobs:
build_docs:
name: Build the production documentation site
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.111.2
GCLOUD_VERSION: 458.0.1-linux-x86_64
BUCKET: docs-prod-learn-redis-com
BUCKET_SERVICE_ACCOUNT: ${{ secrets.BUCKET_DOCUMENTATION_SA_PROD }}
BUCKET_SECRET: ${{ secrets.BUCKET_DOCUMENTATION_PROD }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT_PROD }}
steps:
- name: Start
run: echo "The name of the branch is ${{ github.ref }} on ${{ github.repository }}"
- name: Install Hugo
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Check the branch out
uses: actions/checkout@v4
- name: List repository files
run: ls ${{ github.workspace }}
- name: Validate the branch name before using it
run: |
if [[ "${{ github.ref_name }}" =~ ^[a-zA-Z0-9_.-]+$ ]]
then
echo "The branch name ${{ github.ref_name }} is valid."
else
echo "ERROR: Invalid branch name ${{ github.ref_name }}!"
exit 1
fi
- name: Install dependencies
run: make deps
- name: Build out all versions
run: |
set -x
function setBaseUrl() {
if [[ "${{ github.ref_name }}" == "main" ]]
then
hugo_root_path=docs/staging/dev
elif [[ "${{ github.ref_name }}" == "latest" ]]
then
hugo_root_path="docs/latest"
elif [[ "${{ endsWith(github.ref_name, '-build') }}" == "true" ]]
then
hugo_root_path=`echo docs/version/${{ github.ref_name }} | sed 's/-build$//'`
else
hugo_root_path=docs/staging/${{ github.ref_name }}
fi \
&& sed -i "s#baseURL = \"https://redis.io\"#baseURL = \"https://redis.io/$hugo_root_path\"#g" config.toml
}
setBaseUrl
kubernetes_versions=($(find content/operate/kubernetes/ -maxdepth 1 -type d -regex ".*[0-9-]" | awk -F/ '{print $NF}'))
rs_versions=($(find content/operate/rs/ -maxdepth 1 -type d -regex ".*[0-9-]" | awk -F/ '{print $NF}'))
# build latest
for version in "${kubernetes_versions[@]}"; do
rm -r "content/operate/kubernetes/${version}"
done
for version in "${rs_versions[@]}"; do
rm -r "content/operate/rs/${version}"
done
make all
git checkout .
# build all versions
for version in "${kubernetes_versions[@]}"; do
setBaseUrl
# for each version, remove all other versions before building
versions_to_remove=($(echo "${kubernetes_versions[@]}" "${version}" | tr ' ' '\n' | sort | uniq -u))
for version_to_remove in "${versions_to_remove[@]}"; do
rm -r "content/operate/kubernetes/${version_to_remove}"
done
cp -r "content/operate/kubernetes/${version}"/* content/operate/kubernetes/
rm -r "content/operate/kubernetes/${version}"
sed -i 's/id="versionSelectorKubernetesValue" class="version-selector-control">latest/id="versionSelectorKubernetesValue" class="version-selector-control">v'"${version}"'/' layouts/partials/docs-nav.html
sed -i 's/linkTitle: '"${version}"'/linkTitle: Redis for Kubernetes/' content/operate/kubernetes/_index.md
# inject replace command in meta-links to make sure editURL and issuesURL point to right version
sed -i "11i \{\{ \$gh_file = replaceRE \`\^operate\/kubernetes\/\` \"operate\/kubernetes\/$version\/\" \$gh_file }}" layouts/partials/meta-links.html
hugo -d "kubernetes-${version}"
git checkout .
done
for version in "${rs_versions[@]}"; do
setBaseUrl
# for each version, remove all other versions before building
versions_to_remove=($(echo "${rs_versions[@]}" "${version}" | tr ' ' '\n' | sort | uniq -u))
for version_to_remove in "${versions_to_remove[@]}"; do
rm -r "content/operate/rs/${version_to_remove}"
done
cp -r "content/operate/rs/${version}"/* content/operate/rs/
rm -r "content/operate/rs/${version}"
sed -i 's/id="versionSelectorRsValue" class="version-selector-control">latest/id="versionSelectorRsValue" class="version-selector-control">v'"${version}"'/' layouts/partials/docs-nav.html
sed -i 's/linkTitle: '"${version}"'/linkTitle: Redis Software/' content/operate/rs/_index.md
# inject replace command in meta-links to make sure editURL and issuesURL point to right version
sed -i "11i \{\{ \$gh_file = replaceRE \`\^operate\/rs\/\` \"operate\/rs\/$version\/\" \$gh_file }}" layouts/partials/meta-links.html
hugo -d "rs-${version}"
git checkout .
done
- name: List client examples
run: ls "${{ github.workspace }}/examples"
- name: List files to be published
run: ls "${{ github.workspace }}/public"
- name: Install the Google Cloud CLI
run: |
wget -O ${{ github.workspace }}/google-cloud-cli.tar.gz "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-$GCLOUD_VERSION.tar.gz" \
&& tar -xvf google-cloud-cli.tar.gz -C ${{ github.workspace }}\
&& ${{ github.workspace }}/google-cloud-sdk/install.sh --quiet
- name: Prepare bucket authentication
run: echo $BUCKET_SECRET | base64 --decode > service_account.json && ls -a service_account.json
- name: Authenticate to the bucket
run: |
./google-cloud-sdk/bin/gcloud auth activate-service-account $BUCKET_SERVICE_ACCOUNT --key-file=./service_account.json --project=$GCP_PROJECT \
&& ./google-cloud-sdk/bin/gcloud auth list
- name: Sync the branch to the bucket
run: |
if [[ "${{ github.ref_name }}" == "main" ]]
then
bucket_path=staging/dev
elif [[ "${{ github.ref_name }}" == "latest" ]]
then
bucket_path=${{ github.ref_name }}
elif [[ "${{ endsWith(github.ref_name, '-build') }}" == "true" ]]
then
bucket_path=`echo "version/${{ github.ref_name }}" | sed 's/-build$//'`
else
bucket_path=staging/${{ github.ref_name }}
fi \
&& ./google-cloud-sdk/bin/gsutil -m rsync -r -c -j html -d ${{ github.workspace }}/public gs://$BUCKET/$bucket_path
if [[ "${{ github.ref_name }}" == "latest" ]]
then
versioned_builds=($(find . -type d -regex ".*[0-9-]" -maxdepth 1 | sed -E 's/^.\///'))
for versioned_build in "${versioned_builds[@]}"; do
product=$(grep -Eo '[a-zA-Z]+' <<< $versioned_build)
gsutil -m rsync -r -c -j html -d "${{ github.workspace }}/${versioned_build}/operate/${product}" "gs://${BUCKET}/${versioned_build}/operate/${product}"
done
fi
if [[ "$bucket_path" == staging/* ]]
then
versioned_builds=($(find . -type d -regex ".*[0-9-]" -maxdepth 1 | sed -E 's/^.\///'))
for versioned_build in "${versioned_builds[@]}"; do
product=$(grep -Eo '[a-zA-Z]+' <<< $versioned_build)
gsutil -m rsync -r -c -j html -d "${{ github.workspace }}/${versioned_build}/operate/${product}" "gs://${BUCKET}/${bucket_path}/${versioned_build}/operate/${product}"
done
fi
- name: End
run: echo "This job's status is ${{ job.status }}."