Skip to content

Commit

Permalink
Create Plugin: Add bundle stats workflow (#1357)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackw authored Dec 9, 2024
1 parent 6bb5a7e commit 96041e3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
28 changes: 28 additions & 0 deletions docusaurus/docs/get-started/set-up-development-environment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ jobs:
token: ${{ secrets.GH_PAT_TOKEN }}
```

### The bundle stats workflow

The bundle stats (`bundle-stats.yml`) workflow is intended to help developers keep an eye on the size of their plugins frontend assets. Changes in PRs trigger this workflow which will compare two webpack stats files; one from the default branch and the other from the PR. It then calculates differences between these assets sizes and posts a formatted comment to the PR giving an overview of any size differences.

```yaml title="bundle-stats.yml"
name: Bundle Stats
on:
pull_request:
branches:
- main
permissions:
contents: write
pull-requests: write
actions: read
jobs:
compare:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: grafana/plugin-actions/bundle-size@main
```

## Extend configurations

The `.config/` directory holds the preferred configuration for the different tools used to develop, test, and build a Grafana plugin. Although you can make changes, we recommend against doing so. Instead, follow the guidance in this topic to customize your tooling configs.
Expand Down
21 changes: 21 additions & 0 deletions packages/create-plugin/templates/github/workflows/bundle-stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Bundle Stats

on:
pull_request:
branches:
- main

permissions:
contents: write
pull-requests: write
actions: read

jobs:
compare:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: grafana/plugin-actions/bundle-size@main
15 changes: 14 additions & 1 deletion packages/create-plugin/templates/github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ jobs:
- name: Unit tests
run: {{ packageManagerName }} run test:ci
- name: Build frontend
run: {{ packageManagerName }} run build
run: |
if [ "$\{{ github.event_name }}" == "push" ] && [ "$\{{ github.ref }}" == "refs/heads/main" ]; then
{{ packageManagerName }} run build{{#if isNPM}} --{{/if}} --profile --json stats.json
else
{{ packageManagerName }} run build
fi
- name: Check for backend
id: check-for-backend
Expand Down Expand Up @@ -121,6 +126,14 @@ jobs:
path: $\{{ steps.metadata.outputs.plugin-id }}
retention-days: 5

- name: Upload stats.json artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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
Expand Down

0 comments on commit 96041e3

Please sign in to comment.