Skip to content

Commit dd4219a

Browse files
Change release workflow
1 parent e04fa83 commit dd4219a

File tree

1 file changed

+121
-15
lines changed

1 file changed

+121
-15
lines changed

.github/workflows/release.yml

+121-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,132 @@
1-
# This GitHub Action automates the process of building Grafana plugins.
2-
# (For more information, see https://github.com/grafana/plugin-actions/blob/main/build-plugin/README.md)
31
name: Release
42

53
on:
64
push:
75
tags:
86
- 'v*' # Run workflow on version tags, e.g. v1.0.0.
97

10-
permissions: read-all
11-
128
jobs:
139
release:
14-
permissions:
15-
contents: write
1610
runs-on: ubuntu-latest
11+
env:
12+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
1713
steps:
18-
- uses: actions/checkout@v4
19-
- uses: grafana/plugin-actions/build-plugin@main
20-
# Uncomment to enable plugin signing
21-
# (For more info on how to generate the access policy token see https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin#generate-an-access-policy-token)
22-
#with:
23-
# Make sure to save the token in your repository secrets
24-
#policy_token: $
25-
# Usage of GRAFANA_API_KEY is deprecated, prefer `policy_token` option above
26-
#grafana_token: $
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Node.js environment
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '22'
20+
cache: 'yarn'
21+
22+
- name: Setup Go environment
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: '1.23'
26+
27+
- name: Install dependencies
28+
run: yarn install --immutable --prefer-offline
29+
30+
- name: Build and test frontend
31+
run: yarn build
32+
33+
- name: Check for backend
34+
id: check-for-backend
35+
run: |
36+
if [ -f "Magefile.go" ]
37+
then
38+
echo "has-backend=true" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Test backend
42+
if: steps.check-for-backend.outputs.has-backend == 'true'
43+
uses: magefile/mage-action@v1
44+
with:
45+
version: latest
46+
args: coverage
47+
48+
- name: Build backend
49+
if: steps.check-for-backend.outputs.has-backend == 'true'
50+
uses: magefile/mage-action@v1
51+
with:
52+
version: latest
53+
args: buildAll
54+
55+
- name: Warn missing Grafana API key
56+
run: |
57+
echo Please generate a Grafana API key: https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#generate-an-api-key
58+
echo Once done please follow the instructions found here: https://github.com/${{github.repository}}/blob/main/README.md#using-github-actions-release-workflow
59+
if: ${{ env.GRAFANA_API_KEY == '' }}
60+
61+
- name: Sign plugin
62+
run: yarn sign || exit 0
63+
if: ${{ env.GRAFANA_API_KEY != '' }}
64+
65+
- name: Get plugin metadata
66+
id: metadata
67+
run: |
68+
sudo apt-get install jq
69+
70+
export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
71+
export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
72+
export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
73+
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
74+
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
75+
76+
echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
77+
echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
78+
echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT
79+
echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT
80+
echo "archive-checksum=${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" >> $GITHUB_OUTPUT
81+
82+
echo "github-tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
83+
84+
- name: Read changelog
85+
id: changelog
86+
run: |
87+
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
88+
echo "path=release_notes.md" >> $GITHUB_OUTPUT
89+
90+
- name: Check package version
91+
run: if [ "v${{ steps.metadata.outputs.plugin-version }}" != "${{ steps.metadata.outputs.github-tag }}" ]; then printf "\033[0;31mPlugin version doesn't match tag name\033[0m\n"; exit 1; fi
92+
93+
- name: Package plugin
94+
id: package-plugin
95+
run: |
96+
mv dist ${{ steps.metadata.outputs.plugin-id }}
97+
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
98+
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
99+
echo "checksum=$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" >> $GITHUB_OUTPUT
100+
101+
- name: Validate plugin
102+
run: |
103+
git clone https://github.com/grafana/plugin-validator
104+
pushd ./plugin-validator/pkg/cmd/plugincheck2
105+
go install
106+
popd
107+
plugincheck2 -config ./plugin-validator/config/default.yaml ${{ steps.metadata.outputs.archive }}
108+
109+
- name: Create Github release
110+
uses: softprops/action-gh-release@v1
111+
with:
112+
draft: true
113+
generate_release_notes: true
114+
files: |
115+
./${{ steps.metadata.outputs.archive }}
116+
./${{ steps.metadata.outputs.archive-checksum }}
117+
body: |
118+
**This Github draft release has been created for your plugin.**
119+
120+
_Note: if this is the first release for your plugin please consult the [distributing-your-plugin section](https://github.com/${{github.repository}}/blob/main/README.md#distributing-your-plugin) of the README_
121+
122+
If you would like to submit this release to Grafana please consider the following steps:
123+
124+
- Check the Validate plugin step in the [release workflow](https://github.com/${{github.repository}}/commit/${{github.sha}}/checks/${{github.run_id}}) for any warnings that need attention
125+
- Navigate to https://grafana.com/auth/sign-in/ to sign into your account
126+
- Once logged in click **My Plugins** in the admin navigation
127+
- Click the **Submit Plugin** button
128+
- Fill in the Plugin Submission form:
129+
- Paste this [.zip asset link](https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}) in the Plugin URL field
130+
- Paste this [.zip.md5 link](https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive-checksum }}) in the MD5 field
131+
132+
Once done please remove these instructions and publish this release.

0 commit comments

Comments
 (0)