-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Deploy Jekyll PR to E4E-DEV | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Execute Deploy | ||
env: | ||
SSH_PRIVATE_KEY: ${{secrets.KASTNER_ML_DEPLOY_SSH}} | ||
SSH_KNOWN_HOSTS: ${{secrets.KASTNER_ML_KNOWN_HOSTS}} | ||
SSH_KEY_PATH: ${{github.workspace}}/../private.key | ||
PR_NUMBER: ${{github.event.number}} | ||
run: | | ||
mkdir -p ~/.ssh/ | ||
echo "$SSH_PRIVATE_KEY" > $SSH_KEY_PATH | ||
chmod 600 $SSH_KEY_PATH | ||
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts | ||
# ssh -i $SSH_KEY_PATH [email protected] '/bin/bash /tmp/deploy_e4e.sh' | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'''E4E Website Development PR Deploy | ||
''' | ||
import datetime as dt | ||
from argparse import ArgumentParser | ||
from os import environ | ||
from pathlib import Path | ||
from shlex import split | ||
from subprocess import check_call | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser() | ||
parser.add_argument('--host', default='[email protected]', type=str) | ||
parser.add_argument('--branch', required=True, type=str) | ||
parser.add_argument('--pr', required=True, type=int) | ||
|
||
args = parser.parse_args() | ||
|
||
CLONE_DIR = Path('/home/deploy/workspace/e4e_tools/website_prs/').joinpath(str(args.pr)) | ||
CLONE_DIR.mkdir(parents=True, exist_ok=True) | ||
if not CLONE_DIR.joinpath('.git').exists(): | ||
cmd = f'git clone --depth 1 --single-branch --branch={args.branch} https://github.com/UCSD-E4E/website2.0.git {CLONE_DIR.as_posix()}' | ||
check_call(split(cmd)) | ||
else: | ||
cmd = f'git fetch --all' | ||
check_call(split(cmd), cwd=CLONE_DIR) | ||
cmd = f'git reset --hard origin/{args.branch}' | ||
check_call(split(cmd), cwd=CLONE_DIR) | ||
|
||
# At this point, the repo should be checked out to latest in the PR at CLONE_DIR | ||
CACHE_DIR = CLONE_DIR.joinpath('cache') | ||
RESIZE_DIR = CACHE_DIR.joinpath('resize') | ||
CACHE_DIR.mkdir(parents=True, exist_ok=True) | ||
RESIZE_DIR.mkdir(parents=True, exist_ok=True) | ||
check_call(split('npm ci'), cwd=CLONE_DIR) | ||
cmd = ['npx', 'gulp', 'build', '-j', f'--baseurl {args.pr} --config _config.yml,_e4e_dev_config.yml'] | ||
check_call(cmd, cwd=CLONE_DIR, ) | ||
assert CLONE_DIR.joinpath('_site').exists() | ||
with open(CLONE_DIR.joinpath('_site', 'last_deployed.txt'), 'w', encoding='utf-8') as handle: | ||
handle.write(dt.datetime.now().isoformat()) | ||
|
||
# Deploy | ||
SITE_DIR = CLONE_DIR.joinpath('_site') | ||
cmd = f'rsync -r -e "ssh -i /home/deploy/.ssh/id_e4edev" --progress {SITE_DIR.as_posix()}/ [email protected]:htdocs/{args.pr}' | ||
|
||
check_call(split(cmd), cwd=CLONE_DIR) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |