-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate-manifest
executable file
·108 lines (86 loc) · 4.28 KB
/
create-manifest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")"
if [ "$VERSION" = "" ] || [ "$SDK_VERSION" = "" ] || [ "$CHANNEL" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0:"
echo "This script will create a branch in the manifest repository checked out in $SCRIPTFOLDER/../manifest and push the branch and tag."
echo "The repository is cloned from github.com/kinvolk/manifest.git if it does not exist (origin in an existing repository must point there"
echo "or pushing fails or does some unwanted action)."
echo "Set VERSION, SDK_VERSION, and CHANNEL as environment variables, e.g., VERSION=2345.3.0 SDK_VERSION=2345.2.0 CHANNEL=stable $0"
echo
echo "It creates tags only for the manifest repository. Tags for the repositories scripts, coreos-overlay, and portage-stable should be"
echo "created first with ./tag-release (which can be rerun on build failures to introduce fixes without changing the manifest)."
echo "By default the manifest references refs/tags/CHANNEL-VERSION for the repositories scripts, coreos-overlay, and portage-stable"
echo "and simply refs/heads/master for the others because their revisions are defined by the CROS_WORKON_COMMIT in the respective ebuild files."
echo "Set the environment variables SCRIPTS_REF, OVERLAY_REF, PORTAGE_REF, or DEFAULT_REF to specify any other reference."
exit 1
fi
set -euo pipefail
SCRIPTS_REF="${SCRIPTS_REF-refs/tags/$CHANNEL-$VERSION}"
OVERLAY_REF="${OVERLAY_REF-refs/tags/$CHANNEL-$VERSION}"
PORTAGE_REF="${PORTAGE_REF-refs/tags/$CHANNEL-$VERSION}"
DEFAULT_REF="${DEFAULT_REF-refs/heads/master}"
echo "Running with CHANNEL=$CHANNEL VERSION=$VERSION SDK_VERSION=$SDK_VERSION"
echo "SCRIPTS_REF=$SCRIPTS_REF OVERLAY_REF=$OVERLAY_REF PORTAGE_REF=$PORTAGE_REF"
echo "DEFAULT_REF=$DEFAULT_REF"
cd "$SCRIPTFOLDER/.."
MANIFESTFOLDER="manifest"
if [ -d "${MANIFESTFOLDER}" ]; then
git -C "${MANIFESTFOLDER}" fetch --prune origin
else
git clone [email protected]:kinvolk/manifest.git "${MANIFESTFOLDER}"
fi
cd "${MANIFESTFOLDER}"
if [ "$(git status --porcelain || echo failed)" != "" ]; then
echo "Error: Unexpected output of git status:"
git status
exit 1
fi
BRANCHNAME="flatcar-$CHANNEL-$VERSION"
EXISTS=0
echo "Preparing branch"
git checkout flatcar-master
git pull
git branch "$BRANCHNAME" || EXISTS=1
git checkout "$BRANCHNAME"
if [ "$EXISTS" = 1 ]; then
echo "Warning: Reusing existing branch $BRANCHNAME, will try to pull."
git pull || echo "Warning: Pulling failed. Ignore the above output if the branch just exists locally."
fi
echo "Preparing files"
sed -E -i "s/(FLATCAR_VERSION=)(.*)/\1$VERSION/" version.txt
sed -E -i "s/(FLATCAR_VERSION_ID=)(.*)/\1$VERSION/" version.txt
sed -E -i "s/(FLATCAR_SDK_VERSION=)(.*)/\1$SDK_VERSION/" version.txt
echo "Removing old build-*.xml files"
git rm ./build-*.xml || echo "Warning: Could not delete old files"
FILENAME="build-$(echo "$VERSION" | cut -d '.' -f 1).xml"
export SCRIPTS_REF OVERLAY_REF PORTAGE_REF DEFAULT_REF
cat "$SCRIPTFOLDER/manifest-template.xml.envsubst" | envsubst '$SCRIPTS_REF $OVERLAY_REF $PORTAGE_REF $DEFAULT_REF' > "$FILENAME"
# Note: appc-acbuild, appc-spec, rkt, and systemd always stay at refs/heads/master because they do not have flatcar-master or build branches
ln -fs "$FILENAME" default.xml
cp "$FILENAME" release.xml
MAJOR="${VERSION%%.*}"
MAINT="flatcar"
if [ "$CHANNEL" = lts ] && [ "$MAJOR" = "2605" ]; then
MAINT="flatcar-lts"
fi
echo "Creating maintenance.xml for $MAINT-$MAJOR branches"
SCRIPTS_REF="refs/heads/$MAINT-$MAJOR"
OVERLAY_REF="refs/heads/$MAINT-$MAJOR"
PORTAGE_REF="refs/heads/$MAINT-$MAJOR"
export SCRIPTS_REF OVERLAY_REF PORTAGE_REF DEFAULT_REF
cat "$SCRIPTFOLDER/manifest-template.xml.envsubst" | envsubst '$SCRIPTS_REF $OVERLAY_REF $PORTAGE_REF $DEFAULT_REF' > maintenance.xml
echo "Adding changed files"
git add "$FILENAME" release.xml default.xml version.txt maintenance.xml
echo "Committing manifest"
git commit -m "build $VERSION" --author 'Flatcar Buildbot <[email protected]>'
echo "Pushing branch"
git push --force-with-lease --set-upstream origin "$BRANCHNAME"
TAG="v$VERSION"
echo "Deleting tag $TAG if it exists"
git tag -d "$TAG" || echo "No local tags deleted"
git push --delete origin "$TAG" || echo "No remote tags deleted"
echo "Tagging commit"
git tag -s "$TAG" -m "$TAG"
echo "Pushing tag"
git push origin "$TAG"
echo "Done"