speakyourcode/grafana-button-panel

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI

on:
  push:
    branches:
      - master
      - main
  pull_request:
    branches:
      - master
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup Node.js environment
        uses: actions/setup-node@v3
        with:
          node-version: '16.x'

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

      - name: Cache yarn cache
        uses: actions/cache@v3
        id: cache-yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Cache node_modules
        id: cache-node-modules
        uses: actions/cache@v3
        with:
          path: node_modules
          key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Build and test frontend
        run: yarn build

      - name: Start grafana docker
        run: yarn server -d

      - name: Run e2e tests
        run: yarn e2e

      - name: stop grafana docker
        run: docker-compose down

      - name: Check for backend
        id: check-for-backend
        run: |
          if [ -f "Magefile.go" ]
          then
            echo "has-backend=true" >> $GITHUB_OUTPUT
          fi

      - name: Setup Go environment
        if: steps.check-for-backend.outputs.has-backend == 'true'
        uses: actions/setup-go@v3
        with:
          go-version: '1.19'

      - name: Test backend
        if: steps.check-for-backend.outputs.has-backend == 'true'
        uses: magefile/mage-action@v1
        with:
          version: latest
          args: coverage

      - name: Build backend
        if: steps.check-for-backend.outputs.has-backend == 'true'
        uses: magefile/mage-action@v1
        with:
          version: latest
          args: buildAll