Skip to content

GITBOOK-62: No subject #9

GITBOOK-62: No subject

GITBOOK-62: No subject #9

Workflow file for this run

name: SH Migrate Documentation to Fluid Topics
on:
push: # Automatically triggers on every commit
branches:
- main # Trigger the workflow on commits to the 'main' branch
workflow_dispatch:
inputs:
COMMIT_HASH:
description: 'Optional commit hash to process'
required: false
environment:
description: 'Select the environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production
jobs:
migrate-docs:
runs-on: self-hosted
steps:
# Step 1: Set up working directory and GitBook folder paths
- name: Set working directory
run: |
export WORK_DIR="workspace_${{ github.run_id }}_${{ github.job }}_${{ github.run_number }}"
export DOCS_FOLDER="$WORK_DIR/gitbook-content"
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_ENV
echo "DOCS_FOLDER=$DOCS_FOLDER" >> $GITHUB_ENV
# Step 2: Checkout GitBook content
- name: Clone GitBook content
run: |
mkdir -p $DOCS_FOLDER
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git $DOCS_FOLDER
cd $DOCS_FOLDER
git checkout ${{ inputs.COMMIT_HASH || github.sha }}
env:
DOCS_FOLDER: ${{ env.DOCS_FOLDER }}
# Step 3: Clone Gitbook-to-FT Utility
- name: Clone Gitbook-to-FT Utility
run: |
git clone https://github.com/jfrog/Gitbook-to-FT.git $WORK_DIR/Gitbook-to-FT
env:
WORK_DIR: ${{ env.WORK_DIR }}
# Step 4: List directory contents
- name: List directory contents
run: |
ls -l $WORK_DIR
ls -l $WORK_DIR/gitbook-content
env:
WORK_DIR: ${{ env.WORK_DIR }}
# Step 5: Install Python and dependencies
- name: Install Python and required dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip
python3 -m pip install --upgrade pip
python3 -m pip install -r $WORK_DIR/Gitbook-to-FT/requirements.txt
env:
WORK_DIR: ${{ env.WORK_DIR }}
# Step 6: Configure environment variables based on selected environment
- name: Set environment variables
run: |
# Default to staging if 'environment' is not set (e.g., in push events)
ENVIRONMENT=${{ github.event.inputs.environment || 'staging' }}
if [[ "$ENVIRONMENT" == "staging" ]]; then
echo "FLUID_TOPICS_BASE_URL=${{ vars.STAGING_FLUID_TOPICS_BASE_URL }}" >> $GITHUB_ENV
echo "FLUID_TOPICS_API_KEY=${{ secrets.STAGING_FLUID_TOPICS_API_KEY }}" >> $GITHUB_ENV
elif [[ "$ENVIRONMENT" == "production" ]]; then
echo "FLUID_TOPICS_BASE_URL=${{ vars.PRODUCTION_FLUID_TOPICS_BASE_URL }}" >> $GITHUB_ENV
echo "FLUID_TOPICS_API_KEY=${{ secrets.PRODUCTION_FLUID_TOPICS_API_KEY }}" >> $GITHUB_ENV
fi
# Step 7: Run the migration utility
- name: Run migration utility
env:
DOCS_FOLDER: ${{ env.DOCS_FOLDER }}
PUBLICATION_TITLE: ${{ vars.PUBLICATION_TITLE }}
run: |
python3 $WORK_DIR/Gitbook-to-FT/md2ft/main.py
# Step 4: List directory contents
- name: List directory contents
run: |
ls -l $WORK_DIR
ls -l $WORK_DIR/gitbook-content
env:
WORK_DIR: ${{ env.WORK_DIR }}
# Step 7: Run the migration utility
- name: Run migration utility
env:
DOCS_FOLDER: ${{ env.DOCS_FOLDER }}
FLUID_TOPICS_API_KEY: ${{ env.FLUID_TOPICS_API_KEY }}
FLUID_TOPICS_BASE_URL: ${{ env.FLUID_TOPICS_BASE_URL }}
FLUID_TOPICS_SOURCE_ID: ${{ vars.FLUID_TOPICS_SOURCE_ID }}
run: |
curl -X POST "${{ env.FLUID_TOPICS_BASE_URL }}/api/admin/khub/sources/${{ env.FLUID_TOPICS_SOURCE_ID }}/upload" \
-H "Authorization: Bearer ${{ env.FLUID_TOPICS_API_KEY }}" \
-F "file=@${{ env.DOCS_FOLDER }}/documentation.zip"
# Step 8: Cleanup temporary directories
- name: Cleanup temporary directories
if: always()
run: |
rm -rf $WORK_DIR
env:
WORK_DIR: ${{ env.WORK_DIR }}