Skip to content

Commit 3a0a24e

Browse files
authored
release-to-wolfi - support updating pipelines only (enterprise, extras) (chainguard-dev#202)
With this you can sync to other dirs also. $ ./tools/release-to-wolfi vX.Y.Z \ ~/src/wolfi-os/ ~/src/enterprise-packages ~/src/extra-packages The big TODO here would be to have github client push and do the PR also.
1 parent 9304a44 commit 3a0a24e

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ To release a version of tw to wolfi, run tools/release-to-wolfi.
77

88
$ git tag vX.Y.Z
99
$ git push origin vX.Y.Z
10-
$ ./tools/release-to-wolfi vX.Y.Z ~/src/wolfi-os/
10+
$ ./tools/release-to-wolfi vX.Y.Z \
11+
~/src/wolfi-os/ ~/src/enterprise-packages ~/src/extra-packages
1112

1213
This takes care of updating the `tw.yaml` file from `melange.yaml`
13-
here, and copying pipeline updates over.
14+
for wolfi, and syncs the pipeline files for other dirs.
1415

1516
That will do a commit and you just need to push and do a PR.

tools/release-to-wolfi

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# shellcheck disable=SC2015,SC2039,SC2166,SC3043
3-
VERBOSITY=0
3+
VERBOSITY=1
44
# run with 'TWGIT=$PWD' to test locally
55
TWGIT=${TWGIT:-https://github.com/chainguard-dev/tw}
66

@@ -9,10 +9,16 @@ fail() { [ $# -eq 0 ] || stderr "$@"; exit 1; }
99

1010
Usage() {
1111
cat <<EOF
12-
Usage: ${0##*/} tag wolfi-os/
12+
Usage: ${0##*/} tag packages-git-dir/ [ packages-git-dir ...]]
1313
1414
Release 'tag' to wolfi, where 'wolfi-os' is a wolfi-dev/os
1515
git checkout.
16+
17+
packages-git-dir is a local git checkout. A commit will be
18+
added to it that has the pipelines/ sync'd.
19+
20+
If the packages-git-dir is wolfi, then melange.yaml will be
21+
copied to tw.yaml.
1622
EOF
1723
}
1824

@@ -24,10 +30,40 @@ cleanup() {
2430
debug() {
2531
local level="$1"
2632
shift
27-
[ "${level}" -gt "${VERBOSITY}" ] && return
33+
[ "$VERBOSITY" -lt "$level" ] && return
2834
stderr "${@}"
2935
}
3036

37+
sync_to_dir() {
38+
local gdir="$1"
39+
# we assume presence of busybox.yaml indicates wolfi, and that tw should be updated.
40+
if [ -f "$gdir/busybox.yaml" ]; then
41+
debug 1 "updating melange.yaml -> tw.yaml in $gdir"
42+
# search only in lines 1 to 10 for version and epoch
43+
sed -e "1,10s/^\([ ]\+version\): .*/\1: \"${tag#v}\"/" \
44+
-e "1,10s,^\([ ]\+epoch\): .*,\1: 0," \
45+
-e "s,#wolfi#,," \
46+
-e "s,^\([ ]\+expected-commit\): .*$,\1: $cksum," \
47+
"melange.yaml" > "$gdir/tw.yaml"
48+
( cd "$gdir" && git add tw.yaml )
49+
fi
50+
51+
debug 1 "syncing pipelines to $gdir"
52+
for d in pipelines/*/tw; do
53+
[ -d "$gdir/$d" ] || mkdir -p "$gdir/$d" ||
54+
fail "failed to mkdir in $gdir"
55+
cp "$d"/* "$gdir/$d" ||
56+
fail "failed cp tw/$d/* -> $gdir/$d"
57+
( cd "$gdir" && git add "$d" ) ||
58+
fail "failed to git add $d"
59+
done
60+
61+
( cd "$gdir" && git commit -m "tw - bump to $tag" ) ||
62+
fail "failed to commit to $gdir"
63+
return 0
64+
}
65+
66+
3167
main() {
3268
[ "$1" = "--help" ] && { Usage; exit 0; }
3369

@@ -43,15 +79,17 @@ main() {
4379

4480
shift $((OPTIND -1))
4581

46-
[ $# -eq 2 ] || { bad_Usage "got $# args expected 2"; return 1; }
82+
[ $# -ge 2 ] || { bad_Usage "got $# args expected 2+"; return 1; }
4783

48-
local tag="$1" gdir="$2"
84+
local tag="$1"
4985
tag=v${tag#v} # chop of 'v' in v0.0.1
86+
shift
5087

51-
if [ ! -d "$gdir" ]; then
52-
fail "$gdir: not a directory"
53-
fi
54-
gdir=$( cd "$gdir" && pwd ) || fail "failed to cd $gdir"
88+
local gdir=""
89+
for gdir in "$@"; do
90+
[ -d "$gdir" ] || fail "$gdir: not a directory"
91+
( cd "$gdir" ) || fail "failed to cd $gdir"
92+
done
5593

5694
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
5795
fail "failed to make tempdir"
@@ -62,26 +100,9 @@ main() {
62100
cd tw || fail "failed cd into git cloned $TWGIT"
63101
cksum=$(git rev-parse "$tag") || fail "$tag did not exist"
64102

65-
# search only in lines 1 to 10 for version and epoch
66-
sed -e "1,10s/^\([ ]\+version\): .*/\1: \"${tag#v}\"/" \
67-
-e "1,10s,^\([ ]\+epoch\): .*,\1: 0," \
68-
-e "s,#wolfi#,," \
69-
-e "s,^\([ ]\+expected-commit\): .*$,\1: $cksum," \
70-
"melange.yaml" > "$gdir/tw.yaml"
71-
( cd "$gdir" && git add tw.yaml )
72-
73-
for d in pipelines/*/tw; do
74-
[ -d "$gdir/$d" ] || mkdir -p "$gdir/$d" ||
75-
fail "failed to mkdir in $gdir"
76-
cp "$d"/* "$gdir/$d" ||
77-
fail "failed cp tw/$d/* -> $gdir/$d"
78-
( cd "$gdir" && git add "$d" ) ||
79-
fail "failed to git add $d"
103+
for gdir in "$@"; do
104+
sync_to_dir "$gdir" || exit 1
80105
done
81-
82-
cd "$gdir" || fail "failed cd. strange"
83-
git commit -m "tw - bump to $tag"
84-
85106
return 0
86107
}
87108

0 commit comments

Comments
 (0)