Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[devops] added scripts and workflows #1

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Deploy Website
on:
pull_request:
types: [closed]
branches:
- "*"
workflow_dispatch:
repository_dispatch:

jobs:
publish-to-github-pages:
name: Build for international
runs-on: ubuntu-latest
timeout-minutes: 20
if: ( github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true )
permissions:
contents: write
steps:
# Checkout Project
- name: Checkout The Docs Repo
uses: actions/checkout@v3

- name: Checkout Cloud Platform Source
uses: actions/checkout@v3
with:
repository: hpcaitech/Cloud-Platform-Docs-Website
token: ${{ secrets.CLOUD_PLATFORM_GITHUB_TOKEN }}
path: Cloud-Platform

# Setup Node.js
- uses: actions/setup-node@v2
with:
node-version: "16"
cache: "yarn"
cache-dependency-path: Cloud-Platform-Docs-Website/cloud-platform-documentation/package-lock.json

# Setup Python 3.8
- uses: actions/setup-python@v2
with:
python-version: "3.8.14"

# Build for international release
- name: 🔨 Build
run: |
PLATFORM_HOSTNAME=platform.colossalai.com bash ./scripts/build.sh Cloud-Platform-Docs-Website
mv Cloud-Platform-Docs-Website/cloud-platform-documentation/build ./

# Deploy to GitHub Pages for international release
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
cname: docs.platform.colossalai.com

publish-to-ali-cloud:
name: Build for China release
runs-on: ubuntu-latest
timeout-minutes: 20
if: ( github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true )
permissions:
contents: write
steps:
# Checkout Project
- name: Checkout The Docs Repo
uses: actions/checkout@v3

- name: Checkout Cloud Platform Source
uses: actions/checkout@v3
with:
repository: hpcaitech/Cloud-Platform-Docs-Website
token: ${{ secrets.CLOUD_PLATFORM_GITHUB_TOKEN }}
path: Cloud-Platform

# Setup Node.js
- uses: actions/setup-node@v2
with:
node-version: "16"
cache: "yarn"
cache-dependency-path: Cloud-Platform-Docs-Website/cloud-platform-documentation/package-lock.json

# Setup Python 3.8
- uses: actions/setup-python@v2
with:
python-version: "3.8.14"

# Build for international release
- name: 🔨 Build
run: |
PLATFORM_HOSTNAME=platform.luchentech.com bash ./scripts/build.sh Cloud-Platform-Docs-Website
mv ./Cloud-Platform-Docs-Website/cloud-platform-documentation/build ./

# scp to cloud server for China release
- name: Deploy to Private Cloud Server
uses: garygrossgarten/github-action-scp@release
with:
local: build
remote: ${{ secrets.CLOUD_SERVER_BUILD_PATH }}
host: ${{ secrets.CLOUD_SERVER_HOST }}
username: ${{ secrets.CLOUD_SERVER_USER }}
password: ${{ secrets.CLOUD_SERVER_PASSWORD }}
dotfiles: true
rmRemote: true
34 changes: 34 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test build
on:
pull_request:
branches:
- "main"

jobs:
publish:
name: Test build
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
# Checkout Project
- name: 📚 Checkout
uses: actions/checkout@v2

- name: Checkout Cloud Platform Docs Website
uses: actions/checkout@v3
with:
repository: hpcaitech/Cloud-Platform-Docs-Website
token: ${{ secrets.CLOUD_PLATFORM_GITHUB_TOKEN }}
path: Cloud-Platform-Docs-Website

# Setup Node.js
- uses: actions/setup-node@v2
with:
node-version: "16"
cache: "yarn"
cache-dependency-path: Cloud-Platform-Docs-Website/cloud-platform-documentation/package-lock.json

# Build
- name: 🔨 Build
run: |
bash ./scripts/build.sh Cloud-Platform-Docs-Website
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ cython_debug/

# MacOS cache
.DS_Store

# cache
.cache/
58 changes: 58 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# set -x # for debug
set -euo pipefail # fail early

# ======================
# Get the arguments
# ======================
WEB_REPO_DIR=${1}
WEB_REPO_DIR=$(realpath $WEB_REPO_DIR)

