Skip to content

Commit

Permalink
Merge pull request #38 from Shaikh-Ubaid/ci_pr_preview
Browse files Browse the repository at this point in the history
CI: Support PR Preview
  • Loading branch information
Shaikh-Ubaid authored Sep 9, 2022
2 parents 98064bc + 3e51eb2 commit 5a977ed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
38 changes: 15 additions & 23 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
branches: [ "main" ]
repository_dispatch:
types: deploy
pull_request:
branches:
- main

jobs:
build:
Expand Down Expand Up @@ -43,28 +46,17 @@ jobs:
run: |
mv out deploy
- name: GIT Setup Config
- name: Upload Site
shell: bash -l {0}
run: |
git config user.email "noreply@deploy"
git config user.name "Deploy"
- name: GIT Checkout gh-pages and Add Deploy files
shell: bash -l {0}
run: |
cp deploy/ ../deploy -r
git reset --hard
git fetch origin
git checkout gh-pages
rm -rf *
mv ../deploy/* .
run: ci/upload_site.sh
env:
GIT_PR_PREVIEW_PRIVATE_SSH_KEY: ${{ secrets.GIT_PR_PREVIEW_PRIVATE_SSH_KEY }}

- name: GIT Add and Commit
shell: bash -l {0}
run: |
git add .
COMMIT_MESSAGE="Deploying on $(date "+%Y-%m-%d %H:%M:%S")"
git commit -m "${COMMIT_MESSAGE}"
- name: GIT Deploy
run: git push origin gh-pages
- name: Create Deployment Comment
if: ${{ github.ref != 'refs/heads/main' && github.event.pull_request.head.repo.name == github.repository }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Your site is deployed at https://preview.dev.lfortran.org/
reactions: 'rocket'
50 changes: 50 additions & 0 deletions ci/upload_site.sh
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

0 comments on commit 5a977ed

Please sign in to comment.