Skip to content

Commit 262af21

Browse files
authored
updatecli: pass the branch instead (#17291)
1 parent 9717008 commit 262af21

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

.ci/scripts/update-beats.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@
66
set -euo pipefail
77

88
make update-beats BEATS_VERSION="${1}"
9+
10+
#
11+
# updatecli with kind: shell requires the script to exit with 0
12+
# if there are no modifications to the repository.
13+
# Otherwise, it will print the diff.
14+
# This is to avoid the updatecli to fail when there are no modifications.
15+
# See https://www.updatecli.io/docs/plugins/resource/shell/#_shell_target
16+
#
17+
if git diff --quiet ; then
18+
# No modifications – exit successfully but keep stdout empty to that updatecli is happy
19+
exit 0
20+
else
21+
make update-beats-message
22+
git --no-pager diff
23+
fi

.ci/updatecli/update-beats.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ scms:
1313
token: '{{ requiredEnv "GITHUB_TOKEN" }}'
1414
branch: '{{ requiredEnv "BRANCH_NAME" }}'
1515
commitusingapi: true
16+
force: false
1617

1718
actions:
1819
default:
19-
title: '[updatecli] Update to elastic/beats@{{ source "beats" }}'
20+
title: '[updatecli][{{ requiredEnv "BRANCH_NAME" }}] Update to elastic/beats'
2021
kind: github/pullrequest
2122
scmid: default
2223
spec:
@@ -26,41 +27,16 @@ actions:
2627
- backport-skip
2728
description: |-
2829
### What
29-
`elastic/beats` automatic sync
30-
31-
*Changeset*
32-
* https://github.com/elastic/beats/commit/{{ source "beats" }}
33-
34-
sources:
35-
beats:
36-
kind: json
37-
spec:
38-
file: 'https://api.github.com/repos/elastic/beats/commits?sha={{ requiredEnv "BRANCH_NAME" }}&per_page=1'
39-
key: '.[0].sha'
40-
transformers:
41-
# substring 12 chars so it works for the condition
42-
- findsubmatch:
43-
pattern: ^(.{12}).*
44-
captureindex: 1
45-
46-
conditions:
47-
is-already-updated:
48-
name: Is version 'github.com/elastic/beats@{{ source "beats" }}' not updated in 'go.mod'?
49-
kind: shell
50-
disablesourceinput: true
51-
scmid: default
52-
spec:
53-
command: grep {{ source "beats" }} go.mod && exit 1 || exit 0
54-
failwhen: false
30+
`elastic/beats@{{ requiredEnv "BRANCH_NAME" }}` automatic sync
5531
5632
targets:
5733
beats:
58-
name: 'Update to elastic/beats@{{ source "beats" }}'
59-
sourceid: beats
34+
name: 'update-beats with {{ requiredEnv "BRANCH_NAME" }}'
6035
scmid: default
6136
kind: shell
37+
disablesourceinput: true
6238
spec:
63-
command: .ci/scripts/update-beats.sh
39+
command: .ci/scripts/update-beats.sh '{{ requiredEnv "BRANCH_NAME" }}'
6440
environments:
6541
- name: PATH
6642
- name: HOME

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,14 @@ BEATS_MODULE:=github.com/elastic/beats/v7
235235

236236
.PHONY: update-beats
237237
update-beats: update-beats-module tidy notice
238-
@echo --- Use this commit message: Update to elastic/beats@$(shell go list -m -f {{.Version}} $(BEATS_MODULE) | cut -d- -f3)
239238

240239
.PHONY: update-beats-module
241240
update-beats-module:
242241
go get $(BEATS_MODULE)@$(BEATS_VERSION) && go mod tidy
243242

243+
update-beats-message:
244+
@echo --- Use this commit message: Update to elastic/beats@$(shell go list -m -f {{.Version}} $(BEATS_MODULE) | cut -d- -f3)
245+
244246
##############################################################################
245247
# Linting, style-checking, license header checks, etc.
246248
##############################################################################

0 commit comments

Comments
 (0)