fhfuih is running the deployment π #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: HCI Website Deployment | |
run-name: ${{ github.actor }} is running the deployment π | |
on: [push] | |
jobs: | |
deployment: | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "π The job was automatically triggered by a ${{ github.event_name }} event." | |
- run: echo "π The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- uses: pnpm/[email protected] | |
name: Install pnpm | |
id: pnpm-install | |
with: | |
version: 7 | |
run_install: false | |
- name: Get pnpm store directory | |
id: pnpm-cache | |
run: | | |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Build | |
run: pnpm grunt | |
### Don't use wrapped rsync action. Use handmade hacks below | |
### See https://zellwk.com/blog/github-actions-deploy/ | |
# - uses: burnett01/[email protected] | |
# name: Rsync deployment | |
# with: | |
# switches: -avzr -clOt | |
# path: build | |
# remote_path: /project/hci/public_html/ | |
# remote_host: ${{ secrets.RAS_DEPLOY_HOST }} | |
# remote_user: ${{ secrets.RAS_DEPLOY_USER }} | |
# remote_key: ${{ secrets.RAS_DEPLOY_KEY }} | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.RAS_DEPLOY_KEY }} | |
known_hosts: unnecessary | |
- name: Adding Known Hosts | |
run: ssh-keyscan -H ${{ secrets.RAS_DEPLOY_HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy with rsync | |
run: '{ rsync -avzr ./build/ ${{ secrets.RAS_DEPLOY_USER }}@${{ secrets.RAS_DEPLOY_HOST }}:/project/hci/public_html 2>&1 1>&3 3>&- | grep -v ''failed to set times on "/project/hci/public_html/."''; } 3>&1 1>&2' | |
# This command exeutes rsync and filters out some stderr outputs | |
# Filtering stderr is tricky. Refer to https://stackoverflow.com/questions/9112979/pipe-stdout-and-stderr-to-two-different-processes-in-shell-script | |
# Note that zsh seem to behave different with complex pipe-forwarding syntax. This trick should work fine on bash and sh. Bash is GHAction default | |
# Two [actually one] lines are filtered: | |
# The one that reports rsync: failed to set times on "/project/hci/public_html/.": Operation not permitted (1) | |
# [no, this is deleted] The one that concludes: rsync error: some files could not be transferred (code 23) at <...> [sender=<...>]. Newer versions say "some files/attrs were not transferred" instead | |
# The error may be because the parent folder "/project/hci/public_html" is owned by a anonymous user (not me or any real person). I don't want to bother CS dept for that. | |
# P.S. I will receive warning email from GH at every build if there is any stderr! | |
# P.S. I cannot pass `--delete` to rsync because there is a stubborn and unneeded file also owned by this weird user | |
# P.S. I don't know why github action won't allow me to use a quoted multiline string (https://yaml-multiline.info/), so I have to write it in one line |