1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+
8+ jobs :
9+ release :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - uses : actions/checkout@v2
14+
15+ - name : Setup Node.js environment
16+ 17+ with :
18+ node-version : ' 14.x'
19+
20+ - name : Setup Go environment
21+ uses : actions/setup-go@v2
22+ with :
23+ go-version : ' 1.17'
24+
25+ - name : Get yarn cache directory path
26+ id : yarn-cache-dir-path
27+ run : echo "::set-output name=dir::$(yarn cache dir)"
28+
29+ - name : Cache yarn cache
30+ uses : actions/cache@v2
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+ - name : Cache node_modules
38+ id : cache-node-modules
39+ uses : actions/cache@v2
40+ with :
41+ path : node_modules
42+ key : ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
43+ restore-keys : |
44+ ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
45+ - name : Install dependencies
46+ run : yarn install --frozen-lockfile;
47+ if : |
48+ steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
49+ steps.cache-node-modules.outputs.cache-hit != 'true'
50+ - name : Build and test frontend
51+ run : yarn build
52+
53+ - name : Check for backend
54+ id : check-for-backend
55+ run : |
56+ if [ -f "Magefile.go" ]
57+ then
58+ echo "::set-output name=has-backend::true"
59+ fi
60+ - name : Test backend
61+ if : steps.check-for-backend.outputs.has-backend == 'true'
62+ uses : magefile/mage-action@v1
63+ with :
64+ version : latest
65+ args : coverage
66+
67+ - name : Build backend
68+ if : steps.check-for-backend.outputs.has-backend == 'true'
69+ uses : magefile/mage-action@v1
70+ with :
71+ version : latest
72+ args : buildAll
73+
74+ - name : Sign plugin
75+ run : yarn sign
76+ env :
77+ GRAFANA_API_KEY : ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
78+
79+ - name : Get plugin metadata
80+ id : metadata
81+ run : |
82+ sudo apt-get install jq
83+ export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
84+ export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
85+ export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
86+ export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
87+ export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
88+ echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}"
89+ echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}"
90+ echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}"
91+ echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}"
92+ echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
93+ echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
94+ - name : Read changelog
95+ id : changelog
96+ run : |
97+ awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
98+ echo "::set-output name=path::release_notes.md"
99+ - name : Check package version
100+ 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
101+
102+ - name : Package plugin
103+ id : package-plugin
104+ run : |
105+ mv dist ${{ steps.metadata.outputs.plugin-id }}
106+ zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
107+ md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
108+ echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
109+ - name : Lint plugin
110+ run : |
111+ git clone https://github.com/grafana/plugin-validator
112+ pushd ./plugin-validator/pkg/cmd/plugincheck
113+ go install
114+ popd
115+ plugincheck ${{ steps.metadata.outputs.archive }}
116+ - name : Create release
117+ id : create_release
118+ uses : actions/create-release@v1
119+ env :
120+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121+ with :
122+ tag_name : ${{ github.ref }}
123+ release_name : Release ${{ github.ref }}
124+ body_path : ${{ steps.changelog.outputs.path }}
125+ draft : true
126+
127+ - name : Add plugin to release
128+ id : upload-plugin-asset
129+ uses : actions/upload-release-asset@v1
130+ env :
131+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
132+ with :
133+ upload_url : ${{ steps.create_release.outputs.upload_url }}
134+ asset_path : ./${{ steps.metadata.outputs.archive }}
135+ asset_name : ${{ steps.metadata.outputs.archive }}
136+ asset_content_type : application/zip
137+
138+ - name : Add checksum to release
139+ id : upload-checksum-asset
140+ uses : actions/upload-release-asset@v1
141+ env :
142+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
143+ with :
144+ upload_url : ${{ steps.create_release.outputs.upload_url }}
145+ asset_path : ./${{ steps.metadata.outputs.archive-checksum }}
146+ asset_name : ${{ steps.metadata.outputs.archive-checksum }}
147+ asset_content_type : text/plain
148+
149+ - name : Publish to Grafana.com
150+ run : |
151+ 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:
152+ echo
153+ 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 .
0 commit comments