Update README.md #54
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
name: Frontend CI/CD | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 'lts/*' | |
- name: Install dependencies | |
run: npm install | |
working-directory: . | |
- name: Build project | |
run: npm run build | |
working-directory: . | |
- name: install ssh keys | |
# check this thread to understand why its needed: | |
# https://stackoverflow.com/a/70447517 | |
run: | | |
install -m 600 -D /dev/null ~/.ssh/id_rsa | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts | |
- name: connect and pull | |
run: | | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' | |
cd ${{ secrets.WORK_DIR }} | |
git fetch origin | |
UPSTREAM=${{ secrets.MAIN_BRANCH }} | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u}) | |
BASE=$(git merge-base @ @{u}) | |
if [ $LOCAL = $REMOTE ]; then | |
echo "Already up to date." | |
elif [ $LOCAL = $BASE ]; then | |
git pull | |
else | |
echo "Diverged - manual intervention needed" | |
exit 1 | |
fi | |
cd | |
cd ${{ secrets.ROOT_DIR }} | |
docker compose stop frontend | |
docker compose rm -f frontend | |
docker compose up --build -d frontend | |
exit | |
EOF | |
- name: cleanup | |
run: rm -rf ~/.ssh | |