Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Split gh workflow generate commands into a matrix #463

Merged
merged 23 commits into from
Oct 27, 2023
139 changes: 96 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,12 @@ jobs:
- name: Setup .npmrc file for NPM registry
uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'

- name: Setup Go environment
uses: actions/setup-go@v3
with:
go-version: '1.20'

- name: Setup Mage
run: |
git clone https://github.com/magefile/mage
cd mage
go run bootstrap.go

- name: Install dependencies
run: npm ci
run: npm ci --no-audit
- name: Check types
run: npm exec nx affected -- --target typecheck --parallel
- name: Lint
Expand All @@ -45,54 +34,118 @@ jobs:
- name: Build all packages
run: npm run build

generate-plugins:
name: Test plugin scaffolding
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's better to use a label for this? Also, why would you want to skip the CI?

Copy link
Collaborator Author

@jackw jackw Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow runs on push and when a package in this repo is published we push changes to main and the commit message contains these strings so we can bypass unnecessary workflow runs.

needs: [test]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- cmd: generate-app
hasBackend: false
- cmd: generate-app-backend
hasBackend: true
- cmd: generate-panel
hasBackend: false
- cmd: generate-datasource
hasBackend: false
- cmd: generate-datasource-backend
hasBackend: true
- cmd: generate-scenes-app
hasBackend: false
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_BRANCH: ${{ github.event.number || github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
fetch-depth: 0
- uses: nrwl/nx-set-shas@v3
- name: Setup .npmrc file for NPM registry
uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'

- name: Install package dependencies
run: npm ci --no-audit

- name: Generate plugin
run: npm exec nx run @grafana/create-plugin:${{ matrix.cmd }}

- name: Restore cached generated plugin dependencies
id: cache-generated-deps-restore
uses: actions/cache/restore@v3
with:
path: |
./packages/create-plugin/generated/package-lock.json
./packages/create-plugin/generated/node_modules
key: ${{ runner.os }}-generated-plugin-deps

- name: '@grafana/create-plugin - test an app plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-app && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint)
- name: '@grafana/create-plugin - test an app with backend plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-app-backend && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint && mage -v build:linux)
- name: '@grafana/create-plugin - test panel plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-panel && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint)
- name: '@grafana/create-plugin - test datasource plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-datasource && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint)
- name: '@grafana/create-plugin - test datasource with backend plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-datasource-backend && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint && mage -v build:linux)
- name: '@grafana/create-plugin - test scenes app plugin generation'
run: npm exec nx run @grafana/create-plugin:generate-scenes-app && (cd ./packages/create-plugin/generated && npm install && npm run build && npm run lint)
key: ${{ matrix.cmd }}-${{ hashFiles('./packages/create-plugin/generated/package-lock.json') }}

- name: Save generated plugin dependencies
id: cache-generated-deps-save
if: steps.cache-generated-deps-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: |
./packages/create-plugin/generated/package-lock.json
./packages/create-plugin/generated/node_modules
key: ${{ steps.cache-generated-deps-restore.outputs.cache-primary-key }}
- name: Install generated plugin dependencies
run: npm install --prefer-offline --no-audit
working-directory: ./packages/create-plugin/generated

- name: Lint plugin frontend
run: npm run lint
working-directory: ./packages/create-plugin/generated

- name: Build plugin frontend
run: npm run build
working-directory: ./packages/create-plugin/generated

- name: '@grafana/sign-plugin - build'
if: ${{ matrix.cmd == 'generate-panel' && github.actor != 'dependabot[bot]' }}
env:
GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}
run: npm exec nx run @grafana/sign-plugin:build

- name: '@grafana/sign-plugin - use GRAFANA_ACCESS_POLICY_TOKEN to sign generated plugin'
if: ${{ github.actor != 'dependabot[bot]' }}
- name: '@grafana/sign-plugin - use GRAFANA_ACCESS_POLICY_TOKEN to sign generate-panel plugin'
if: ${{ matrix.cmd == 'generate-panel' && github.actor != 'dependabot[bot]' }}
env:
GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}
run: node ../../sign-plugin/dist/bin/run.js --rootUrls http://www.example.com --signatureType private
working-directory: ./packages/create-plugin/generated
- name: '@grafana/sign-plugin - use GRAFANA_API_KEY to sign generated plugin'
if: ${{ github.actor != 'dependabot[bot]' }}

- name: '@grafana/sign-plugin - use GRAFANA_API_KEY to sign generate-panel plugin'
if: ${{ matrix.cmd == 'generate-panel' && github.actor != 'dependabot[bot]' }}
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
run: node ../../sign-plugin/dist/bin/run.js --rootUrls http://www.example.com --signatureType private
working-directory: ./packages/create-plugin/generated

- name: Save generated plugin dependencies
id: cache-generated-deps-save
if: ${{ steps.cache-generated-deps-restore.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: |
./packages/create-plugin/generated/package-lock.json
./packages/create-plugin/generated/node_modules
key: ${{ matrix.cmd }}-${{ hashFiles('./packages/create-plugin/generated/package-lock.json') }}

- uses: actions/setup-go@v4
with:
go-version: '~1.20'
check-latest: true
cache-dependency-path: ./packages/create-plugin/generated/go.sum
if: ${{ matrix.hasBackend == true }}

- name: Build plugin backend
uses: magefile/mage-action@v2
with:
version: latest
args: -v build:linux
workdir: ./packages/create-plugin/generated
if: ${{ matrix.hasBackend == true }}

release:
runs-on: ubuntu-latest
needs: test
needs: [test, generate-plugins]
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci') && github.actor != 'dependabot[bot]'"
name: Release packages
env:
Expand All @@ -117,12 +170,12 @@ jobs:
- name: Setup environment
uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'

- name: Install dependencies
run: npm ci
run: npm ci --no-audit

- name: Build
run: npm run build
Expand Down
Loading