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
diff --git a/jobs/snap/snap-release.sh b/jobs/snap/snap-release.sh
index 7de1c81..06fc6c4 100644
--- a/jobs/snap/snap-release.sh
+++ b/jobs/snap/snap-release.sh
@@ -1,4 +1,4 @@
1#!/bin/sh1#!/bin/bash
2#2#
3# Copyright (C) 2017 Canonical Ltd3# Copyright (C) 2017 Canonical Ltd
4#4#
@@ -29,61 +29,142 @@ echo "New development version: $NEXT_VERSION"
2929
30REPOSITORY_URL="git+ssh://$BOT_USERNAME@git.launchpad.net/~$LAUNCHPAD_TEAM/$LAUNCHPAD_PROJECT/+git/$SNAP_NAME"30REPOSITORY_URL="git+ssh://$BOT_USERNAME@git.launchpad.net/~$LAUNCHPAD_TEAM/$LAUNCHPAD_PROJECT/+git/$SNAP_NAME"
3131
32if [ -e $SNAP_NAME ]; then32if [ -e "$SNAP_NAME" ]; then
33 rm -rf $SNAP_NAME33 rm -rf "$SNAP_NAME"
34fi34fi
3535
36set_git_identity() {36set_git_identity() {
37 git config user.name "System Enablement CI Bot"37 git config user.name "System Enablement CI Bot"
38 git config user.email "ce-system-enablement@lists.canonical.com"38 git config user.email "ce-system-enablement@lists.canonical.com"
39}39}
4040
41# Arguments are:
42# $1 Snap name
43# $2 Version to release
44update_changelog() {
45 local latest_version commits i text range
46 local snap=$1
47 local ver=$2
48 local changelog_file=ChangeLog
49 local changes author full_text
50
51 # latest tag is latest version
52 latest_version="$(git describe --abbrev=0)" || true
53 if [ -n "$latest_version" ]; then
54 range=$latest_version..HEAD
55 else
56 range=HEAD
57 fi
58
59 commits=$(git rev-list --merges --reverse "$range")
60 declare -A changes
61
62 for i in $commits; do
63 local body merge_proposal description text
64
65 body=$(git log --format=%B -n1 "$i")
66 merge_proposal=$(echo "$body" | grep "^Merge-Proposal:") || true
67 author=$(echo "$body" | grep "^Author:") || true
68 author="${author#Author: *}"
69 if [ -z "$author" ]; then
70 if [ -z "$merge_proposal" ]; then
71 author="unknown"
72 else
73 author=${merge_proposal#*~}
74 author=${author%%/*}
75 fi
76 fi
77 # 'sed' removes leading blank lines first, then adds indentation
78 description=$(echo "$body" | grep -v "^Author:\|^Merge" | \
79 sed '/./,$!d' | sed '2,$s/^/ /') || true
80 if [ -z "$description" ]; then
81 description="See more information in merge proposal"
82 fi
83 text=${changes[$author]}
84 printf -v text "%s\n * %s\n %s" \
85 "$text" "$description" "$merge_proposal"
86 changes[$author]=$text
87 done
88
89 printf -v full_text "%s\n" "$(date --rfc-3339=date --utc) $snap $ver"
90 for author in "${!changes[@]}"; do
91 printf -v full_text "%s\n [ %s ]%s\n" \
92 "$full_text" "$author" "${changes[$author]}"
93 done
94
95 if [ ! -e "$changelog_file" ]; then
96 touch "$changelog_file"
97 fi
98 echo "$full_text" | cat - "$changelog_file" > "$changelog_file".tmp
99 mv "$changelog_file".tmp "$changelog_file"
100
101 git add "$changelog_file"
102 git commit -m "Update $changelog_file for $ver"
103}
104
105# Arguments are:
106# $1 Version to be set in the snapcraft.yaml file
107# $2 Path to the snapcraft.yaml file
41bump_version_and_tag() {108bump_version_and_tag() {
42 sed -i -e "s/^version:\ .*/version: $1/g" snapcraft.yaml109 sed -i -e "s/^version:\ .*/version: $1/g" "$2"
43 git add snapcraft.yaml110 git add "$2"
44 git commit -m "Bump version to $1"111 git commit -m "Bump version to $1"
45 git tag -a -m "$1" $1 HEAD112 git tag -a -m "$1" "$1" HEAD
46}113}
47114
48RELEASE_BASE_BRANCH=master115RELEASE_BASE_BRANCH=master
49if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then116if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then
50 RELEASE_BASE_BRANCH=stable117 RELEASE_BASE_BRANCH=stable
51fi118fi
52119
53git clone -b $RELEASE_BASE_BRANCH $REPOSITORY_URL $SNAP_NAME120git clone -b "$RELEASE_BASE_BRANCH" "$REPOSITORY_URL" "$SNAP_NAME"
54cd $SNAP_NAME121cd "$SNAP_NAME"
55122
56if [ ! -e snapcraft.yaml ]; then123SNAPCRAFT_YAML_PATH=
57 echo "ERROR: No top-level snapcraft.yaml file!"124if [ -e snapcraft.yaml ]; then
58 exit 1125 SNAPCRAFT_YAML_PATH=snapcraft.yaml
126elif [ -e snap/snapcraft.yaml ]; then
127 SNAPCRAFT_YAML_PATH=snap/snapcraft.yaml
128fi
129
130if [ -z "$SNAPCRAFT_YAML_PATH" ]; then
131 echo "ERROR: No snapcraft.yaml or snap/snapcraft.yaml file!"
132 exit 1
59fi133fi
60134
61set_git_identity135set_git_identity
62bump_version_and_tag $VERSION136update_changelog "$SNAP_NAME" "$VERSION"
137bump_version_and_tag "$VERSION" "$SNAPCRAFT_YAML_PATH"
63138
64if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then139if [ "$RELEASE_FROM_STABLE" -eq 1 ]; then
65 git push origin $RELEASE_BASE_BRANCH140 git push origin "$RELEASE_BASE_BRANCH"
66 git push origin $VERSION141 git push origin "$VERSION"
67142
68 $BUILD_SCRIPTS/tools/trigger-lp-build.py -s $SNAP_NAME -p143 "$BUILD_SCRIPTS"/tools/trigger-lp-build.py -s "$SNAP_NAME" -p
69else144else
70 if ! git branch -r | grep origin/stable ; then145 if ! git branch -r | grep origin/stable ; then
71 git checkout -b stable origin/master146 git checkout -b stable origin/master
72 else147 else
73 git checkout -b stable origin/stable148 git checkout -b stable origin/stable
74 fi149 fi
75 git merge $RELEASE_BASE_BRANCH150
76151 # We're using `-X theirs` here as master always takes priority over
77 git push origin stable152 # what is in the stable. If something was only submitted into stable
78 git push origin $RELEASE_BASE_BRANCH153 # the commiter needs to take care that the same change is submitted
79 git push origin $VERSION154 # to master too or it is overriden the next time a release happens
80155 # from master.
81 # Build before we change master branch156 git merge --no-ff -X theirs "$RELEASE_BASE_BRANCH"
82 $BUILD_SCRIPTS/tools/trigger-lp-build.py -s $SNAP_NAME -p157
83158 git push origin stable
84 git checkout $RELEASE_BASE_BRANCH159 git push origin "$RELEASE_BASE_BRANCH"
85 sed -i -e "s/^version:\ .*/version: ${NEXT_VERSION}-dev/g" snapcraft.yaml160 git push origin "$VERSION"
86 git add snapcraft.yaml161
87 git commit -m "Open development for ${NEXT_VERSION}-dev"162 # Build before we change master branch
88 git push origin $RELEASE_BASE_BRANCH163 "$BUILD_SCRIPTS"/tools/trigger-lp-build.py -s "$SNAP_NAME" -p
164
165 git checkout "$RELEASE_BASE_BRANCH"
166 sed -i -e "s/^version:\ .*/version: ${NEXT_VERSION}-dev/g" "$SNAPCRAFT_YAML_PATH"
167 git add "$SNAPCRAFT_YAML_PATH"
168 git commit -m "Open development for ${NEXT_VERSION}-dev"
169 git push origin "$RELEASE_BASE_BRANCH"
89fi170fi
diff --git a/tools/automerge-mps.py b/tools/automerge-mps.py
index a4e17d2..4f610a2 100755
--- a/tools/automerge-mps.py
+++ b/tools/automerge-mps.py
@@ -85,9 +85,13 @@ def try_merge(proposal, target_repo, target_branch, source_repo, source_branch):
85 # FIXME: What is the real email address of the bot?85 # FIXME: What is the real email address of the bot?
86 repo.git.config("user.email", "ce-system-enablement@lists.canonical.com")86 repo.git.config("user.email", "ce-system-enablement@lists.canonical.com")
8787
88 registrant_name = proposal.registrant.display_name
89 registrant_mail = proposal.registrant.preferred_email_address.email
88 repo.git.merge("--no-ff",90 repo.git.merge("--no-ff",
89 "-m", "Merge remote tracking branch %s" % (source_branch),91 "-m", "Merge remote tracking branch %s" % (source_branch),
90 "-m", "Merge-Proposal: %s" % proposal.web_link,92 "-m", "Merge-Proposal: %s" % proposal.web_link,
93 "-m", "Author: %s <%s>" % (registrant_name, registrant_mail),
94 "-m", "%s" % proposal.description,
91 "source/%s" % source_branch)95 "source/%s" % source_branch)
9296
93 repo.git.push("origin", target_branch)97 repo.git.push("origin", target_branch)
@@ -135,8 +139,8 @@ for proposal in proposals:
135 clean_branch_name(proposal.target_git_path),139 clean_branch_name(proposal.target_git_path),
136 launchpad.load(proposal.source_git_repository_link),140 launchpad.load(proposal.source_git_repository_link),
137 clean_branch_name(proposal.source_git_path))141 clean_branch_name(proposal.source_git_path))
138 except:142 except Exception as e:
139 print("ERROR: Failed to merge %s" % proposal.web_link)143 print("ERROR: Failed to merge %s (%s)" % (proposal.web_link, e))
140 failed_merges += 1144 failed_merges += 1
141145
142if failed_merges > 0:146if failed_merges > 0:

Subscribers

People subscribed via source and target branches