k8s_apis_sync #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: k8s_apis_sync | |
on: | |
workflow_dispatch: | |
inputs: | |
release: | |
type: string | |
required: true | |
description: '' | |
bucket_folder: | |
type: string | |
required: true | |
description: '' | |
jobs: | |
k8s_apis_sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Checkout' | |
uses: actions/checkout@v3 | |
- name: 'Install crdoc' | |
run: |- | |
curl -LO https://github.com/fybrik/crdoc/releases/download/v0.6.3/crdoc_Linux_x86_64.tar.gz | |
tar -xvzf crdoc_Linux_x86_64.tar.gz | |
sudo mv crdoc /bin/crdoc | |
- name: 'Fetch release' | |
run: |- | |
RELEASE="${{ github.event.inputs.release }}" | |
BUCKET_FOLDER="${{ github.event.inputs.bucket_folder }}" | |
aws s3 cp "s3://redislabs-k8s/${BUCKET_FOLDER}/redis-enterprise-operator-${RELEASE}.tar.gz" --no-sign-request . --region us-east-1 | |
tar xf "redis-enterprise-operator-${RELEASE}.tar.gz" | |
- name: 'Generate READMEs' | |
run: |- | |
mkdir artifacts | |
mkdir templates | |
cp content/operate/kubernetes/reference/kubernetes-api-reference-template.tmpl templates/template.tmpl | |
crdoc --resources crds/reaadb_crd.yaml --output artifacts/redis_enterprise_active_active_database_api.md --template templates/template.tmpl | |
sed -E -i 's/^### RedisEnterpriseActiveActiveDatabase\./### /g' artifacts/redis_enterprise_active_active_database_api.md | |
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterpriseactiveactivedatabase/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_active_active_database_api.md | |
sed -E -i 's/<td><b><a href="#redisenterpriseactiveactivedatabase/<td><b><a href="#/' artifacts/redis_enterprise_active_active_database_api.md | |
crdoc --resources crds/rec_crd.yaml --output artifacts/redis_enterprise_cluster_api.md --template templates/template.tmpl | |
sed -E -i 's/^### RedisEnterpriseCluster\./### /g' artifacts/redis_enterprise_cluster_api.md | |
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterprisecluster/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_cluster_api.md | |
sed -E -i 's/<td><b><a href="#redisenterprisecluster/<td><b><a href="#/' artifacts/redis_enterprise_cluster_api.md | |
crdoc --resources crds/redb_crd.yaml --output artifacts/redis_enterprise_database_api.md --template templates/template.tmpl | |
sed -E -i 's/^### RedisEnterpriseDatabase\./### /g' artifacts/redis_enterprise_database_api.md | |
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterprisedatabase/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_database_api.md | |
sed -E -i 's/<td><b><a href="#redisenterprisedatabase/<td><b><a href="#/' artifacts/redis_enterprise_database_api.md | |
crdoc --resources crds/rerc_crd.yaml --output artifacts/redis_enterprise_remote_cluster.md --template templates/template.tmpl | |
sed -E -i 's/^### RedisEnterpriseRemoteCluster\./### /g' artifacts/redis_enterprise_remote_cluster.md | |
sed -E -i 's/^<sup><sup>\[↩ Parent\]\(#redisenterpriseremotecluster/<sup><sup>\[↩ Parent\]\(#/g' artifacts/redis_enterprise_remote_cluster.md | |
sed -E -i 's/<td><b><a href="#redisenterpriseremotecluster/<td><b><a href="#/' artifacts/redis_enterprise_remote_cluster.md | |
- name: 'Send pull request' | |
env: | |
APP_ID: ${{ secrets.DOCS_APP_ID }} | |
PEM: ${{ secrets.DOCS_APP_PRIVATE_KEY }} | |
REGISTRATION_ID: ${{ secrets.DOCS_APP_REGISTRATION_ID }} | |
run: |- | |
set -o pipefail | |
now=$(date +%s) | |
iat=$((${now} - 60)) # Issues 60 seconds in the past | |
exp=$((${now} + 600)) # Expires 10 minutes in the future | |
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; } | |
header_json='{ | |
"typ":"JWT", | |
"alg":"RS256" | |
}' | |
# Header encode | |
header=$( echo -n "${header_json}" | b64enc ) | |
payload_json='{ | |
"iat":'"${iat}"', | |
"exp":'"${exp}"', | |
"iss":'"${APP_ID}"' | |
}' | |
# Payload encode | |
payload=$( echo -n "${payload_json}" | b64enc ) | |
# Signature | |
header_payload="${header}"."${payload}" | |
signature=$( | |
openssl dgst -sha256 -sign <(echo -n "${PEM}") \ | |
<(echo -n "${header_payload}") | b64enc | |
) | |
# Create JWT | |
JWT="${header_payload}"."${signature}" | |
GH_TOKEN=$(curl -s --request POST --url "https://api.github.com/app/installations/${REGISTRATION_ID}/access_tokens" \ | |
--header "Accept: application/vnd.github+json" --header "Authorization: Bearer $JWT" \ | |
--header "X-GitHub-Api-Version: 2022-11-28" | jq -r '.token') | |
RELEASE="${{ github.event.inputs.release }}" | |
BRANCH="k8s_apis_docs_${RELEASE}" | |
# Setup git email and username | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config user.name "github-actions[bot]" | |
git config --global "url.https://${GH_TOKEN}@github.com/.insteadOf" https://github.com/ | |
git checkout -b "${BRANCH}" | |
cp artifacts/redis_enterprise_active_active_database_api.md content/operate/kubernetes/reference/ | |
cp artifacts/redis_enterprise_cluster_api.md content/operate/kubernetes/reference/ | |
cp artifacts/redis_enterprise_database_api.md content/operate/kubernetes/reference/ | |
cp artifacts/redis_enterprise_remote_cluster.md content/operate/kubernetes/reference/ | |
git apply content/operate/kubernetes/reference/kubernetes-api-reference-frontmatter.patch | |
git add content/operate/kubernetes/reference/ | |
git commit -m "k8s api docs ${RELEASE}" | |
git push origin "${BRANCH}" | |
gh pr create \ | |
--body "k8s api docs ${RELEASE}" \ | |
--title "k8s api docs ${RELEASE}" \ | |
--head "$BRANCH" \ | |
--base "main" |