Skip to content

Commit c51a148

Browse files
Merge pull request #1 from redis/main
Adding latest changes
2 parents 62c376e + 3f1f2ac commit c51a148

File tree

2,117 files changed

+193898
-31391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,117 files changed

+193898
-31391
lines changed

.github/workflows/autocomment.yaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Auto Comment on PR
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'content/**'
7+
types:
8+
- opened
9+
- synchronize
10+
permissions:
11+
pull-requests: write
12+
contents: read
13+
14+
jobs:
15+
auto-comment:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: 'Checkout'
19+
uses: 'actions/checkout@v3'
20+
21+
- name: 'Install jq'
22+
run: sudo apt-get install jq
23+
24+
- name: Create Comment
25+
run: |
26+
set -e
27+
28+
PR_NUMBER=${{ github.event.pull_request.number }}
29+
BRANCH_NAME=${{ github.head_ref }}
30+
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
31+
CREATE_COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
32+
UPDATE_COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/comments"
33+
FILES_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}/files"
34+
35+
# Check if comment already exists
36+
EXISTING_COMMENT_JSON=$(curl -Ls \
37+
-H "Accept: application/vnd.github+json" \
38+
-H "X-GitHub-Api-Version: 2022-11-28" \
39+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
40+
$CREATE_COMMENT_URL \
41+
| jq -r '.[] | select(.user.login == "github-actions[bot]")'
42+
)
43+
EXISTING_COMMENT_ID=$(jq -r '.id' <<<"$EXISTING_COMMENT_JSON")
44+
EXISTING_COMMENT=$(jq -r '.body' <<<"$EXISTING_COMMENT_JSON")
45+
46+
# Get all changed md files
47+
CHANGED_MD_FILES=$(curl -Ls \
48+
-H "Accept: application/vnd.github+json" \
49+
-H "X-GitHub-Api-Version: 2022-11-28" \
50+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
51+
$FILES_URL \
52+
| jq -r --arg prefix $BRANCH_NAME/ '.[] | select(((.filename | test("content\/.+\\.md")) and .status != "removed")) | ($prefix + .filename)' \
53+
| sed -E -e 's|(^[^/]+/)([^/]+/)|\1|' -e 's|^|https://redis.io/docs/staging/|' -e 's|(_?index)?\.md||' \
54+
| uniq \
55+
| xargs \
56+
| sed 's/ /<br>/g')
57+
58+
# Get all changed image files
59+
CHANGED_IMAGE_FILES=$(curl -Ls \
60+
-H "Accept: application/vnd.github+json" \
61+
-H "X-GitHub-Api-Version: 2022-11-28" \
62+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
63+
$FILES_URL \
64+
| jq -r '.[] | select(.filename | test("^static/images\/.+(.png|.svg|.gif|.)")) | .filename | sub("^static/";"")')
65+
66+
if [[ -n "$CHANGED_IMAGE_FILES" ]]
67+
then
68+
# For each image, work out in which README it is present
69+
MD_FILES_WITH_IMAGE=()
70+
for CHANGED_IMAGE_FILE in $CHANGED_IMAGE_FILES; do
71+
MD_FILE_WITH_IMAGE=$(grep -ro "$CHANGED_IMAGE_FILE" content \
72+
| sed -E -e 's|:.+||' -e "s|^content/|https://redis.io/docs/staging/$BRANCH_NAME/|" -e 's|(_?index)?\.md||' \
73+
| uniq)
74+
MD_FILES_WITH_IMAGE+=($MD_FILE_WITH_IMAGE)
75+
done
76+
CHANGED_MD_FILES_WITH_IMAGE=$(printf "%s\n" "${MD_FILES_WITH_IMAGE[@]}" \
77+
| uniq \
78+
| xargs \
79+
| sed 's/ /<br>/g')
80+
CHANGED_MD_FILES="${CHANGED_MD_FILES}<br>${CHANGED_MD_FILES_WITH_IMAGE}"
81+
fi
82+
83+
if [[ -z "$CHANGED_MD_FILES" ]]
84+
then
85+
if [[ -z "$EXISTING_COMMENT_ID" ]]
86+
then
87+
printf '%s\n' 'Nothing to do!'
88+
exit 0
89+
else
90+
# If a comment already exists but there are no changed files in the PR anymore, delete the comment
91+
curl -Ls \
92+
-X DELETE \
93+
-H "Accept: application/vnd.github+json" \
94+
-H "X-GitHub-Api-Version: 2022-11-28" \
95+
-H "Authorization: token ${GITHUB_TOKEN}" \
96+
"${UPDATE_COMMENT_URL}/${EXISTING_COMMENT_ID}"
97+
printf '%s\n' 'Comment deleted!'
98+
exit 0
99+
fi
100+
fi
101+
102+
COMMENT="Staging links:<br> $CHANGED_MD_FILES"
103+
104+
printf '%s %s\n' 'Writing comment: ' "$COMMENT"
105+
106+
generate_post_data()
107+
{
108+
cat <<EOF
109+
{
110+
"body": "$COMMENT"
111+
EOF
112+
}
113+
114+
if [[ -n "$EXISTING_COMMENT_ID" ]]
115+
then
116+
# Update comment on pull request if comment is actually different
117+
if [[ "$COMMENT" != "$EXISTING_COMMENT" ]]
118+
then
119+
curl -Ls \
120+
-X PATCH \
121+
-H "Accept: application/vnd.github+json" \
122+
-H "X-GitHub-Api-Version: 2022-11-28" \
123+
-H "Authorization: token ${GITHUB_TOKEN}" \
124+
"${UPDATE_COMMENT_URL}/${EXISTING_COMMENT_ID}" \
125+
--data "$(generate_post_data)" 1>/dev/null
126+
127+
printf '%s\n' 'Comment updated!'
128+
else
129+
printf '%s\n' 'Nothing changed!'
130+
fi
131+
else
132+
# Write comment on pull request
133+
curl -Ls \
134+
-X POST \
135+
-H "Accept: application/vnd.github+json" \
136+
-H "X-GitHub-Api-Version: 2022-11-28" \
137+
-H "Authorization: token ${GITHUB_TOKEN}" \
138+
$CREATE_COMMENT_URL \
139+
--data "$(generate_post_data)" 1>/dev/null
140+
141+
printf '%s\n' 'Comment written!'
142+
fi
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: k8s_apis_sync
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release:
7+
type: string
8+
required: true
9+
description: ''
10+
bucket_folder:
11+
type: string
12+
required: true
13+
description: ''
14+
15+
jobs:
16+
k8s_apis_sync:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
actions: write
22+
steps:
23+
- name: Generate a token
24+
id: generate-token
25+
uses: actions/create-github-app-token@v1
26+
with:
27+
app-id: ${{ secrets.DOCS_APP_ID }}
28+
private-key: ${{ secrets.DOCS_APP_PRIVATE_KEY }}
29+
30+
- name: 'Checkout'
31+
uses: actions/checkout@v3
32+
with:
33+
token: ${{ steps.generate-token.outputs.token }}
34+
35+
- name: 'Install crdoc'
36+
run: |-
37+
curl -LO https://github.com/fybrik/crdoc/releases/download/v0.6.3/crdoc_Linux_x86_64.tar.gz
38+
tar -xvzf crdoc_Linux_x86_64.tar.gz
39+
sudo mv crdoc /bin/crdoc
40+
41+
- name: 'Fetch release'
42+
run: |-
43+
RELEASE="${{ github.event.inputs.release }}"
44+
BUCKET_FOLDER="${{ github.event.inputs.bucket_folder }}"
45+
aws s3 cp "s3://redislabs-k8s/${BUCKET_FOLDER}/redis-enterprise-operator-${RELEASE}.tar.gz" --no-sign-request . --region us-east-1
46+
47+
tar xf "redis-enterprise-operator-${RELEASE}.tar.gz"
48+
49+
- name: 'Generate READMEs'
50+
run: |-
51+
mkdir artifacts
52+
mkdir templates
53+
cp content/operate/kubernetes/reference/kubernetes-api-reference-template.tmpl templates/template.tmpl
54+
55+
crdoc --resources crds/reaadb_crd.yaml --output artifacts/redis_enterprise_active_active_database_api.md --template templates/template.tmpl
56+
sed -E -i 's/^### RedisEnterpriseActiveActiveDatabase\./### /g' artifacts/redis_enterprise_active_active_database_api.md
57+
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterpriseactiveactivedatabase/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_active_active_database_api.md
58+
sed -E -i 's/<td><a href="#redisenterpriseactiveactivedatabase/<td><a href="#/' artifacts/redis_enterprise_active_active_database_api.md
59+
sed -E -i 's/\[index\]/\[\]/g' artifacts/redis_enterprise_active_active_database_api.md
60+
awk '/(#[^")]+)index/ {gsub(/index/,"")}; {print}' artifacts/redis_enterprise_active_active_database_api.md > _tmp.md && mv _tmp.md artifacts/redis_enterprise_active_active_database_api.md
61+
62+
crdoc --resources crds/rec_crd.yaml --output artifacts/redis_enterprise_cluster_api.md --template templates/template.tmpl
63+
sed -E -i 's/^### RedisEnterpriseCluster\./### /g' artifacts/redis_enterprise_cluster_api.md
64+
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterprisecluster/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_cluster_api.md
65+
sed -E -i 's/<td><a href="#redisenterprisecluster/<td><a href="#/' artifacts/redis_enterprise_cluster_api.md
66+
sed -E -i 's/\[index\]/\[\]/g' artifacts/redis_enterprise_cluster_api.md
67+
awk '/(#[^")]+)index/ {gsub(/index/,"")}; {print}' artifacts/redis_enterprise_cluster_api.md > _tmp.md && mv _tmp.md artifacts/redis_enterprise_cluster_api.md
68+
69+
crdoc --resources crds/redb_crd.yaml --output artifacts/redis_enterprise_database_api.md --template templates/template.tmpl
70+
sed -E -i 's/^### RedisEnterpriseDatabase\./### /g' artifacts/redis_enterprise_database_api.md
71+
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterprisedatabase/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_database_api.md
72+
sed -E -i 's/<td><a href="#redisenterprisedatabase/<td><a href="#/' artifacts/redis_enterprise_database_api.md
73+
sed -E -i 's/\[index\]/\[\]/g' artifacts/redis_enterprise_database_api.md
74+
awk '/(#[^")]+)index/ {gsub(/index/,"")}; {print}' artifacts/redis_enterprise_database_api.md > _tmp.md && mv _tmp.md artifacts/redis_enterprise_database_api.md
75+
76+
crdoc --resources crds/rerc_crd.yaml --output artifacts/redis_enterprise_remote_cluster_api.md --template templates/template.tmpl
77+
sed -E -i 's/^### RedisEnterpriseRemoteCluster\./### /g' artifacts/redis_enterprise_remote_cluster_api.md
78+
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterpriseremotecluster/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_remote_cluster_api.md
79+
sed -E -i 's/<td><a href="#redisenterpriseremotecluster/<td><a href="#/' artifacts/redis_enterprise_remote_cluster_api.md
80+
sed -E -i 's/\[index\]/\[\]/g' artifacts/redis_enterprise_remote_cluster_api.md
81+
awk '/(#[^")]+)index/ {gsub(/index/,"")}; {print}' artifacts/redis_enterprise_remote_cluster_api.md > _tmp.md && mv _tmp.md artifacts/redis_enterprise_remote_cluster_api.md
82+
83+
- name: 'Generate YAML snippets'
84+
run: |-
85+
function formatYamlSnippet() {
86+
cat > "$2" << EOL
87+
\`\`\`yaml
88+
$(cat $1)
89+
\`\`\`
90+
EOL
91+
}
92+
93+
formatYamlSnippet admission-service.yaml content/embeds/admission-service.md
94+
formatYamlSnippet admission/webhook.yaml content/embeds/admission_webhook.md
95+
formatYamlSnippet examples/v1/rec.yaml content/embeds/rec.md
96+
formatYamlSnippet examples/v1alpha1/reaadb.yaml content/embeds/reaadb.md
97+
formatYamlSnippet examples/v1alpha1/redb.yaml content/embeds/redb.md
98+
formatYamlSnippet examples/v1alpha1/rerc.yaml content/embeds/rerc.md
99+
formatYamlSnippet log_collector/log_collector_role_all_mode.yaml content/embeds/log_collector_role_all_mode.md
100+
formatYamlSnippet log_collector/log_collector_role_restricted_mode.yaml content/embeds/log_collector_role_restricted_mode.md
101+
formatYamlSnippet multi-namespace-redb/operator_cluster_role_binding.yaml content/embeds/multi-ns_operator_cluster_role_binding.md
102+
formatYamlSnippet multi-namespace-redb/operator_cluster_role.yaml content/embeds/multi-ns_operator_cluster_role.md
103+
formatYamlSnippet multi-namespace-redb/role_binding.yaml content/embeds/multi-ns_role_binding.md
104+
formatYamlSnippet multi-namespace-redb/role.yaml content/embeds/multi-ns_role.md
105+
formatYamlSnippet openshift/admission-service.yaml content/embeds/openshift_admission-service.md
106+
formatYamlSnippet openshift/rec_rhel.yaml content/embeds/openshift_rec.md
107+
formatYamlSnippet openshift/role_binding.yaml content/embeds/openshift_role_binding.md
108+
formatYamlSnippet openshift/role.yaml content/embeds/openshift_role.md
109+
formatYamlSnippet openshift/scc.yaml content/embeds/openshift_scc.md
110+
formatYamlSnippet openshift/service_account.yaml content/embeds/openshift_service_account.md
111+
formatYamlSnippet rack_awareness/rack_aware_cluster_role_binding.yaml content/embeds/rack_aware_cluster_role_binding.md
112+
formatYamlSnippet rack_awareness/rack_aware_cluster_role.yaml content/embeds/rack_aware_cluster_role.md
113+
formatYamlSnippet rack_awareness/rack_aware_rec.yaml content/embeds/rack_aware_rec.md
114+
formatYamlSnippet role_binding.yaml content/embeds/role_binding.md
115+
formatYamlSnippet role.yaml content/embeds/role.md
116+
formatYamlSnippet service_account.yaml content/embeds/service_account.md
117+
118+
- name: 'Send pull request'
119+
env:
120+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
121+
run: |-
122+
RELEASE="${{ github.event.inputs.release }}"
123+
BRANCH="k8s_apis_docs_${RELEASE}"
124+
125+
# Setup git email and username
126+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
127+
git config user.name "github-actions[bot]"
128+
129+
git checkout -b "${BRANCH}"
130+
131+
cp artifacts/redis_enterprise_active_active_database_api.md content/operate/kubernetes/reference/
132+
cp artifacts/redis_enterprise_cluster_api.md content/operate/kubernetes/reference/
133+
cp artifacts/redis_enterprise_database_api.md content/operate/kubernetes/reference/
134+
cp artifacts/redis_enterprise_remote_cluster_api.md content/operate/kubernetes/reference/
135+
136+
git apply content/operate/kubernetes/reference/kubernetes-api-reference-frontmatter.patch
137+
138+
git add content/operate/kubernetes/reference/
139+
git add content/embeds/
140+
141+
git commit -m "k8s api docs ${RELEASE}"
142+
git push origin "${BRANCH}"
143+
144+
gh pr create \
145+
--body "k8s api docs ${RELEASE}" \
146+
--title "k8s api docs ${RELEASE}" \
147+
--head "$BRANCH" \
148+
--base "main"

0 commit comments

Comments
 (0)