|
| 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: Get yarn cache directory path |
| 21 | + id: yarn-cache-dir-path |
| 22 | + run: echo "::set-output name=dir::$(yarn cache dir)" |
| 23 | + |
| 24 | + - name: Cache yarn cache |
| 25 | + uses: actions/cache@v2 |
| 26 | + id: cache-yarn-cache |
| 27 | + with: |
| 28 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 29 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 30 | + restore-keys: | |
| 31 | + ${{ runner.os }}-yarn- |
| 32 | +
|
| 33 | + - name: Cache node_modules |
| 34 | + id: cache-node-modules |
| 35 | + uses: actions/cache@v2 |
| 36 | + with: |
| 37 | + path: node_modules |
| 38 | + key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }} |
| 39 | + restore-keys: | |
| 40 | + ${{ runner.os }}-${{ matrix.node-version }}-nodemodules- |
| 41 | +
|
| 42 | + - name: Install dependencies |
| 43 | + run: yarn install --frozen-lockfile; |
| 44 | + if: | |
| 45 | + steps.cache-yarn-cache.outputs.cache-hit != 'true' || |
| 46 | + steps.cache-node-modules.outputs.cache-hit != 'true' |
| 47 | +
|
| 48 | + - name: Build and test frontend |
| 49 | + run: yarn build |
| 50 | + |
| 51 | + - name: Get plugin metadata |
| 52 | + id: metadata |
| 53 | + run: | |
| 54 | + sudo apt-get install jq |
| 55 | +
|
| 56 | + export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id) |
| 57 | + export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version) |
| 58 | + export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type) |
| 59 | + export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip |
| 60 | + export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5 |
| 61 | +
|
| 62 | + echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}" |
| 63 | + echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}" |
| 64 | + echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}" |
| 65 | + echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}" |
| 66 | + echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" |
| 67 | +
|
| 68 | + echo ::set-output name=github-tag::${GITHUB_REF#refs/*/} |
| 69 | +
|
| 70 | + - name: Read changelog |
| 71 | + id: changelog |
| 72 | + run: | |
| 73 | + awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md |
| 74 | + echo "::set-output name=path::release_notes.md" |
| 75 | +
|
| 76 | + - name: Check package version |
| 77 | + 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 |
| 78 | + |
| 79 | + - name: Package plugin |
| 80 | + id: package-plugin |
| 81 | + run: | |
| 82 | + mv dist "${{ steps.metadata.outputs.plugin-id }}" |
| 83 | + zip "${{ steps.metadata.outputs.archive }}" "${{ steps.metadata.outputs.plugin-id }}" -r |
| 84 | + md5sum "${{ steps.metadata.outputs.archive }}" > "${{ steps.metadata.outputs.archive-checksum }}" |
| 85 | + echo "::set-output name=checksum::$(cat \"./${{ steps.metadata.outputs.archive-checksum }}\" | cut -d' ' -f1)" |
| 86 | +
|
| 87 | + - name: Upload artifacts |
| 88 | + uses: actions/upload-artifact@v2 |
| 89 | + with: |
| 90 | + name: ${{ steps.metadata.outputs.archive }} |
| 91 | + path: ./${{ steps.metadata.outputs.archive }} |
| 92 | + |
| 93 | + - name: Create release |
| 94 | + id: create_release |
| 95 | + uses: actions/create-release@v1 |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + with: |
| 99 | + tag_name: ${{ github.ref }} |
| 100 | + release_name: Release ${{ github.ref }} |
| 101 | + body_path: ${{ steps.changelog.outputs.path }} |
| 102 | + |
| 103 | + - name: Add plugin to release |
| 104 | + id: upload-plugin-asset |
| 105 | + uses: actions/upload-release-asset@v1 |
| 106 | + env: |
| 107 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + with: |
| 109 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 110 | + asset_path: ./${{ steps.metadata.outputs.archive }} |
| 111 | + asset_name: ${{ steps.metadata.outputs.archive }} |
| 112 | + asset_content_type: application/zip |
| 113 | + |
| 114 | + - name: Add checksum to release |
| 115 | + id: upload-checksum-asset |
| 116 | + uses: actions/upload-release-asset@v1 |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + with: |
| 120 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 121 | + asset_path: ./${{ steps.metadata.outputs.archive-checksum }} |
| 122 | + asset_name: ${{ steps.metadata.outputs.archive-checksum }} |
| 123 | + asset_content_type: text/plain |
| 124 | + |
| 125 | + outputs: |
| 126 | + artifact_name: ${{ steps.metadata.outputs.archive }} |
| 127 | + |
| 128 | + internal-deploy: |
| 129 | + needs: release |
| 130 | + runs-on: ubuntu-latest |
| 131 | + steps: |
| 132 | + - name: Update Netdata Infra |
| 133 | + uses: benc-uk/workflow-dispatch@v1 |
| 134 | + with: |
| 135 | + token: ${{ secrets.NETDATABOT_GITHUB_TOKEN }} |
| 136 | + repo: ${{ secrets.NETDATA_INFRA_REPO }} |
| 137 | + workflow: Netdata Grafana Plugin Deploy |
| 138 | + ref: master |
| 139 | + inputs: '{"artifact_name": "${{ needs.release.outputs.artifact_name }}", "env": "production", "workflow_run_id": "${{ github.run_id }}"}' |
| 140 | + continue-on-error: true |
0 commit comments