Merge branch 'main' of github.com:sandwichfarm/myrelay.site into main #148
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: deploy | |
on: | |
push | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: install | |
env: | |
NODE_OPTIONS: "--max_old_space_size=4096" | |
run: | | |
yarn install | |
- name: build | |
run: yarn build | |
- name: get-npm-version | |
if: github.ref == 'refs/heads/main' | |
id: package-version | |
uses: martinbeentjes/[email protected] | |
- name: Install SSH Key | |
if: github.ref == 'refs/heads/main' | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }} | |
- name: Adding Known Hosts | |
if: github.ref == 'refs/heads/main' | |
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy with rsync | |
if: github.ref == 'refs/heads/main' | |
run: | | |
TARGET_DIR="/var/www/html/${{ steps.package-version.outputs.current-version}}" | |
rsync -a --rsync-path="mkdir -p $TARGET_DIR && rsync" ./build/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$TARGET_DIR | |
- name: Update symlink | |
if: github.ref == 'refs/heads/main' | |
env: | |
WEB_PATH: "/var/www/html" | |
run: | | |
LATEST_PATH="${WEB_PATH}/latest" | |
VERSIONED_PATH="${WEB_PATH}/${{ steps.package-version.outputs.current-version }}" | |
sudo rm -f "$LATEST_PATH" | |
sudo ln -sf "$VERSIONED_PATH" "$LATEST_PATH" |