From 52b0f2e5acb003d039ad61f7d8e722d227d5e176 Mon Sep 17 00:00:00 2001 From: OmkarDeshpande7 Date: Sat, 12 Sep 2026 22:36:10 +0530 Subject: [PATCH] add github actions --- .github/workflows/00_rebase_pr.yaml | 93 ++++++++++ .../workflows/01_update_release_notes.yaml | 161 ++++++++++++++++++ .github/workflows/02_backfill_docs.yaml | 105 ++++++++++++ .github/workflows/deploy_gh_page.yaml | 78 +++++++++ .github/workflows/pre_release.yaml | 76 +++++++++ 5 files changed, 513 insertions(+) create mode 100644 .github/workflows/00_rebase_pr.yaml create mode 100644 .github/workflows/01_update_release_notes.yaml create mode 100644 .github/workflows/02_backfill_docs.yaml create mode 100644 .github/workflows/deploy_gh_page.yaml create mode 100644 .github/workflows/pre_release.yaml diff --git a/.github/workflows/00_rebase_pr.yaml b/.github/workflows/00_rebase_pr.yaml new file mode 100644 index 0000000..5737e76 --- /dev/null +++ b/.github/workflows/00_rebase_pr.yaml @@ -0,0 +1,93 @@ +name: Rebase PR + +on: + issue_comment: + types: [created] + workflow_dispatch: # Enable manual triggering + inputs: + branch: + description: 'Select the branch to rebase the PR too' + required: true + +jobs: + check-comment: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + is_rebase: ${{ steps.check-rebase.outputs.is_rebase }} + steps: + - name: Check comment is rebase + if: ${{ github.event.issue.pull_request }} && startsWith(github.event.comment.body || '', '/rebase') + id: check-rebase + run: | + echo "User Comment: $COMMENT_BODY" + echo "is_rebase=true" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMMENT_BODY: ${{ github.event.comment.body }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + rebase: + needs: check-comment + if: ${{ needs.check-comment.outputs.is_rebase }} + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + id-token: write + steps: + - name: Check user permissions + id: check-permissions + run: | + USER_LOGIN="${{ github.event.comment.user.login }}" + COLLABORATORS=$(gh api "/repos/${{ github.repository }}/collaborators" \ + --jq '.[] | select(.permissions.admin == true or .permissions.maintain == true or .permissions.push == true) | .login') + if [[ "$COLLABORATORS" =~ "$USER_LOGIN" ]]; then + echo "is_authorized=true" >> $GITHUB_OUTPUT + else + echo "::error::User $USER_LOGIN lacks required permissions" + gh pr comment ${{ github.event.issue.number }} --body "$USER_LOGIN lacks required permissions. Please contact a maintainer." + exit 1 + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install GitHub CLI + run: | + sudo apt-get update + sudo apt-get install gh + echo "gh cli installed" + + - name: Find latest release branch + id: find_release_branch + run: | + git fetch origin + LATEST_BRANCH=$(git branch -r | grep 'origin/release-v' | sed 's/origin\///' | sort -V | tail -n 1) + echo "Latest release branch: $LATEST_BRANCH" + echo "latest_branch=$LATEST_BRANCH" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Rebase current PR onto latest release branch + if: ${{ needs.check-comment.outputs.is_rebase }} && steps.check-permissions.outputs.is_authorized == 'true' + run: | + # Configure Git + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "GitHub Actions Bot" + + echo "going to branch: $TARGET_BRANCH" + git fetch origin $TARGET_BRANCH + #git rebase origin/$TARGET_BRANCH + gh pr edit ${{ github.event.issue.number }} --base $TARGET_BRANCH + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.event.repository.name }} + TARGET_BRANCH: ${{ steps.find_release_branch.outputs.latest_branch }} diff --git a/.github/workflows/01_update_release_notes.yaml b/.github/workflows/01_update_release_notes.yaml new file mode 100644 index 0000000..832d97b --- /dev/null +++ b/.github/workflows/01_update_release_notes.yaml @@ -0,0 +1,161 @@ +name: Update Release Notes on Release Event + +env: + QCOW2_IMG: ${{ vars.REGISTRY }}/${{ vars.REPO }}/vjailbreak + +on: + release: + types: [published] + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'info' + type: choice + options: + - info + - warning + - debug + environment: + description: 'Environment to run in' + type: environment + required: true + branch: + description: 'Branch to use' + required: true + default: 'gh-pages' + release_tag: + description: 'Manually run for a specific release tag' + required: true + type: text + +jobs: + check-and-wait-for-artifacts: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.get_tag.outputs.tag }} + steps: + - name: Set Tag for Release Event + if: github.event_name == 'release' + id: set_release_tag + run: echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT + + - name: Set Tag for Manual Trigger + if: github.event_name == 'workflow_dispatch' + id: set_manual_tag + run: echo "tag=${{ github.event.inputs.release_tag }}" >> $GITHUB_OUTPUT + + - name: Get Tag + id: get_tag + run: echo "tag=${{ steps.set_release_tag.outputs.tag || steps.set_manual_tag.outputs.tag }}" >> $GITHUB_OUTPUT + + - name: Install Dependencies + run: | + curl -LO https://github.com/oras-project/oras/releases/download/v1.2.1/oras_1.2.1_linux_amd64.tar.gz + sudo tar -C /usr/local/bin/ -xzvf oras_1.2.1_linux_amd64.tar.gz oras + + - name: Wait and check for QCOW image (Max 45 mins) + run: | + RELEASE_TAG="${{ steps.get_tag.outputs.tag }}" + QCOW_IMAGE_URL="${{ env.QCOW2_IMG }}:${RELEASE_TAG}" + + echo "Waiting for artifact to be available at $QCOW_IMAGE_URL" + + for i in $(seq 1 135); do + if oras manifest fetch "$QCOW_IMAGE_URL" &>/dev/null; then + echo "" + echo "Success! Artifact found." + exit 0 + fi + + if [[ $i -eq 135 ]]; then + break + fi + + sleep 20 + done + + echo "" + echo "Artifact not found after 45 minutes. Failing workflow." + exit 1 + + update-release-notes: + needs: check-and-wait-for-artifacts + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: gh-pages + fetch-depth: 0 + + - name: Install GitHub CLI and jq + run: | + sudo apt-get update + sudo apt-get install -y gh jq + + - name: Set Tag from Previous Event + id: set_tag + run: echo "tag=${{ needs.check-and-wait-for-artifacts.outputs.tag }}" >> $GITHUB_OUTPUT + + - name: Generate Notes for New Release + id: process_release + run: | + RELEASE_TAG="${{ steps.set_tag.outputs.tag }}" + + echo ">>> Processing new release: $RELEASE_TAG" + + RELEASE_NOTES=$(gh release view "$RELEASE_TAG" --json body --template '{{.body}}' || echo "") + if [ -z "$RELEASE_NOTES" ]; then + echo "No release notes found for $RELEASE_TAG, skipping." + echo "processed_release=false" >> $GITHUB_OUTPUT + exit 0 + fi + + # find the previous tag + ALL_TAGS_SORTED=$(git tag --sort=version:refname) + LAST_TAG=$(echo "$ALL_TAGS_SORTED" | grep -B 1 -x "$RELEASE_TAG" | head -n 1) + + if [[ -n "$LAST_TAG" && "$LAST_TAG" != "$RELEASE_TAG" ]]; then + echo "Found previous version: $LAST_TAG. Updating version numbers in docs..." + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/introduction/getting_started.mdx + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/components/githubRelease.astro + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/index.mdx + fi + + # Create the new release note file + FILE_NAME="docs/src/content/docs/release_docs/$RELEASE_TAG.md" + mkdir -p "$(dirname "$FILE_NAME")" + { + echo "---" + echo "title: $RELEASE_TAG" + echo "description: Release Notes for $RELEASE_TAG" + echo "---" + echo "" + echo "$RELEASE_NOTES" + } > "$FILE_NAME" + + echo "processed_release=true" >> $GITHUB_OUTPUT + echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Archive and Delete Old Release Notes + if: steps.process_release.outputs.processed_release == 'true' + uses: platform9/vjailbreak/.github/actions/archive-old-release-notes@main + + - name: Create PR with changes + if: steps.process_release.outputs.processed_release == 'true' + uses: platform9/vjailbreak/.github/actions/create-docs-pr@main + with: + branch-prefix: update-release-docs + commit-message: "docs: Update for release ${{ steps.process_release.outputs.release_tag }}" + pr-title: "docs: Update for release ${{ steps.process_release.outputs.release_tag }}" + pr-body: "This PR was automatically generated." + retry: 'false' + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/02_backfill_docs.yaml b/.github/workflows/02_backfill_docs.yaml new file mode 100644 index 0000000..b474636 --- /dev/null +++ b/.github/workflows/02_backfill_docs.yaml @@ -0,0 +1,105 @@ +name: Manual Docs Backfill + +env: + QCOW2_IMG: ${{ vars.REGISTRY }}/${{ vars.REPO }}/vjailbreak + +on: + workflow_dispatch: + inputs: + release_tag: + description: 'Single release tag to process' + required: false + process_all_recent: + description: 'Process all missing releases' + required: true + default: true + type: boolean + +jobs: + backfill-release-notes: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + + steps: + - name: Checkout gh-pages Branch + uses: actions/checkout@v4 + with: + ref: gh-pages + fetch-depth: 0 + + - name: Install GitHub CLI and jq + run: sudo apt-get update && sudo apt-get install -y gh jq skopeo + + - name: Process and Generate Release Notes + id: process_releases + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # This function processes a single release tag + process_release() { + local RELEASE_TAG=$1 + if [ -f "docs/src/content/docs/release_docs/$RELEASE_TAG.md" ]; then + echo "Documentation for $RELEASE_TAG already exists, skipping." + return 0 + fi + + local QCOW_IMAGE_URI="docker://${{ env.QCOW2_IMG }}:${RELEASE_TAG}" + echo "--> Checking for image: $QCOW_IMAGE_URI" + if ! skopeo inspect "$QCOW_IMAGE_URI" &>/dev/null; then + echo "::warning::Image not found for tag $RELEASE_TAG. Skipping doc generation for this release." + return 0 + fi + echo "--> Image found. Proceeding with doc generation." + + echo ">>> Processing release: $RELEASE_TAG" + RELEASE_NOTES=$(gh release view "$RELEASE_TAG" --json body --template '{{.body}}' || echo "") + if [ -z "$RELEASE_NOTES" ]; then + echo "No release notes found for $RELEASE_TAG, skipping."; return 0 + fi + + local ALL_TAGS_SORTED=$(git tag --sort=version:refname) + local LAST_TAG=$(echo "$ALL_TAGS_SORTED" | grep -B 1 -x "$RELEASE_TAG" | head -n 1) + + if [[ -n "$LAST_TAG" && "$LAST_TAG" != "$RELEASE_TAG" ]]; then + echo "Found previous version: $LAST_TAG. Updating docs..." + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/introduction/getting_started.mdx + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/components/githubRelease.astro + sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/index.mdx + fi + + local FILE_NAME="docs/src/content/docs/release_docs/$RELEASE_TAG.md" + mkdir -p "$(dirname "$FILE_NAME")" + { echo "---"; echo "title: $RELEASE_TAG"; echo "description: Release Notes for $RELEASE_TAG"; echo "---"; echo ""; echo "$RELEASE_NOTES"; } > "$FILE_NAME" + echo "Created documentation file: $FILE_NAME" + PROCESSED_LIST_TEMP+="$RELEASE_TAG " + } + export -f process_release + PROCESSED_LIST_TEMP="" + + if [[ -n "${{ github.event.inputs.release_tag }}" ]]; then + echo "Processing single specified release..." + process_release "${{ github.event.inputs.release_tag }}" + elif [[ "${{ github.event.inputs.process_all_recent }}" == "true" ]]; then + echo "Processing all recent missing releases..." + ALL_RELEASES=$(gh release list --limit 100 --json tagName --jq '.[].tagName' | sort -V) + for TAG in $ALL_RELEASES; do process_release "$TAG"; done + fi + + echo "PROCESSED_RELEASES=${PROCESSED_LIST_TEMP}" >> $GITHUB_OUTPUT + + - name: Archive and Delete Old Release Notes + if: steps.process_releases.outputs.PROCESSED_RELEASES != '' + uses: platform9/vjailbreak/.github/actions/archive-old-release-notes@main + + - name: Create PR with changes + if: steps.process_releases.outputs.PROCESSED_RELEASES != '' + uses: platform9/vjailbreak/.github/actions/create-docs-pr@main + with: + branch-prefix: backfill-docs + commit-message: "docs: Backfill missing release documentation for ${{ steps.process_releases.outputs.PROCESSED_RELEASES }}" + pr-title: "docs: Backfill release documentation for ${{ steps.process_releases.outputs.PROCESSED_RELEASES }}" + pr-body: "This PR was automatically generated to backfill documentation for one or more releases." + retry: 'true' + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/deploy_gh_page.yaml b/.github/workflows/deploy_gh_page.yaml new file mode 100644 index 0000000..3a3db16 --- /dev/null +++ b/.github/workflows/deploy_gh_page.yaml @@ -0,0 +1,78 @@ +name: Deploy Docs & API Documentation + + +on: + # Trigger the workflow every time you push to the `gh-pages` branch + # Using a different branch name? Replace `gh-pages` with your branch’s name + push: + branches: [ gh-pages ] + # Allows you to run this workflow manually from the Actions tab on GitHub. + workflow_dispatch: + inputs: + branch: + description: 'Branch to use' + required: true + default: 'gh-pages' +# Allow this job to clone the repo and create a page deployment +permissions: + contents: write + pages: write + id-token: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout your repository using git + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install yq for OpenAPI generation + run: | + wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq + chmod +x /usr/local/bin/yq + + - name: Generate Swagger UI for all tags + run: | + chmod +x scripts/generate_all_openapi.sh + ./scripts/generate_all_openapi.sh + + - name: Generate Swagger UI links for all versions + run: ./scripts/generate_swagger_links.sh + + - name: List Swagger UI build output + run: ls -alR docs/public/swagger-ui/ || echo "No Swagger UI build output found" + + - name: Check generated Swagger UI links file + run: | + if [ -f docs/src/content/docs/guides/using_apis.md ]; then + head -20 docs/src/content/docs/guides/using_apis.md + else + echo "File not found: docs/src/content/docs/guides/using_apis.md" + fi + + - name: Install, build, and upload your site + env: + SITE_URL: ${{ env.SITE_URL }} + BASE: ${{ github.event.repository.name }} + uses: withastro/action@v4 + with: + path: docs/ # The root location of your Astro project inside the repository. (optional) + # node-version: 20 # The specific version of Node that should be used to build your site. Defaults to 20. (optional) + # package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional) + - name: Print Astro site configuration + run: | + echo "Astro Configuration:" + cat ./docs/astro.config.mjs + + deploy: + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml new file mode 100644 index 0000000..edf4f66 --- /dev/null +++ b/.github/workflows/pre_release.yaml @@ -0,0 +1,76 @@ +name: Pre-Release + +on: + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v0.4.0)" + required: true + type: string + branch: + description: "Branch to use (default: main)" + required: false + default: "main" + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + generate-crds: + name: Generate CRDs and Installer + runs-on: ubuntu-latest + + steps: + - name: Checkout branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.branch || 'main' }} + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: k8s/migration/go.mod + cache-dependency-path: k8s/migration/go.sum + + - name: Install controller-gen + run: | + go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.1 + + - name: Setup Kustomize + uses: imranismail/setup-kustomize@v2 + with: + kustomize-version: '5.3.0' + + - name: Run build-installer + run: | + cd k8s/migration + make build-installer TAG=${{ github.event.inputs.tag }} + + - name: Check for changes + id: changes + run: | + if [[ -n "$(git status --porcelain)" ]]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Disable git hooks + if: steps.changes.outputs.changes == 'true' + run: git config core.hooksPath /dev/null + + - name: Create Pull Request + if: steps.changes.outputs.changes == 'true' + uses: peter-evans/create-pull-request@v6 + with: + branch: pre-release/${{ github.event.inputs.tag }} + base: main + commit-message: "chore: generate CRDs and installer for ${{ github.event.inputs.tag }}" + title: "chore: Pre-release CRD generation for ${{ github.event.inputs.tag }}" + body: | + Auto-generated CRDs and installer manifests for `${{ github.event.inputs.tag }}`. + + Please review and merge before creating the release. \ No newline at end of file