Continuous Integration / Continuous Development

GitHub Actions for YaMa

Automate Playwright testing

This action installs Playwright, with the necessary dependencies, so that all of the tests can run before deploying to Vercel.

name: Playwright Tests
on:
  push:
    branches: [ main, master, testing ]
  pull_request:
    branches: [ main, master, testing ]
jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: '14.x'
    - name: Install dependencies
      run: npm i
    - name: Install Playwright
      run: npx playwright install --with-deps
    - name: Install Microsoft Edge
      run: npx playwright install msedge
    - name: Install Google Chrome
      run: npx playwright install chrome
    - name: Run Playwright tests
      run: npx playwright test
    - uses: actions/upload-artifact@v2
      if: failure()
      with:
        name: playwright-report
        path: playwright-report/
        retention-days: 7

Deploy YaMa to Vercel

This action installs Vercel and then deploys the app.

The benefit of this action is that an instance of Vercel is initialised only when needed.

name: Deploy to Vercel
on:
  push:
    branches: [ main, testing ]
jobs:
  buildAndDeploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Setup Node.js (required to install Vercel CLI)
        uses: actions/setup-node@v3

      - name: Install Vercel CLI
        run: npm install --global vercel
        
      - name: Deploy static content to Vercel
        run: |
          productionFlag=""
          if [[ ${GITHUB_REF} == "refs/heads/main" ]]; then
            productionFlag="--prod"
          fi
          vercel . --token ${VERCEL_TOKEN} $productionFlag
        env:
          VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
          VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
          VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

Automate the build and deployment of the mdBook site.

This action installs mdBook, installs Admonish for Material UI call-outs styling, builds the book (html files), and then deploys it to Vercel .

The benefit of this action is that an instance of mdBook is initialised only when needed.

Note

The following Environment Variables should be added as Encrypted Secrets in GitHub.

VERCEL_TOKEN refers to the special access token which will be used to authenticate the login session in the CI/CD environment. Refer to this support article on Vercel Access Token for more information. The VERCEL_PROJECT_ID & VERCEL_ORG_ID are found inside the .vercel/project.json file of your project.

name: Build Book & Deploy to Vercel

on: [push, pull_request]

jobs:
  buildAndDeploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Install mdBook
        uses: extractions/setup-crate@v1
        with:
          owner: rust-lang
          name: mdBook

      - name: Install mdBook Admonish
        run: cargo install mdbook-admonish

      - name: Add required files and configuration for Admonish
        run: mdbook-admonish install

      - name: Generate static content for the book
        run: mdbook build

      - name: Setup Node.js (required to install Vercel CLI)
        uses: actions/setup-node@v3

      - name: Install Vercel CLI
        run: npm install --global vercel

      - name: Deploy static content to Vercel
        run: |
          productionFlag=""
          if [[ ${GITHUB_REF} == "refs/heads/main" ]]; then
            productionFlag="--prod"
          fi

          vercel . --token ${VERCEL_TOKEN} $productionFlag
        env:
          VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
          VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
          VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

Automate the saving of .drawio files to .png.

Note

In order for this action to work, the .drawio file must have changed after this action was initially run.

If no changes have been made to the .drawio file, this action will not do anything.

name: Export drawio files to png and keep updates synchronised
on:
  push:
    branches: [ main, testing ]
  pull_request:
    branches: [ main, testing ]  
    paths:
      - "**.drawio"
      - .github/workflows/drawio-export-png.yaml
concurrency:
  group: drawio-export-${{ github.ref }}
  cancel-in-progress: true
jobs:
  drawio-export:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Draw.io Export Action
        uses: rlespinasse/drawio-export-action@2.1.0
        with:
            # Path to the drawio files to export
            path: diagrams
            # Exported format [default: pdf] [possible values: adoc, jpg, pdf, png, svg, vsdx, xml]
            format: png
            # Exported folder name (default location is same a path above)
            output: ../src/media
            # Remove the Page label (i.e. Page-1) from file name
            remove-page-suffix: true
            # Sets the border width around the diagram
            border: 5

      - name: Get author and committer info from HEAD commit
        uses: rlespinasse/git-commit-data-action@v1
        if: github.ref == 'refs/heads/main'

      - name: Commit changed files
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "docs: sync drawio exported files"
          commit_user_name: "${{ env.GIT_COMMIT_COMMITTER_NAME }}"
          commit_user_email: "${{ env.GIT_COMMIT_COMMITTER_EMAIL }}"
          commit_author: "${{ env.GIT_COMMIT_AUTHOR }}"
        if: github.ref == 'refs/heads/main'