theshire/.forgejo/workflows/schemas.yaml
Joseph Hanson 516a81df5e
Some checks failed
Schemas / Schemas (push) Failing after 38s
debug
2024-05-29 13:43:26 -05:00

104 lines
3.3 KiB
YAML

---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Schemas"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Every day at midnight
push:
branches: ["main"]
paths: [".forgejo/workflows/schemas.yaml"]
jobs:
publish:
name: Schemas
runs-on: ["docker-x86_64"]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: https://github.com/actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Workflow Tools
shell: bash
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
curl -LO "https://dl.min.io/client/mc/release/linux-amd64/mc"
chmod +x mc
mv mc /usr/local/bin/
- name: Setup Python
run: |
apt-get update
apt-get install -y python3 python3-pip
pip3 install --upgrade pip
- name: Write kubeconfig
id: kubeconfig
uses: https://github.com/timheuer/base64-to-file@v1
with:
encodedString: "${{ secrets.KUBECONFIG }}"
fileName: kubeconfig
fileDir: $GITHUB_WORKSPACE
- name: Write mc
id: mcconfig
uses: https://github.com/timheuer/base64-to-file@v1
with:
encodedString: "${{ secrets.MCCONFIG }}"
fileName: config.json
fileDir: $GITHUB_WORKSPACE
- name: Extracting CRDs to yaml
env:
KUBECONFIG: "${{ steps.kubeconfig.outputs.filePath }}"
run: |
# Create temp folder for CRDs
TMP_CRD_DIR=$(mktemp -d)
echo "Temp directory: $TMP_CRD_DIR"
# Create final schemas directory
SCHEMAS_DIR=$GITHUB_WORKSPACE/crdSchemas
mkdir -p $SCHEMAS_DIR
# Extract CRDs from cluster
NUM_OF_CRDS=0
while read -r crd
do
filename=${crd%% *}
kubectl get crds "$filename" -o yaml > "$TMP_CRD_DIR/$filename.yaml" 2>&1
echo "Extracted CRD: $filename"
resourceKind=$(grep "kind:" "$TMP_CRD_DIR/$filename.yaml" | awk 'NR==2{print $2}' | tr '[:upper:]' '[:lower:]')
resourceGroup=$(grep "group:" "$TMP_CRD_DIR/$filename.yaml" | awk 'NR==1{print $2}')
# Save name and group for later directory organization
CRD_GROUPS["$resourceKind"]="$resourceGroup"
let ++NUM_OF_CRDS
done < <(kubectl get crds 2>&1 | sed -n '/NAME/,$p' | tail -n +2)
echo numCRDs: $NUM_OF_CRDS
- name: Download and run crd-extractor
env:
KUBECONFIG: "${{ steps.kubeconfig.outputs.filePath }}"
shell: bash
run: |
curl -fsSL -o $GITHUB_WORKSPACE/crd-extractor.sh \
https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/Utilities/crd-extractor.sh
chmod +x $GITHUB_WORKSPACE/crd-extractor.sh
bash $GITHUB_WORKSPACE/crd-extractor.sh
- name: Deploy to Cloudflare R2
env:
MC_CONFIG_DIR: $GITHUB_WORKSPACE
shell: bash
run: |
mc cp --recursive $SCHEMAS_DIR r2-ks/kubernetes-schemas