Skip to content

Commit

Permalink
chore(dependencies*): generate new ci-node.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquin-diaz committed Feb 12, 2025
1 parent 2b90207 commit b1a7245
Showing 1 changed file with 195 additions and 36 deletions.
231 changes: 195 additions & 36 deletions .github/workflows/ci-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,236 @@ on:
release:
types: [released, prereleased]

permissions: read-all

jobs:
tests:
build:
name: Build, lint and unit tests
runs-on: ubuntu-latest
outputs:
plugin-id: ${{ steps.metadata.outputs.plugin-id }}
plugin-version: ${{ steps.metadata.outputs.plugin-version }}
has-e2e: ${{ steps.check-for-e2e.outputs.has-e2e }}
has-backend: ${{ steps.check-for-backend.outputs.has-backend }}
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci --prefer-offline
run: npm ci

- name: Check types
run: npm run typecheck
- name: Lint
run: npm run lint
- name: Unit tests
run: npm run test:ci
- name: Build frontend for production
if: ${{ github.event_name == 'release' && contains(fromJSON('["released", "prereleased"]'), github.event.action) }}
run: |
npm run build -- --profile --json stats.json
- name: Build frontend
run: |
if [ "${{ github.event_name == 'release' && contains(fromJSON('["released", "prereleased"]'), github.event.action) }}" == "true" ]; then
npm run build -- --profile --json stats.json
else
npm run build
fi
- 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@v5
with:
go-version: '1.22'

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

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

- name: Check for E2E
id: check-for-e2e
run: |
if [ -f "playwright.config.ts" ]
then
echo "has-e2e=true" >> $GITHUB_OUTPUT
fi
- name: Sign plugin
run: npm run sign
if: ${{ env.GRAFANA_API_KEY != '' }}

- name: Get plugin metadata
id: metadata
run: |
sudo apt-get install jq
export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT
- name: Package plugin
id: package-plugin
run: |
mv dist ${{ steps.metadata.outputs.plugin-id }}
zip -r ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
- name: Check plugin.json
run: |
docker run --pull=always \
-v $PWD/${{ steps.metadata.outputs.archive }}:/archive.zip \
grafana/plugin-validator-cli -analyzer=metadatavalid /archive.zip
- name: Archive Build
uses: actions/upload-artifact@v4
with:
name: ${{ steps.metadata.outputs.plugin-id }}-${{ steps.metadata.outputs.plugin-version }}
path: ${{ steps.metadata.outputs.plugin-id }}
retention-days: 5

- name: Upload stats.json artifact
if: ${{ github.event_name == 'release' && contains(fromJSON('["released", "prereleased"]'), github.event.action) }}
uses: actions/upload-artifact@v4
with:
name: main-branch-stats
path: stats.json
overwrite: true

resolve-versions:
name: Resolve e2e images
runs-on: ubuntu-latest
timeout-minutes: 3
needs: build
if: ${{ needs.build.outputs.has-e2e == 'true' }}
outputs:
matrix: ${{ steps.resolve-versions.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version@main

e2e-tests:
playwright-tests:
needs: [resolve-versions, build]
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}}
name: e2e test ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download plugin
uses: actions/download-artifact@v4
with:
fetch-depth: 0
path: dist
name: ${{ needs.build.outputs.plugin-id }}-${{ needs.build.outputs.plugin-version }}

- name: Execute permissions on binary
if: needs.build.outputs.has-backend == 'true'
run: |
chmod +x ./dist/gpx_*
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci --prefer-offline
- name: Build dependencies
run: npm run build
- name: Start Grafana container
run: docker compose --file compose.yaml up --detach
- name: Run e2e tests

- name: Install dev dependencies
run: npm ci

- name: Start Grafana
run: |
docker compose pull
ANONYMOUS_AUTH_ENABLED=false DEVELOPMENT=false GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d
- name: Wait for grafana server
uses: grafana/plugin-actions/wait-for-grafana@main
with:
url: http://localhost:3000/login

- name: Install Playwright Browsers
run: npm exec playwright install chromium --with-deps

- name: Run Playwright tests
id: run-tests
run: npm run e2e
- name: Stop Grafana container
run: docker compose --file compose.yaml down

build:
- name: Docker logs
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
run: |
docker logs embrace-grafana >& grafana-server.log
- name: Stop grafana docker
run: docker compose down

- name: Upload server log
uses: actions/upload-artifact@v4
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
with:
name: ${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}-server-log
path: grafana-server.log
retention-days: 5

# Uncomment this step to upload the Playwright report to Github artifacts.
# If your repository is public, the report will be public on the Internet so beware not to expose sensitive information.
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# if: ${{ always() && steps.run-tests.outcome == 'failure' }}
# with:
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
# path: playwright-report/
# retention-days: 5

upload_release:
name: Upload release
runs-on: ubuntu-latest
needs:
- tests
- e2e-tests
- build
- playwright-tests
if: ${{ github.event_name == 'release' && contains(fromJSON('["released", "prereleased"]'), github.event.action) }}
env:
FILENAME: embraceio-metric-app-${{ github.event.release.tag_name }}.zip
steps:
- uses: actions/checkout@v4

- name: Download plugin
uses: actions/download-artifact@v4
with:
fetch-depth: 0
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
# - name: Update version in package.json and plugin.json
# run: |
# sed -i 's/"version": "0.0.0"/"version": "${{ github.event.release.tag_name }}"/g' package.json src/plugin.json
- name: Install dependencies
run: npm ci --prefer-offline
- name: Build dependencies
run: npm run build
- name: Sign Grafana plugin
run: npx @grafana/sign-plugin
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
path: dist
name: ${{ needs.build.outputs.plugin-id }}-${{ needs.build.outputs.plugin-version }}

- name: Rename dist directory
run: mv dist/ embraceio-metric-app/
- name: Zip app directory
Expand All @@ -87,4 +246,4 @@ jobs:
- name: Upload release
run: gh release upload "${{ github.event.release.tag_name }}" $FILENAME md5.txt --clobber
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ github.token }}

0 comments on commit b1a7245

Please sign in to comment.