# ======================
# Set up the variables
# ======================
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR="$SCRIPT_DIR/.."
CACHE_DIR="$ROOT_DIR/.cache"

# ======================
# Set up the website
# ======================
DOCUSAURUS_DIR="$WEB_REPO_DIR/cloud-platform-documentation"

# install the dependency
cd $DOCUSAURUS_DIR
yarn install


# ======================
# Set up the docs
# ======================
# clear blog and docs
rm -rf $DOCUSAURUS_DIR/docs/*
rm -rf $DOCUSAURUS_DIR/blog/*
mkdir -p $DOCUSAURUS_DIR/docs
mkdir -p $DOCUSAURUS_DIR/blog

# replace the docs and blog
cp -r $ROOT_DIR/docs/docs/* $DOCUSAURUS_DIR/docs
cp -r $ROOT_DIR/docs/blog/* $DOCUSAURUS_DIR/blog
cp -r $ROOT_DIR/docs/sidebars.js $DOCUSAURUS_DIR/


# ======================
# Build the website
# ======================
# check if PLATFORM_HOSTNAME is set
# if set, do nothing
# else, set it to platform.luchentech.com
if [ -z ${PLATFORM_HOSTNAME+x} ]; then
echo "[INFO] PLATFORM_HOSTNAME is unset, set it to platform.luchentech.com"
export PLATFORM_HOSTNAME="platform.luchentech.com"
else
echo "[INFO] PLATFORM_HOSTNAME is set to '$PLATFORM_HOSTNAME'"
fi

# build the docs and serve
cd $DOCUSAURUS_DIR
yarn build
8 changes: 8 additions & 0 deletions scripts/install_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# set -x # for debug

# install nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

# install yarn
npm install --global yarn
74 changes: 74 additions & 0 deletions scripts/preview.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# set -x # for debug
set -euo pipefail # fail early

# ======================
# Get the arguments
# ======================
BRANCH=${1:-main}

# ======================
# Set up the variables
# ======================
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR="$SCRIPT_DIR/.."
CACHE_DIR="$ROOT_DIR/.cache"

# ======================
# Set up the website
# ======================
WEB_REPO="[email protected]:hpcaitech/Cloud-Platform-Docs-Website.git"
REPO_DIR="$CACHE_DIR/Cloud-Platform-Docs-Website"
DOCUSAURUS_DIR="$REPO_DIR/cloud-platform-documentation"

mkdir -p $CACHE_DIR
cd $CACHE_DIR

if [ ! -d "$WEB_REPO" ] ; then
git clone "$WEB_REPO"
echo "[INFO] Cloning the website code to ${CACHE_DIR} via ${WEB_REPO}"
else
echo "[INFO] Using existing website code in ${CACHE_DIR}"
fi

# check out to the branch
cd $REPO_DIR
git fetch origin
git checkout $BRANCH

# install the dependency
cd $DOCUSAURUS_DIR
yarn install


# ======================
# Set up the docs
# ======================
# clear blog and docs
rm -rf $DOCUSAURUS_DIR/docs/*
rm -rf $DOCUSAURUS_DIR/blog/*
mkdir -p $DOCUSAURUS_DIR/docs
mkdir -p $DOCUSAURUS_DIR/blog

# replace the docs and blog
cp -r $ROOT_DIR/docs/docs/* $DOCUSAURUS_DIR/docs
cp -r $ROOT_DIR/docs/blog/* $DOCUSAURUS_DIR/blog
cp -r $ROOT_DIR/docs/sidebars.js $DOCUSAURUS_DIR/


# ======================
# Build the website
# ======================
# check if PLATFORM_HOSTNAME is set
# if set, do nothing
# else, set it to platform.luchentech.com
if [ -z ${PLATFORM_HOSTNAME+x} ]; then
echo "[INFO] PLATFORM_HOSTNAME is unset, set it to platform.luchentech.com"
export PLATFORM_HOSTNAME="platform.luchentech.com"
else
echo "[INFO] PLATFORM_HOSTNAME is set to '$PLATFORM_HOSTNAME'"
fi

# build the docs and serve
cd $DOCUSAURUS_DIR
yarn start