-
Notifications
You must be signed in to change notification settings - Fork 4
201 lines (167 loc) · 7.5 KB
/
plugin-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Plugin release
on:
workflow_dispatch:
inputs:
release:
description: 'Release a new version of the plugin'
required: true
default: false
type: 'boolean'
permissions:
contents: write
id-token: write
jobs:
build-release:
runs-on: ubuntu-latest
env:
plugin-dist-folder: ./packages/grafana-llm-app/dist
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_SIGNING_KEY }} # Requires a Grafana API key from Grafana.com.
outputs:
upload-folder: ${{ steps.metadata.outputs.upload-folder }}
version-tag: ${{ steps.metadata.outputs.plugin-version }}
plugin-id: ${{ steps.metadata.outputs.plugin-id }}
steps:
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_ID }}
installation_id: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_INSTALLATION_ID }}
private_key: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
# Releases should always be made off of 'main'
ref: 'main'
fetch-depth: 0
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 22
- name: Setup Go environment
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Store Go cache paths
id: go-cache-paths
run: echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- name: Restore go-build cache
id: restore-go-build-cache
uses: actions/cache/restore@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-build-
- name: Install utilities
run: sudo apt-get install jq
- name: Install Mage
uses: magefile/mage-action@v3
with:
install-only: true
- name: Install dependencies
run: npm ci
- name: Build plugin
run: npm run build:all
- name: Run frontend tests
run: npm run test:ci
- name: Run backend tests
run: npm run backend:test
- name: Warn missing Grafana API key
run: |
echo Please generate a Grafana API key: https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#generate-an-api-key
echo Once done please follow the instructions found here: https://github.com/${{github.repository}}/blob/main/README.md#using-github-actions-release-workflow
if: ${{ env.GRAFANA_API_KEY == '' }}
- name: Get plugin metadata
id: metadata
run: |
export GRAFANA_PLUGIN_ID=$(cat ${{ env.plugin-dist-folder }}/plugin.json | jq -r .id)
export GRAFANA_PLUGIN_VERSION=$(cat ${{ env.plugin-dist-folder }}/plugin.json | jq -r .info.version)
export GRAFANA_PLUGIN_TYPE=$(cat ${{ env.plugin-dist-folder }}/plugin.json | jq -r .type)
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
export GRAFANA_PLUGIN_ARTIFACT_LATEST=${GRAFANA_PLUGIN_ID}-latest.zip
export GRAFANA_PLUGIN_ARTIFACT_LATEST_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT_LATEST}.md5
echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT
echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT
echo "archive-checksum=${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" >> $GITHUB_OUTPUT
echo "archive-latest=${GRAFANA_PLUGIN_ARTIFACT_LATEST}" >> $GITHUB_OUTPUT
echo "archive-latest-checksum=${GRAFANA_PLUGIN_ARTIFACT_LATEST_CHECKSUM}" >> $GITHUB_OUTPUT
echo "upload-folder=__to-upload__" >> $GITHUB_OUTPUT
- name: Package plugin
uses: sandersaarond/shared-workflows/actions/bundle-plugin@add-bundle-plugin
with:
distDir: ${{ env.plugin-dist-folder }}
- name: Validate plugin
run: |
git clone https://github.com/grafana/plugin-validator
pushd ./plugin-validator/pkg/cmd/plugincheck2
go install
popd
plugincheck2 -config ./plugin-validator/config/default.yaml __to-upload__/${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}
plugincheck2 -config ./plugin-validator/config/default.yaml __to-upload__/latest/${{ steps.metadata.outputs.archive-latest }}
- name: Create tag
uses: rickstaa/action-create-tag@v1
with:
github_token: ${{ steps.get_installation_token.outputs.token }}
message: "chore(tag): tag version ${{ steps.metadata.outputs.plugin-version }} [BOT]"
tag: v${{ steps.metadata.outputs.plugin-version }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: upload-dir
path: __to-upload__
release-and-upload:
runs-on: ubuntu-latest
needs: [ 'build-release' ]
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_SIGNING_KEY }}
GCOM_ROOT: https://grafana.com
steps:
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_ID }}
installation_id: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_INSTALLATION_ID }}
private_key: ${{ secrets.GRAFANA_MACHINE_LEARNING_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
ref: main
token: ${{ steps.get_installation_token.outputs.token }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: upload-dir
path: ${{ needs.build-release.outputs.upload-folder }}
- name: Create Github release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
./${{ needs.build-release.outputs.upload-folder }}/**/*${{ needs.build-release.outputs.version-tag }}*.zip?(.md5)
tag_name: ${{ needs.build-release.outputs.version-tag }}
- id: get-secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
common_secrets: |
GCP_UPLOAD_ARTIFACTS_KEY=grafana/integration-artifacts-uploader-service-account:'credentials.json'
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ env.GCP_UPLOAD_ARTIFACTS_KEY }}
- id: 'upload-to-gcs'
name: 'Upload assets to latest'
uses: 'google-github-actions/upload-cloud-storage@v1'
with:
path: ./${{ needs.build-release.outputs.upload-folder }}
destination: 'integration-artifacts/grafana-llm-app/release/'
parent: false
- id: 'publish-to-gcom'
name: 'Publish to Grafana.com'
uses: 'sandersaarond/shared-workflows/actions/publish-backend-plugin-on-site@publish-plugin-on-site'
with:
plugin-id: ${{ needs.build-release.outputs.plugin-id }}
plugin-version: ${{ needs.build-release.outputs.version-tag }}
plugin-dist: "https://www.github.com/grafana/grafana-llm-app/tree/main/packages/grafana-llm-app/dist"
gcp-bucket: integration-artifacts
gcom-token: ${{ env.GRAFANA_API_KEY }}
gcom-api: ${{ env.GCOM_ROOT }}