|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" # Run workflow on version tags, e.g. v1.0.0. |
| 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.15" |
| 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 | +
|
| 38 | + - name: Cache node_modules |
| 39 | + id: cache-node-modules |
| 40 | + uses: actions/cache@v2 |
| 41 | + with: |
| 42 | + path: node_modules |
| 43 | + key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-${{ matrix.node-version }}-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 "::set-output name=has-backend::true" |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Test backend |
| 65 | + if: steps.check-for-backend.outputs.has-backend == 'true' |
| 66 | + uses: magefile/mage-action@v1 |
| 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@v1 |
| 74 | + 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 | + sudo apt-get install jq |
| 87 | +
|
| 88 | + export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id) |
| 89 | + export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version) |
| 90 | + export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type) |
| 91 | + export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip |
| 92 | + export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5 |
| 93 | +
|
| 94 | + echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}" |
| 95 | + echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}" |
| 96 | + echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}" |
| 97 | + echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}" |
| 98 | + echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" |
| 99 | +
|
| 100 | + echo ::set-output name=github-tag::${GITHUB_REF#refs/*/} |
| 101 | +
|
| 102 | + - name: Read changelog |
| 103 | + id: changelog |
| 104 | + run: | |
| 105 | + awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md |
| 106 | + echo "::set-output name=path::release_notes.md" |
| 107 | +
|
| 108 | + - name: Check package version |
| 109 | + 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 |
| 110 | + |
| 111 | + - name: Package plugin |
| 112 | + id: package-plugin |
| 113 | + run: | |
| 114 | + mv dist ${{ steps.metadata.outputs.plugin-id }} |
| 115 | + zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r |
| 116 | + md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }} |
| 117 | + echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" |
| 118 | +
|
| 119 | + - name: Lint plugin |
| 120 | + run: | |
| 121 | + git clone https://github.com/grafana/plugin-validator |
| 122 | + pushd ./plugin-validator/cmd/plugincheck |
| 123 | + go install |
| 124 | + popd |
| 125 | + plugincheck ${{ steps.metadata.outputs.archive }} |
| 126 | +
|
| 127 | + - name: Create release |
| 128 | + id: create_release |
| 129 | + uses: actions/create-release@v1 |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + with: |
| 133 | + tag_name: ${{ github.ref }} |
| 134 | + release_name: Release ${{ github.ref }} |
| 135 | + body_path: ${{ steps.changelog.outputs.path }} |
| 136 | + draft: true |
| 137 | + |
| 138 | + - name: Add plugin to release |
| 139 | + id: upload-plugin-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 }} |
| 146 | + asset_name: ${{ steps.metadata.outputs.archive }} |
| 147 | + asset_content_type: application/zip |
| 148 | + |
| 149 | + - name: Add checksum to release |
| 150 | + id: upload-checksum-asset |
| 151 | + uses: actions/upload-release-asset@v1 |
| 152 | + env: |
| 153 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 154 | + with: |
| 155 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 156 | + asset_path: ./${{ steps.metadata.outputs.archive-checksum }} |
| 157 | + asset_name: ${{ steps.metadata.outputs.archive-checksum }} |
| 158 | + asset_content_type: text/plain |
| 159 | + |
| 160 | + - name: Publish to Grafana.com |
| 161 | + run: | |
| 162 | + 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: |
| 163 | + echo |
| 164 | + 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