-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Shaikh-Ubaid/ci_pr_preview
CI: Support PR Preview
- Loading branch information
Showing
2 changed files
with
65 additions
and
23 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
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 @@ | ||
#/usr/bin/bash | ||
|
||
set -ex | ||
|
||
git_ref=${GITHUB_REF} | ||
|
||
if [[ ${git_ref} == "refs/heads/main" ]]; then | ||
# Production version - pipeline triggered from main branch | ||
deploy_repo_pull="https://github.com/lfortran/lcompilers_frontend.git" | ||
deploy_repo_push="[email protected]:lfortran/lcompilers_frontend.git" | ||
else | ||
# Test version - pipeline triggered from pull request | ||
deploy_repo_pull="https://github.com/lfortran/pull_request_preview.git" | ||
deploy_repo_push="[email protected]:lfortran/pull_request_preview.git" | ||
fi | ||
|
||
|
||
mkdir ~/.ssh | ||
chmod 700 ~/.ssh | ||
ssh-keyscan github.com >> ~/.ssh/known_hosts | ||
eval "$(ssh-agent -s)" | ||
|
||
D=`pwd` | ||
|
||
mkdir $HOME/repos | ||
cd $HOME/repos | ||
|
||
git clone ${deploy_repo_pull} pr_preview | ||
cd pr_preview | ||
git fetch origin | ||
git checkout gh-pages | ||
rm -rf * | ||
mv $D/deploy/* . | ||
|
||
git config user.email "noreply@deploy" | ||
git config user.name "Deploy" | ||
|
||
git add . | ||
COMMIT_MESSAGE="Deploying on $(date "+%Y-%m-%d %H:%M:%S")" | ||
git commit -m "${COMMIT_MESSAGE}" | ||
|
||
if [[ ${git_ref} != "refs/heads/main" ]]; then | ||
if [[ "${GIT_PR_PREVIEW_PRIVATE_SSH_KEY}" == "" ]]; then | ||
echo "Note: GIT_PR_PREVIEW_PRIVATE_SSH_KEY is empty, skipping..." | ||
exit 0 | ||
fi | ||
ssh-add <(echo "$GIT_PR_PREVIEW_PRIVATE_SSH_KEY" | base64 -d) | ||
fi | ||
|
||
git push ${deploy_repo_push} gh-pages:gh-pages |