Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/jenkins-jobs:create-changelog into ~snappy-hwe-team/snappy-hwe-snaps/+git/jenkins-jobs:master

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Simon Fels
Approved revision: 41f42b3cb698bf5b7cc43330016aad91d93713f7
Merged at revision: ea76528042e35c73462d73273b2f11f4c6c9d531
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/jenkins-jobs:create-changelog
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/jenkins-jobs:master
Diff against target: 219 lines (+125/-40)
2 files modified
jobs/snap/snap-release.sh (+119/-38)
tools/automerge-mps.py (+6/-2)
Reviewer Review Type Date Requested Status
Simon Fels Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+326055@code.launchpad.net

Description of the change

Update ChangeLog on snap release. The format of the ChangeLog file would be as follows:

[year-moth-date] [snap name] [released version]

  [ Author <author e-mail> ]
  * Description of change 1
    Merge-Proposal: [link to lp merge proposal]
  * Description of change 2
    Merge-Proposal: [link to lp merge proposal]

  [ Author <author e-mail> ]
  * Description of change 1
    Merge-Proposal: [link to lp merge proposal]

[repetition of the previous pattern from old releases]

To post a comment you must log in.
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

See also related MP to build-scripts: https://code.launchpad.net/~alfonsosanchezbeato/snappy-hwe-snaps/+git/build-scripts/+merge/325938

For jenkins jobs, snap-release.sh is fully copied into jenkins and not sourced, so the shebang will be respected and we will run bash as shell.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Simon Fels (morphis) wrote :

Did you give this a try on a local jenkins instance or how did you test this?

