CI: Notify channel on drone yaml changes (#42428)

* Notify on drone yaml changes

* Change secrets

* Remove test notification

* Fix typo
pull/42476/head^2
Dimitris Sotirakis 4 years ago committed by GitHub
parent 95831e9be0
commit 54ea2ed766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      .drone.yml
  2. 24
      scripts/drone/pipelines/main.star
  3. 4
      scripts/drone/pipelines/pr.star
  4. 10
      scripts/drone/pipelines/release.star
  5. 6
      scripts/drone/steps/lib.star
  6. 9
      scripts/drone/utils/utils.star

@ -832,6 +832,34 @@ volumes:
- name: cypress_cache - name: cypress_cache
temp: {} temp: {}
--- ---
depends_on: []
kind: pipeline
name: notify-drone-changes
platform:
arch: amd64
os: linux
steps:
- image: plugins/slack
name: slack
settings:
channel: slack-webhooks-test
template: "`.drone.yml` and `starlark` files have been changed on the OSS repo,
by: {{build.author}}. \nBranch: <https://github.com/{{ repo.owner }}/{{ repo.name
}}/commits/{{ build.branch }}|{{ build.branch }}>\nCommit hash: <https://github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}|{{
truncate build.commit 8 }}>"
webhook:
from_secret: drone-changes-webhook
trigger:
branch: main
event:
- push
paths:
exclude:
- exclude
include:
- .drone.yml
type: docker
---
depends_on: depends_on:
- build-main - build-main
- windows-main - windows-main
@ -4158,6 +4186,6 @@ kind: secret
name: drone_token name: drone_token
--- ---
kind: signature kind: signature
hmac: e905a82f06335fcdb8d1ea1d5c0b1d966cd66e37a49ae771d4d2ffcd1f3d8997 hmac: 003d0d4a8b4e2fc81f575c838b064e5778c2562b445b26c5a76339ca95c95330
... ...

@ -49,6 +49,8 @@ load(
'scripts/drone/utils/utils.star', 'scripts/drone/utils/utils.star',
'pipeline', 'pipeline',
'notify_pipeline', 'notify_pipeline',
'failure_template',
'drone_change_template',
) )
ver_mode = 'main' ver_mode = 'main'
@ -142,6 +144,18 @@ def main_pipelines(edition):
'event': ['push',], 'event': ['push',],
'branch': 'main', 'branch': 'main',
} }
drone_change_trigger = {
'event': ['push',],
'branch': 'main',
'paths': {
'include': [
'.drone.yml',
],
'exclude': [
'exclude',
],
},
}
steps, windows_steps, publish_steps = get_steps(edition=edition) steps, windows_steps, publish_steps = get_steps(edition=edition)
if edition == 'enterprise': if edition == 'enterprise':
@ -157,6 +171,8 @@ def main_pipelines(edition):
name='windows-main', edition=edition, trigger=trigger, name='windows-main', edition=edition, trigger=trigger,
steps=initialize_step(edition, platform='windows', ver_mode=ver_mode) + windows_steps, steps=initialize_step(edition, platform='windows', ver_mode=ver_mode) + windows_steps,
depends_on=['build-main'], platform='windows', depends_on=['build-main'], platform='windows',
), notify_pipeline(
name='notify-drone-changes', slack_channel='slack-webhooks-test', trigger=drone_change_trigger, template=drone_change_template, secret='drone-changes-webhook',
), ),
] ]
if edition != 'enterprise': if edition != 'enterprise':
@ -167,8 +183,8 @@ def main_pipelines(edition):
)) ))
pipelines.append(notify_pipeline( pipelines.append(notify_pipeline(
name='notify-main', slack_channel='grafana-ci-notifications', trigger=trigger, name='notify-main', slack_channel='grafana-ci-notifications', trigger=dict(trigger, status = ['failure']),
depends_on=['build-main', 'windows-main', 'publish-main'], depends_on=['build-main', 'windows-main', 'publish-main'], template=failure_template, secret='slack_webhook'
)) ))
else: else:
# Add downstream enterprise pipelines triggerable from OSS builds # Add downstream enterprise pipelines triggerable from OSS builds
@ -192,8 +208,8 @@ def main_pipelines(edition):
)) ))
pipelines.append(notify_pipeline( pipelines.append(notify_pipeline(
name='notify-main-downstream', slack_channel='grafana-enterprise-ci-notifications', trigger=trigger, name='notify-main-downstream', slack_channel='grafana-enterprise-ci-notifications', trigger=dict(trigger, status = ['failure']),
depends_on=['build-main-downstream', 'windows-main-downstream', 'publish-main-downstream'], depends_on=['build-main-downstream', 'windows-main-downstream', 'publish-main-downstream'], template=failure_template, secret='slack_webhook',
)) ))
return pipelines return pipelines

