SilasBerger / teaching-website

My teaching website 👨‍🏫
https://teach.silasberger.ch
1 stars 0 forks source link

CI: Split re-useable parts (checkout, install, test) out of matrix build #5

Open SilasBerger opened 8 months ago

SilasBerger commented 8 months ago

May be useful: https://github.com/actions/cache, https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows

Concept:

name: Deploy Application
run-name: ${{ github.actor }} is deploying the teaching website 🚀
on:
  push:
    branches:
      - main
      - feature/first-content
  pull_request:
    branches:
      - main
jobs:
  install_and_test:
    runs-on: ubuntu-latest
    name: Install dependencies and run tests
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Node setup
        uses: actions/setup-node@v2
        with:
          node-version: '20.x'
      - name: Yarn install
        run: yarn install --frozen-lockfile
      - name: Test
        run: yarn run test
      # TODO: Cache node installation, checked-out repo, node_modules
  build_and_deploy_sites:
    runs-on: ubuntu-latest
    needs: install_and_test
    name: Build and deploy all sites
    strategy:
      matrix:
        site: [ teach, gbsl, lerbermatt ]
    steps:
      # TODO: Load cached node installation, checked-out repo, node_modules
      - name: Build for site ${{ matrix.site }}
        run: SITE=${{ matrix.site }} npm run build
      - name: RSync to webhost
        uses: Burnett01/rsync-deployments@6.0.0
        with:
          switches: -avzr --delete
          path: build/
          remote_path: ~/sites/${{ matrix.site }}.silasberger.ch/
          remote_host: ${{ secrets.WEBHOST_SSH_HOSTNAME }}
          remote_user: ${{ secrets.WEBHOST_SSH_USERNAME }}
          remote_key: ${{ secrets.WEBHOST_SSH_PRIVATE_KEY }}