|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v2 |
| 12 | + |
| 13 | + - name: Setup Node.js environment |
| 14 | + uses: actions/setup-node@v3 |
| 15 | + with: |
| 16 | + node-version: '14' |
| 17 | + cache: 'yarn' |
| 18 | + |
| 19 | + - name: Install dependencies |
| 20 | + run: yarn install --frozen-lockfile |
| 21 | + |
| 22 | + - name: Build and test frontend |
| 23 | + run: yarn build |
| 24 | + |
| 25 | + - name: Get plugin metadata |
| 26 | + id: metadata |
| 27 | + run: | |
| 28 | + sudo apt-get install jq |
| 29 | +
|
| 30 | + export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id) |
| 31 | + export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version) |
| 32 | + export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type) |
| 33 | + export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip |
| 34 | + export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5 |
| 35 | +
|
| 36 | + echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}" |
| 37 | + echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}" |
| 38 | + echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}" |
| 39 | + echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}" |
| 40 | + echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" |
| 41 | +
|
| 42 | + echo ::set-output name=github-tag::${GITHUB_REF#refs/*/} |
| 43 | +
|
| 44 | + - name: Read changelog |
| 45 | + id: changelog |
| 46 | + run: | |
| 47 | + awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md |
| 48 | + echo "::set-output name=path::release_notes.md" |
| 49 | +
|
| 50 | + - name: Check package version |
| 51 | + 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 |
| 52 | + |
| 53 | + - name: Package plugin |
| 54 | + id: package-plugin |
| 55 | + run: | |
| 56 | + mv dist ${{ steps.metadata.outputs.plugin-id }} |
| 57 | + zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r |
| 58 | + md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }} |
| 59 | + echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" |
| 60 | +
|
| 61 | + # does not work with unsigned plugins! |
| 62 | + # - name: Lint plugin |
| 63 | + # run: | |
| 64 | + # git clone https://github.com/grafana/plugin-validator |
| 65 | + # BIN_PATH=`pwd` |
| 66 | + # pushd ./plugin-validator/pkg/cmd/plugincheck |
| 67 | + # go build -o $BIN_PATH/plugincheck |
| 68 | + # popd |
| 69 | + # ./plugincheck ${{ steps.metadata.outputs.archive }} |
| 70 | + |
| 71 | + - name: Create release |
| 72 | + id: create_release |
| 73 | + uses: actions/create-release@v1 |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + with: |
| 77 | + tag_name: ${{ github.ref }} |
| 78 | + release_name: Release ${{ github.ref }} |
| 79 | + body_path: ${{ steps.changelog.outputs.path }} |
| 80 | + draft: true |
| 81 | + |
| 82 | + - name: Add plugin to release |
| 83 | + id: upload-plugin-asset |
| 84 | + uses: actions/upload-release-asset@v1 |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + with: |
| 88 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 89 | + asset_path: ./${{ steps.metadata.outputs.archive }} |
| 90 | + asset_name: ${{ steps.metadata.outputs.archive }} |
| 91 | + asset_content_type: application/zip |
| 92 | + |
| 93 | + - name: Add checksum to release |
| 94 | + id: upload-checksum-asset |
| 95 | + uses: actions/upload-release-asset@v1 |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + with: |
| 99 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 100 | + asset_path: ./${{ steps.metadata.outputs.archive-checksum }} |
| 101 | + asset_name: ${{ steps.metadata.outputs.archive-checksum }} |
| 102 | + asset_content_type: text/plain |
0 commit comments