@ -40,7 +40,10 @@ load(
load( load(
'scripts/drone/utils/utils.star', 'scripts/drone/utils/utils.star',
'notify_pipeline',
'pipeline', 'pipeline',
'failure_template',
'drone_change_template',
) )
ver_mode = 'pr' ver_mode = 'pr'
@ -109,7 +112,6 @@ def pr_pipelines(edition):
build_steps.extend([ build_steps.extend([
package_step(edition=edition2, ver_mode=ver_mode, include_enterprise2=include_enterprise2, variants=['linux-x64']), package_step(edition=edition2, ver_mode=ver_mode, include_enterprise2=include_enterprise2, variants=['linux-x64']),
e2e_tests_server_step(edition=edition2, port=3002), e2e_tests_server_step(edition=edition2, port=3002),
e2e_tests_step(edition=edition2, port=3002),
e2e_tests_step('dashboards-suite', edition=edition2, port=3002), e2e_tests_step('dashboards-suite', edition=edition2, port=3002),
e2e_tests_step('smoke-tests-suite', edition=edition2, port=3002), e2e_tests_step('smoke-tests-suite', edition=edition2, port=3002),
e2e_tests_step('panels-suite', edition=edition2, port=3002), e2e_tests_step('panels-suite', edition=edition2, port=3002),

@ -48,6 +48,8 @@ load(
'scripts/drone/utils/utils.star', 'scripts/drone/utils/utils.star',
'pipeline', 'pipeline',
'notify_pipeline', 'notify_pipeline',
'failure_template',
'drone_change_template',
) )
def release_npm_packages_step(edition, ver_mode): def release_npm_packages_step(edition, ver_mode):
@ -227,8 +229,8 @@ def release_pipelines(ver_mode='release', trigger=None):
pipelines.append(publish_pipeline) pipelines.append(publish_pipeline)
pipelines.append(notify_pipeline( pipelines.append(notify_pipeline(
name='notify-{}'.format(ver_mode), slack_channel='grafana-ci-notifications', trigger=trigger, name='notify-{}'.format(ver_mode), slack_channel='grafana-ci-notifications', trigger=dict(trigger, status = ['failure']),
depends_on=[p['name'] for p in pipelines], depends_on=[p['name'] for p in pipelines], template=failure_template, secret='slack_webhook',
)) ))
return pipelines return pipelines
@ -260,8 +262,8 @@ def test_release_pipelines():
pipelines = oss_pipelines + enterprise_pipelines + [publish_pipeline,] pipelines = oss_pipelines + enterprise_pipelines + [publish_pipeline,]
pipelines.append(notify_pipeline( pipelines.append(notify_pipeline(
name='notify-{}'.format(ver_mode), slack_channel='grafana-ci-notifications', trigger=trigger, name='notify-{}'.format(ver_mode), slack_channel='grafana-ci-notifications', trigger=dict(trigger, status = ['failure']),
depends_on=[p['name'] for p in pipelines], depends_on=[p['name'] for p in pipelines], template=failure_template, secret='slack_webhook',
)) ))
return pipelines return pipelines

@ -12,14 +12,14 @@ wix_image = 'grafana/ci-wix:0.1.1'
test_release_ver = 'v7.3.0-test' test_release_ver = 'v7.3.0-test'
def slack_step(channel): def slack_step(channel, template, secret):
return { return {
'name': 'slack', 'name': 'slack',
'image': 'plugins/slack', 'image': 'plugins/slack',
'settings': { 'settings': {
'webhook': from_secret('slack_webhook'), 'webhook': from_secret(secret),
'channel': channel, 'channel': channel,
'template': 'Build {{build.number}} failed for commit: <https://github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}|{{ truncate build.commit 8 }}>: {{build.link}}\nBranch: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>\nAuthor: {{build.author}}', 'template': template,
}, },
} }

@ -6,6 +6,9 @@ load(
load('scripts/drone/vault.star', 'from_secret', 'github_token', 'pull_secret', 'drone_token') load('scripts/drone/vault.star', 'from_secret', 'github_token', 'pull_secret', 'drone_token')
failure_template = 'Build {{build.number}} failed for commit: <https://github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}|{{ truncate build.commit 8 }}>: {{build.link}}\nBranch: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>\nAuthor: {{build.author}}'
drone_change_template = '`.drone.yml` and `starlark` files have been changed on the OSS repo, by: {{build.author}}. \nBranch: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}>\nCommit hash: <https://github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}|{{ truncate build.commit 8 }}>'
def pipeline( def pipeline(
name, edition, trigger, steps, services=[], platform='linux', depends_on=[], name, edition, trigger, steps, services=[], platform='linux', depends_on=[],
): ):
@ -54,8 +57,8 @@ def pipeline(
return pipeline return pipeline
def notify_pipeline(name, slack_channel, trigger, depends_on=[]): def notify_pipeline(name, slack_channel, trigger, depends_on=[], template=None, secret=None):
trigger = dict(trigger, status = ['failure']) trigger = dict(trigger)
return { return {
'kind': 'pipeline', 'kind': 'pipeline',
'type': 'docker', 'type': 'docker',
@ -66,7 +69,7 @@ def notify_pipeline(name, slack_channel, trigger, depends_on=[]):
'name': name, 'name': name,
'trigger': trigger, 'trigger': trigger,
'steps': [ 'steps': [
slack_step(slack_channel), slack_step(slack_channel, template, secret),
], ],
'depends_on': depends_on, 'depends_on': depends_on,
} }

Loading…
Cancel
Save