1+ # filepath: .github/workflows/release.yml
12name : Release
23
34on :
45 push :
56 tags :
6- - " v*.*.* " # Run workflow on version tags, e.g. v1.0.0.
7+ - ' v* ' # Run workflow on version tags, e.g. v1.0.0.
78
89jobs :
910 release :
11+ permissions :
12+ id-token : write
13+ contents : write
14+ attestations : write
1015 runs-on : ubuntu-latest
11-
1216 steps :
1317 - uses : actions/checkout@v4
1418
15- - name : Setup Node.js environment
16- uses : actions/setup-node@v4
17- with :
18- node-version : " 20.x"
19-
20- - name : Setup Go environment
21- uses : actions/setup-go@v5
22- with :
23- go-version : " 1.26"
24-
25- - name : Get yarn cache directory path
26- id : yarn-cache-dir-path
27- run : echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
28-
29- - name : Cache yarn cache
30- uses : actions/cache@v4
31- id : cache-yarn-cache
32- with :
33- path : ${{ steps.yarn-cache-dir-path.outputs.dir }}
34- key : ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
35- restore-keys : |
36- ${{ runner.os }}-yarn-
37-
38- - name : Cache node_modules
39- id : cache-node-modules
40- uses : actions/cache@v4
41- with :
42- path : node_modules
43- key : ${{ runner.os }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
44- restore-keys : |
45- ${{ runner.os }}-nodemodules-
46-
47- - name : Install dependencies
48- run : yarn install --frozen-lockfile
49- if : |
50- steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
51- steps.cache-node-modules.outputs.cache-hit != 'true'
52-
53- - name : Build and test frontend
54- run : yarn build
55-
56- - name : Check for backend
57- id : check-for-backend
58- run : |
59- if [ -f "Magefile.go" ]
60- then
61- echo "has-backend=true" >> "$GITHUB_OUTPUT"
62- fi
63-
64- - name : Test backend
65- if : steps.check-for-backend.outputs.has-backend == 'true'
66- uses : magefile/mage-action@v3
67- with :
68- version : latest
69- args : coverage
70-
71- - name : Build backend
72- if : steps.check-for-backend.outputs.has-backend == 'true'
73- uses : magefile/mage-action@v3
19+ - uses : grafana/plugin-actions/build-plugin@main
7420 with :
75- version : latest
76- args : buildAll
77-
78- - name : Sign plugin
79- run : yarn sign
80- env :
81- GRAFANA_API_KEY : ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
82-
83- - name : Get plugin metadata
84- id : metadata
85- run : |
86- GRAFANA_PLUGIN_ID=$(jq -r .id dist/plugin.json)
87- GRAFANA_PLUGIN_VERSION=$(jq -r .info.version dist/plugin.json)
88- GRAFANA_PLUGIN_TYPE=$(jq -r .type dist/plugin.json)
89- GRAFANA_PLUGIN_ARTIFACT="${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip"
90- GRAFANA_PLUGIN_ARTIFACT_CHECKSUM="${GRAFANA_PLUGIN_ARTIFACT}.md5"
91-
92- {
93- echo "plugin-id=${GRAFANA_PLUGIN_ID}"
94- echo "plugin-version=${GRAFANA_PLUGIN_VERSION}"
95- echo "plugin-type=${GRAFANA_PLUGIN_TYPE}"
96- echo "archive=${GRAFANA_PLUGIN_ARTIFACT}"
97- echo "archive-checksum=${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
98- echo "github-tag=${GITHUB_REF#refs/*/}"
99- } >> "$GITHUB_OUTPUT"
100-
101- - name : Read changelog
102- id : changelog
103- run : |
104- awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
105- echo "path=release_notes.md" >> "$GITHUB_OUTPUT"
106-
107- - name : Check package version
108- 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
109-
110- - name : Package plugin
111- id : package-plugin
112- run : |
113- mv dist ${{ steps.metadata.outputs.plugin-id }}
114- zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
115- md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
116- echo "checksum=$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
117-
118- - name : Lint plugin
119- run : |
120- git clone https://github.com/grafana/plugin-validator
121- pushd ./plugin-validator/pkg/cmd/plugincheck2
122- go install
123- popd
124- plugincheck2 -config ./plugin-validator/config/default.yaml ${{ steps.metadata.outputs.archive }}
125-
126- - name : Create release
127- env :
128- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
129- run : |
130- gh release create "${{ steps.metadata.outputs.github-tag }}" \
131- --title "Release ${{ steps.metadata.outputs.github-tag }}" \
132- --notes-file "${{ steps.changelog.outputs.path }}" \
133- --draft \
134- "${{ steps.metadata.outputs.archive }}" \
135- "${{ steps.metadata.outputs.archive-checksum }}"
136-
137- - name : Publish to Grafana.com
138- run : |
139- echo A draft release has been created for your plugin. Please review and publish it. Then submit your plugin to grafana.com/plugins by opening a PR to https://github.com/grafana/grafana-plugin-repository with the following entry:
140- echo
141- echo '{ "id": "${{ steps.metadata.outputs.plugin-id }}", "type": "${{ steps.metadata.outputs.plugin-type }}", "url": "https://github.com/${{ github.repository }}", "versions": [ { "version": "${{ steps.metadata.outputs.plugin-version }}", "commit": "${{ github.sha }}", "url": "https://github.com/${{ github.repository }}", "download": { "any": { "url": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}", "md5": "${{ steps.package-plugin.outputs.checksum }}" } } } ] }' | jq .
21+ # refer to https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin#generate-an-access-policy-token to generate it
22+ # save the value in your repository secrets
23+ policy_token : ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}
24+ attestation : true
25+ use_changelog_generator : true # Enable automatic changelog generation
0 commit comments