Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
chore(github): add github workflow to auto-build schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgon committed Apr 3, 2024
1 parent 6414c73 commit 3029c34
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 89 deletions.
19 changes: 19 additions & 0 deletions .direnv/bin/nix-direnv-reload
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/ajgon/Projects/schemas" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/ajgon/Projects/schemas")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi

# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/ajgon/Projects/schemas" true

# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/ajgon/Projects/schemas/.envrc"

# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/ajgon/Projects/schemas/.envrc" "/home/ajgon/Projects/schemas/.direnv"/*.rc
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
7 changes: 5 additions & 2 deletions _docker/crd-extractor.sh → .github/scripts/crd-extractor.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Create temp folder for CRDs
TMP_CRD_DIR=$HOME/.datree/crds
mkdir -p "$TMP_CRD_DIR"
Expand Down Expand Up @@ -37,7 +41,7 @@ if [ $NUM_OF_CRDS == 0 ]; then
fi

# Convert crds to jsonSchema
python3 /opt/openapi2jsonschema.py "$TMP_CRD_DIR"/*.yaml
python3 "${SCRIPT_DIR}/openapi2jsonschema.py" "$TMP_CRD_DIR"/*.yaml
conversionResult=$?

# Copy and rename files to support kubeval
Expand All @@ -60,4 +64,3 @@ if [ $conversionResult == 0 ]; then
fi

rm -rf "$TMP_CRD_DIR"
chown -R "$PUID:$PGID" /crds
File renamed without changes.
1 change: 1 addition & 0 deletions .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyaml
59 changes: 0 additions & 59 deletions .github/workflows/release.yaml

This file was deleted.

50 changes: 50 additions & 0 deletions .github/workflows/update-schemas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# yamllint disable rule:comments
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Update schemas"

'on': workflow_dispatch

jobs:
render-readme:
name: Update schemas
runs-on: gha-runner-scale-set
steps:
- name: Generate Token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
id: generate-token
with:
app_id: "${{ secrets.BOT_APP_ID }}"
private_key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"

- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: "${{ steps.generate-token.outputs.token }}"

- name: Setup Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.11'
cache: 'pip' # caching pip dependencies

- name: Install Requirements
run: |
sudo apt-get update && apt-get install --yes --no-install-recommends git
pip install -r ./.github/scripts/requirements.txt && pip freeze
- name: Setup kubectl
uses: azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.0

- name: Refresh schemas
run: |
./.github/scripts/crd-extractor.sh
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d # v5.0.0
with:
commit_message: "feat: update schemas"
commit_user_name: "RoboDexo2000[bot]"
commit_user_email: "150604236+RoboDexo2000[bot]@users.noreply.github.com"
commit_author: "RoboDexo2000 <150604236+RoboDexo2000[bot]@users.noreply.github.com>"
# yamllint enable rule:comments
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.direnv
.devenv
20 changes: 0 additions & 20 deletions _docker/Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions build.sh

This file was deleted.

61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.yamllint
];
};
}
);
}

0 comments on commit 3029c34

Please sign in to comment.