Update CRD Reference #266
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: Update CRD Reference | |
on: | |
schedule: | |
- cron: '0 1 * * *' | |
workflow_dispatch: | |
jobs: | |
update-crd-reference: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout K8ssandra-operator main branch | |
uses: actions/checkout@v2 | |
with: | |
repository: k8ssandra/k8ssandra-operator | |
ref: main | |
path: k8ssandra-operator-main | |
- name: Checkout K8ssandra-operator releases | |
uses: actions/checkout@v2 | |
with: | |
repository: k8ssandra/k8ssandra-operator | |
ref: main | |
path: k8ssandra-operator-releases | |
- name: Checkout cass-operator | |
uses: actions/checkout@v2 | |
with: | |
repository: k8ssandra/cass-operator | |
ref: master | |
path: cass-operator | |
- name: Install crdoc | |
run: | | |
go install fybrik.io/crdoc@latest | |
- name: Generate CRD reference for each K8ssandra-operator release | |
run: | | |
set -x | |
# Compute the md5 sum of the current CRD reference directory contents. Will be used to decide if a PR is needed. | |
crd_dir_current_hash=$(find k8ssandra-operator-main/docs/content/en/reference/crd/ -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | head -c 8) | |
# Cleanup the CRD reference directory. | |
rm -rf k8ssandra-operator-main/docs/content/en/reference/crd/*/ | |
mkdir -p k8ssandra-operator-main/docs/content/en/reference/crd/releases | |
cp k8ssandra-operator-main/docs/config/crdoc-templates/_index_releases.md k8ssandra-operator-main/docs/content/en/reference/crd/releases/_index.md | |
# Fetch and cycle through K8ssandra-operator release branches to generate CRD references. | |
cd k8ssandra-operator-releases | |
git fetch | |
k8c_releases=$(git branch -r |grep -E "release/[0-9]{1,2}.[0-9]{1,2}") | |
for branch in $k8c_releases | |
do | |
git checkout -f $branch | |
version=$(echo $branch | sed 's/origin\/release\///g') | |
mkdir -p ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/k8ssandra-operator-releases/k8ssandra-operator-crds-$version > /dev/null 2>&1 | |
~/go/bin/crdoc --resources config/crd/bases --output ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/k8ssandra-operator-releases/k8ssandra-operator-crds-$version/_index.md --template ../k8ssandra-operator-main/docs/config/crdoc-templates/k8c.tmpl | |
sed -i "s/RELEASE_VERSION/$version/g" ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/k8ssandra-operator-releases/k8ssandra-operator-crds-$version/_index.md | |
done | |
# Generate CRD reference for K8ssandra-operator main branch (latest) | |
git checkout -f main | |
mkdir -p ../k8ssandra-operator-main/docs/content/en/reference/crd/k8ssandra-operator-crds-latest/ > /dev/null 2>&1 | |
~/go/bin/crdoc --resources config/crd/bases --output ../k8ssandra-operator-main/docs/content/en/reference/crd/k8ssandra-operator-crds-latest/_index.md --template ../k8ssandra-operator-main/docs/config/crdoc-templates/k8c.tmpl | |
sed -i "s/vRELEASE_VERSION/latest build/g" ../k8ssandra-operator-main/docs/content/en/reference/crd/k8ssandra-operator-crds-latest/_index.md | |
cp ../k8ssandra-operator-main/docs/config/crdoc-templates/_index_k8ssandra_operator_crds.md ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/k8ssandra-operator-releases/_index.md | |
# Fetch and cycle through cass-operator release branches to generate CRD references. | |
cd ../cass-operator | |
git fetch | |
cass_releases=$(git branch -r |grep -E "[0-9]{1,2}.[0-9]{1,2}.x") | |
for branch in $cass_releases | |
do | |
git checkout -f $branch | |
version=$(echo $branch | sed 's/origin\///g') | |
if [ -d "config/crd/bases" ]; then | |
mkdir -p ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/cass-operator-releases/cass-operator-crds-$version > /dev/null 2>&1 | |
~/go/bin/crdoc --resources config/crd/bases --output ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/cass-operator-releases/cass-operator-crds-$version/_index.md --template ../k8ssandra-operator-main/docs/config/crdoc-templates/cassdc.tmpl | |
sed -i "s/RELEASE_VERSION/$version/g" ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/cass-operator-releases/cass-operator-crds-$version/_index.md | |
fi | |
done | |
# Generate CRD reference for cass-operator master branch (latest) | |
git checkout -f master | |
mkdir -p ../k8ssandra-operator-main/docs/content/en/reference/crd/cass-operator-crds-latest/ > /dev/null 2>&1 | |
~/go/bin/crdoc --resources config/crd/bases --output ../k8ssandra-operator-main/docs/content/en/reference/crd/cass-operator-crds-latest/_index.md --template ../k8ssandra-operator-main/docs/config/crdoc-templates/cassdc.tmpl | |
sed -i "s/vRELEASE_VERSION/latest build/g" ../k8ssandra-operator-main/docs/content/en/reference/crd/cass-operator-crds-latest/_index.md | |
cp ../k8ssandra-operator-main/docs/config/crdoc-templates/_index_cass_operator_crds.md ../k8ssandra-operator-main/docs/content/en/reference/crd/releases/cass-operator-releases/_index.md | |
crd_dir_new_hash=$(find ../k8ssandra-operator-main/docs/content/en/reference/crd/ -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | head -c 8) | |
echo "PR_BRANCH=$crd_dir_current_hash-$crd_dir_new_hash" >> $GITHUB_ENV | |
- name: Check if a closed PR exists for the same version | |
run: | | |
set -x | |
cd k8ssandra-operator-main | |
CLOSED_UPGRADE_PR=$(curl -L -s "https://api.github.com/repos/k8ssandra/k8ssandra-operator/pulls?state=closed"|jq -c '.[] | select( .title == "Upgrade CRD reference ${{ env.PR_BRANCH }}" )'|jq -r '.title') | |
if ([ -z "$CLOSED_UPGRADE_PR" ] && [ $crd_dir_current_hash != $crd_dir_new_hash ]); then | |
echo "PR_EXISTS=no" >> $GITHUB_ENV | |
else | |
echo "PR_EXISTS=yes" >> $GITHUB_ENV | |
fi | |
- name: Send CRD reference update PR | |
if: ${{ env.PR_EXISTS == 'no' }} | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
path: k8ssandra-operator-main | |
token: ${{ secrets.CREATE_PR_TOKEN }} | |
commit-message: Upgrade CRD reference | |
delete-branch: true | |
branch: upgrade/upgrade-crd-reference-${{ env.PR_BRANCH }} | |
base: main | |
title: Upgrade CRD reference ${{ env.PR_BRANCH }} | |
body: | | |
This is an auto-generated PR from the K8ssandra CRD reference update GHA workflow. | |
- name: Setup tmate session | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ failure() }} | |
timeout-minutes: 15 | |
with: | |
limit-access-to-actor: true |