review: Needs Information
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :
Revision history for this message
Simon Fels (morphis) wrote :

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jobs/snap/snap-release.sh b/jobs/snap/snap-release.sh
2index 7de1c81..06fc6c4 100644
3--- a/jobs/snap/snap-release.sh
4+++ b/jobs/snap/snap-release.sh
5@@ -1,4 +1,4 @@
6-#!/bin/sh
7+#!/bin/bash
8 #
9 # Copyright (C) 2017 Canonical Ltd
10 #
11@@ -29,61 +29,142 @@ echo "New development version: $NEXT_VERSION"
12
13 REPOSITORY_URL="git+ssh://$BOT_USERNAME@git.launchpad.net/~$LAUNCHPAD_TEAM/$LAUNCHPAD_PROJECT/+git/$SNAP_NAME"
14
15-if [ -e $SNAP_NAME ]; then
16- rm -rf $SNAP_NAME
17+if [ -e "$SNAP_NAME" ]; then
18+ rm -rf "$SNAP_NAME"
19 fi
20
21 set_git_identity() {
22- git config user.name "System Enablement CI Bot"
23- git config user.email "ce-system-enablement@lists.canonical.com"
24+ git config user.name "System Enablement CI Bot"
25+ git config user.email "ce-system-enablement@lists.canonical.com"
26 }
27
28+# Arguments are:
29+# $1 Snap name
30+# $2 Version to release
31+update_changelog() {
32+ local latest_version commits i text range
33+ local snap=$1
34+ local ver=$2
35+ local changelog_file=ChangeLog
36+ local changes author full_text
37+
38+ # latest tag is latest version
39+ latest_version="$(git describe --abbrev=0)" || true
40+ if [ -n "$latest_version" ]; then
41+ range=$latest_version..HEAD
42+ else
43+ range=HEAD
44+ fi
45+
46+ commits=$(git rev-list --merges --reverse "$range")
47+ declare -A changes
48+
49+ for i in $commits; do
50+ local body merge_proposal description text
51+
52+ body=$(git log --format=%B -n1 "$i")
53+ merge_proposal=$(echo "$body" | grep "^Merge-Proposal:") || true
54+ author=$(echo "$body" | grep "^Author:") || true
55+ author="${author#Author: *}"
56+ if [ -z "$author" ]; then
57+ if [ -z "$merge_proposal" ]; then
58+ author="unknown"
59+ else
60+ author=${merge_proposal#*~}
61+ author=${author%%/*}
62+ fi
63+ fi
64+ # 'sed' removes leading blank lines first, then adds indentation
65+ description=$(echo "$body" | grep -v "^Author:\|^Merge" | \
66+ sed '/./,$!d' | sed '2,$s/^/ /') || true
67+ if [ -z "$description" ]; then
68+ description="See more information in merge proposal"
69+ fi
70+ text=${changes[$author]}
71+ printf -v text "%s\n * %s\n %s" \
72+ "$text" "$description" "$merge_proposal"
73+ changes[$author]=$text
74+ done
75+
76+ printf -v full_text "%s\n" "$(date --rfc-3339=date --utc) $snap $ver"
77+ for author in "${!changes[@]}"; do
78+ printf -v full_text "%s\n [ %s ]%s\n" \
79+ "$full_text" "$author" "${changes[$author]}"
80+ done
81+
82+ if [ ! -e "$changelog_file" ]; then
83+ touch "$changelog_file"
84+ fi
85+ echo "$full_text" | cat - "$changelog_file" > "$changelog_file".tmp
86+ mv "$changelog_file".tmp "$changelog_file"
87+
88+ git add "$changelog_file"
89+ git commit -m "Update $changelog_file for $ver"
90+}
91+
92+# Arguments are:
93+# $1 Version to be set in the snapcraft.yaml file
94+# $2 Path to the snapcraft.yaml file
95 bump_version_and_tag() {
96- sed -i -e "s/^version:\ .*/version: $1/g" snapcraft.yaml
97- git add snapcraft.yaml
98- git commit -m "Bump version to $1"
99- git tag -a -m "$1" $1 HEAD
100+ sed -i -e "s/^version:\ .*/version: $1/g" "$2"
101+ git add "$2"
102+ git commit -m "Bump version to $1"
103+ git tag -a -m "$1" "$1" HEAD
104 }
105
106 RELEASE_BASE_BRANCH=master
107 if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then
108- RELEASE_BASE_BRANCH=stable
109+ RELEASE_BASE_BRANCH=stable
110 fi
111
112-git clone -b $RELEASE_BASE_BRANCH $REPOSITORY_URL $SNAP_NAME
113-cd $SNAP_NAME
114+git clone -b "$RELEASE_BASE_BRANCH" "$REPOSITORY_URL" "$SNAP_NAME"
115+cd "$SNAP_NAME"
116
117-if [ ! -e snapcraft.yaml ]; then
118- echo "ERROR: No top-level snapcraft.yaml file!"
119- exit 1
120+SNAPCRAFT_YAML_PATH=
121+if [ -e snapcraft.yaml ]; then
122+ SNAPCRAFT_YAML_PATH=snapcraft.yaml
123+elif [ -e snap/snapcraft.yaml ]; then
124+ SNAPCRAFT_YAML_PATH=snap/snapcraft.yaml
125+fi
126+
127+if [ -z "$SNAPCRAFT_YAML_PATH" ]; then
128+ echo "ERROR: No snapcraft.yaml or snap/snapcraft.yaml file!"
129+ exit 1
130 fi
131
132 set_git_identity
133-bump_version_and_tag $VERSION
134+update_changelog "$SNAP_NAME" "$VERSION"
135+bump_version_and_tag "$VERSION" "$SNAPCRAFT_YAML_PATH"
136
137 if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then
138- git push origin $RELEASE_BASE_BRANCH
139- git push origin $VERSION
140+ git push origin "$RELEASE_BASE_BRANCH"
141+ git push origin "$VERSION"
142
143- $BUILD_SCRIPTS/tools/trigger-lp-build.py -s $SNAP_NAME -p
144+ "$BUILD_SCRIPTS"/tools/trigger-lp-build.py -s "$SNAP_NAME" -p
145 else
146- if ! git branch -r | grep origin/stable ; then
147- git checkout -b stable origin/master
148- else
149- git checkout -b stable origin/stable
150- fi
151- git merge $RELEASE_BASE_BRANCH
152-
153- git push origin stable
154- git push origin $RELEASE_BASE_BRANCH
155- git push origin $VERSION
156-
157- # Build before we change master branch
158- $BUILD_SCRIPTS/tools/trigger-lp-build.py -s $SNAP_NAME -p
159-
160- git checkout $RELEASE_BASE_BRANCH
161- sed -i -e "s/^version:\ .*/version: ${NEXT_VERSION}-dev/g" snapcraft.yaml
162- git add snapcraft.yaml
163- git commit -m "Open development for ${NEXT_VERSION}-dev"
164- git push origin $RELEASE_BASE_BRANCH
165+ if ! git branch -r | grep origin/stable ; then
166+ git checkout -b stable origin/master
167+ else
168+ git checkout -b stable origin/stable
169+ fi
170+
171+ # We're using `-X theirs` here as master always takes priority over
172+ # what is in the stable. If something was only submitted into stable
173+ # the commiter needs to take care that the same change is submitted
174+ # to master too or it is overriden the next time a release happens
175+ # from master.
176+ git merge --no-ff -X theirs "$RELEASE_BASE_BRANCH"
177+
178+ git push origin stable
179+ git push origin "$RELEASE_BASE_BRANCH"
180+ git push origin "$VERSION"
181+
182+ # Build before we change master branch
183+ "$BUILD_SCRIPTS"/tools/trigger-lp-build.py -s "$SNAP_NAME" -p
184+
185+ git checkout "$RELEASE_BASE_BRANCH"
186+ sed -i -e "s/^version:\ .*/version: ${NEXT_VERSION}-dev/g" "$SNAPCRAFT_YAML_PATH"
187+ git add "$SNAPCRAFT_YAML_PATH"
188+ git commit -m "Open development for ${NEXT_VERSION}-dev"
189+ git push origin "$RELEASE_BASE_BRANCH"
190 fi
191diff --git a/tools/automerge-mps.py b/tools/automerge-mps.py
192index a4e17d2..4f610a2 100755
193--- a/tools/automerge-mps.py
194+++ b/tools/automerge-mps.py
195@@ -85,9 +85,13 @@ def try_merge(proposal, target_repo, target_branch, source_repo, source_branch):
196 # FIXME: What is the real email address of the bot?
197 repo.git.config("user.email", "ce-system-enablement@lists.canonical.com")
198
199+ registrant_name = proposal.registrant.display_name
200+ registrant_mail = proposal.registrant.preferred_email_address.email
201 repo.git.merge("--no-ff",
202 "-m", "Merge remote tracking branch %s" % (source_branch),
203 "-m", "Merge-Proposal: %s" % proposal.web_link,
204+ "-m", "Author: %s <%s>" % (registrant_name, registrant_mail),
205+ "-m", "%s" % proposal.description,
206 "source/%s" % source_branch)
207
208 repo.git.push("origin", target_branch)
209@@ -135,8 +139,8 @@ for proposal in proposals:
210 clean_branch_name(proposal.target_git_path),
211 launchpad.load(proposal.source_git_repository_link),
212 clean_branch_name(proposal.source_git_path))
213- except:
214- print("ERROR: Failed to merge %s" % proposal.web_link)
215+ except Exception as e:
216+ print("ERROR: Failed to merge %s (%s)" % (proposal.web_link, e))
217 failed_merges += 1
218
219 if failed_merges > 0:

Subscribers

People subscribed via source and target branches