Chore: Add GH workflow to release core plugins (#77204)

This commit is contained in:
Andres Martinez Gotor 2023-10-27 13:07:32 +02:00 committed by GitHub
parent 46f331e284
commit b537bb12f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 219 additions and 1 deletions

2
.github/CODEOWNERS vendored
View File

@ -655,7 +655,7 @@ embed.go @grafana/grafana-as-code
/.github/workflows/ephemeral-instances-pr-comment.yml @grafana/grafana-operator-experience-squad
/.github/workflows/ephemeral-instances-pr-opened-closed.yml @grafana/grafana-operator-experience-squad
/.github/workflows/create-security-patch-from-security-mirror.yml @grafana/grafana-delivery
/.github/workflows/core-plugins-build-and-release.yml @grafana/plugins-platform-frontend @grafana/plugins-platform-backend
# Generated files not requiring owner approval
/packages/grafana-data/src/types/featureToggles.gen.ts @grafanabot

View File

@ -0,0 +1,218 @@
on:
workflow_dispatch:
inputs:
plugin_id:
description: "ID of the plugin you want to publish"
required: true
type: choice
options:
- grafana-testdata-datasource
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-${{ inputs.plugin_id }}
cancel-in-progress: true
env:
GRABPL_VERSION: 3.0.44
GCP_BUCKET: integration-artifacts # Dev: plugins-community-staging
GCOM_API: https://grafana.com # Dev: https://grafana-dev.com
jobs:
build-and-publish:
name: Build and publish ${{ inputs.plugin_id }}
runs-on: ubuntu-latest
outputs:
type: ${{ steps.get_dir.outputs.dir }}
has_backend: ${{ steps.check_backend.outputs.has_backend }}
version: ${{ steps.build_frontend.outputs.version }}
steps:
- name: checkout
uses: actions/checkout@v3
- name: Verify inputs
run: |
if [ -z ${{ inputs.plugin_id }} ]; then echo "Missing plugin ID"; exit 1; fi
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.PLUGINS_GOOGLE_CREDENTIALS }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Setup nodejs environment
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: yarn
- name: Find plugin directory
shell: bash
id: get_dir
run: |
dir=$(find public/app/plugins -name ${{ inputs.plugin_id }} -print -quit)
echo "dir=${dir}" >> $GITHUB_OUTPUT
- name: Install frontend dependencies
shell: bash
working-directory: ${{ steps.get_dir.outputs.dir }}
run: |
yarn install --immutable
- name: Download grabpl executable
shell: sh
working-directory: ${{ steps.get_dir.outputs.dir }}
run: |
[ ! -d ./bin ] && mkdir -pv ./bin || true
curl -fL -o ./bin/grabpl https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v${{ env.GRABPL_VERSION }}/grabpl
chmod 0755 ./bin/grabpl
- name: Check backend
id: check_backend
shell: bash
run: |
if [ -d ./pkg/tsdb/${{ inputs.plugin_id }} ]; then
echo "has_backend=true" >> $GITHUB_OUTPUT
else
echo "has_backend=false" >> $GITHUB_OUTPUT
fi
- name: Setup golang environment
uses: actions/setup-go@v4
if: steps.check_backend.outputs.has_backend == 'true'
with:
go-version-file: go.mod
- name: Install Mage
shell: bash
if: steps.check_backend.outputs.has_backend == 'true'
run: |
go install github.com/magefile/mage
- name: Check tools
shell: bash
working-directory: ${{ steps.get_dir.outputs.dir }}
run: |
echo "======================================="
echo " Frontend tools"
echo "======================================="
echo "-------- node version -----"
node --version
echo "-------- npm version -----"
npm --version
echo "-------- yarn version -----"
yarn --version
echo "======================================="
echo " Misc tools"
echo "======================================="
echo "-------- docker version -----"
docker --version
echo "-------- jq version -----"
jq --version
echo "-------- grabpl version -----"
./bin/grabpl --version
echo "======================================="
- name: Check backend tools
shell: bash
if: steps.check_backend.outputs.has_backend == 'true'
working-directory: ${{ steps.get_dir.outputs.dir }}
run: |
echo "======================================="
echo " Backend tools"
echo "======================================="
echo "-------- go version -----"
go version
echo "-------- mage version -----"
mage --version
echo "======================================="
- name: build:frontend
shell: bash
id: build_frontend
run: |
command="plugin:build:commit"
if [ "$GITHUB_REF" != "refs/heads/main" ]; then
# Release branch, do not add commit hash to version
command="plugin:build"
fi
yarn $command --scope="@grafana-plugins/${{ inputs.plugin_id }}"
version=$(cat ${{ steps.get_dir.outputs.dir }}/dist/plugin.json | jq -r .info.version)
echo "version=${version}" >> $GITHUB_OUTPUT
- name: build:backend
if: steps.check_backend.outputs.has_backend == 'true'
shell: bash
env:
VERSION: ${{ steps.build_frontend.outputs.version }}
run: |
make build-plugin-go PLUGIN_ID=${{ inputs.plugin_id }}
- name: package
working-directory: ${{ steps.get_dir.outputs.dir }}
run: |
mkdir -p ci/jobs/package
bin/grabpl plugin package
env:
GRAFANA_API_KEY: ${{ secrets.PLUGINS_GRAFANA_API_KEY }}
PLUGIN_SIGNATURE_TYPE: grafana
- name: Check existing release
env:
GCOM_TOKEN: ${{ secrets.PLUGINS_GCOM_TOKEN }}
VERSION: ${{ steps.build_frontend.outputs.version }}
run: |
api_res=$(curl -X 'GET' -H "Authorization: Bearer $GCOM_TOKEN" \
'${{ env.GCOM_API}}/api/plugins/${{ inputs.plugin_id }}?version=$VERSION' \
-H 'accept: application/json')
api_res_code=$(echo $api_res | jq -r .code)
if [ "$api_res_code" = "NotFound" ]; then
echo "No existing release found"
else
echo "Expecting a missing release, got:"
echo $api_res
exit 1
fi
- name: store build artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: ${{ steps.get_dir.outputs.dir }}/ci/packages/*.zip
- name: Publish release to Google Cloud Storage
working-directory: ${{ steps.get_dir.outputs.dir }}
env:
VERSION: ${{ steps.build_frontend.outputs.version }}
run: |
echo "Publish release to Google Cloud Storage:"
touch ci/packages/windows ci/packages/darwin ci/packages/linux ci/packages/any
gsutil -m cp -r ci/packages/*windows* gs://${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/windows
gsutil -m cp -r ci/packages/*linux* gs://${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/linux
gsutil -m cp -r ci/packages/*darwin* gs://${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/darwin
gsutil -m cp -r ci/packages/*any* gs://${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/any
- name: Publish new plugin version on grafana.com
working-directory: ${{ steps.get_dir.outputs.dir }}
env:
GCOM_TOKEN: ${{ secrets.PLUGINS_GCOM_TOKEN }}
VERSION: ${{ steps.build_frontend.outputs.version }}
run: |
echo "Publish new plugin version on grafana.com:"
echo "Plugin version: ${VERSION}"
result=`curl -H "Authorization: Bearer $GCOM_TOKEN" -H "Content-Type: application/json" ${{ env.GCOM_API}}/api/plugins -d "{
\"url\": \"https://github.com/grafana/grafana/tree/main/${{ steps.get_dir.outputs.dir }}\",
\"download\": {
\"linux-amd64\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/linux/${{ inputs.plugin_id }}-${VERSION}.linux_amd64.zip\",
\"md5\": \"$(cat ci/packages/info-linux_amd64.json | jq -r .plugin.md5)\"
},
\"linux-arm64\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/linux/${{ inputs.plugin_id }}-${VERSION}.linux_arm64.zip\",
\"md5\": \"$(cat ci/packages/info-linux_arm64.json | jq -r .plugin.md5)\"
},
\"linux-arm\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/linux/${{ inputs.plugin_id }}-${VERSION}.linux_arm.zip\",
\"md5\": \"$(cat ci/packages/info-linux_arm.json | jq -r .plugin.md5)\"
},
\"windows-amd64\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/windows/${{ inputs.plugin_id }}-${VERSION}.windows_amd64.zip\",
\"md5\": \"$(cat ci/packages/info-windows_amd64.json | jq -r .plugin.md5)\"
},
\"darwin-amd64\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/darwin/${{ inputs.plugin_id }}-${VERSION}.darwin_amd64.zip\",
\"md5\": \"$(cat ci/packages/info-darwin_amd64.json | jq -r .plugin.md5)\"
},
\"darwin-arm64\": {
\"url\": \"https://storage.googleapis.com/${{ env.GCP_BUCKET }}/${{ inputs.plugin_id }}/release/${VERSION}/darwin/${{ inputs.plugin_id }}-${VERSION}.darwin_arm64.zip\",
\"md5\": \"$(cat ci/packages/info-darwin_arm64.json | jq -r .plugin.md5)\"
}
}
}"`
if [[ "$(echo $result | jq -r .version)" == "null" ]]; then
echo "Failed to publish plugin version. Got:"
echo $result
exit 1
fi