Skip to content

Commit

Permalink
start a release-inventory.sh and install-cr.sh script
Browse files Browse the repository at this point in the history
also clean up some other scripts and add docs
  • Loading branch information
colearendt authored and willholley committed Sep 28, 2022
1 parent 5733350 commit 973ac31
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
47 changes: 47 additions & 0 deletions docs/DEPRECATED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Deprecated

Per [this issue](https://github.com/apache/couchdb-helm/issues/62), we plan to move things in `./docs` here
to GitHub releases and follow the helm community's guidance on
release practices for helm charts.

# Migration Path

In order to migrate the old .tgz files, we:

- Will find the latest commit that modified a .tgz
- Sanity check that `Chart.yaml` represents the same version
- Forego any further file consistency checks (this is best effort)
- Presume that the git state matches what is in the .tgz at that time
- Tag and release the given commit to GitHub Releases using [`chart-releaser`](https://github.com/helm/chart-releaser)

## How To

1. `cd docs` to move into this directory
2. Install the `chart-releaser` binary (only one architecture defined)
```bash
cd docs
./install-cr.sh
```
3. Build an inventory of what .tgz files exist in the directory
```bash
./get-inventory.sh
```
4. Sanity check that things look appropriate
```bash
./check-inventory.sh
```
5. Run the release dry-run
```bash
# ./release-inventory.sh {{ owner }}
# i.e.
./release-inventory.sh colearendt
```
6. Check that things look good, then run the actual release process
```bash
# ./release-inventory.sh {{ owner }} execute
# (see docs for more info / other args)
# i.e.
./release-inventory.sh colearendt execute
```

NOTE: we have not done anything to sign chart packages here, though `chart-releaser` supports doing so.
4 changes: 3 additions & 1 deletion docs/get-inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ echo '--> Building inventory.txt with files and commits'

# generate the list of backfill commits
# assuming that the commit that added the tarball also has the appropriate state committed to the repo
for f in `ls . | grep -v '.*backfill.*' | grep -v '.*inventory.*' | grep -v '.*index.*'`; do echo $f: `git log --oneline -- $f | head -1` >> inventory.txt; done
for f in `ls . | grep 'couchdb-.*\.tgz'`; do
echo $f: `git log --oneline -- $f | head -1` >> inventory.txt;
done

echo '--> Done!'
13 changes: 13 additions & 0 deletions docs/install-cr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

os=$(uname -p)
arch=$(uname -s)
if [[ "${os}" == "arm" ]] && [[ "${arch}" == "Darwin" ]]; then
mkdir -p ./bin/cr-1.4.0/
curl -L https://github.com/helm/chart-releaser/releases/download/v1.4.0/chart-releaser_1.4.0_darwin_arm64.tar.gz | tar -xzvf - -C ./bin/cr-1.4.0/
ln -f -s $PWD/bin/cr-1.4.0/cr $PWD/bin/cr
echo "Installed successfully!"
else
echo "ERROR: OS '${os}' and Architecture '${arch}' not defined"
echo "Visit https://github.com/helm/chart-releaser/releases to see releases"
fi
73 changes: 73 additions & 0 deletions docs/release-inventory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

set -euxo pipefail

# Example usage
#
#
# $1 == owner - no default
# $2 == "execute" makes the release fire!
# $3 == GitHub auth token. Defaults to the value of $GITHUB_PAT
# $4 == GitHub repository - defaults to "couchdb-helm"

owner=${1:-}
execute=${2:-}
token=${3:-${GITHUB_PAT:-}}
repo=${4:-couchdb-helm}
chart_name=${5:-couchdb}

if [[ -z "$owner" ]]; then
echo "Error: must provide 'owner' in first argument"
exit 1
fi

echo "Owner: $owner"
echo "Execute?: $execute"

IFS_OLD=$IFS
trap 'IFS=$IFS_OLD' EXIT SIGINT
IFS=$'\n'

current_sha=$(git branch --show-current)
res=$?
if [[ $res -gt 0 ]]; then
current_sha=$(git rev-parse --short HEAD)
fi;
# clean up handler. This warns, but does help escape the loop on interrupt
trap "git checkout $current_sha; exit 1" EXIT SIGINT

inventory=$(cat inventory.txt)
for line in ${inventory}; do
echo $line;
tarball=$(echo $line | cut -d: -f 1);
gitsha=$(echo $line | cut -d' ' -f 2);
cversion=${tarball/couchdb-/};
cversion=${cversion/.tgz/};
echo "--> Checking out '$gitsha' for chart version '$cversion'";

git checkout $gitsha;

long_sha=$(git rev-parse $gitsha)

read -n 1 -p "Pausing to check if this is ok. Press any key to continue: ";
echo ;
echo "--> Continuing...";
echo; echo;

if [[ "$execute" == "execute" ]] && [[ -n "$token" ]]; then
echo "--> Setting tag for release ${cversion} and sha ${gitsha}!"
git tag -f ${chart_name}-${cversion}
echo "--> Executing release!"
./bin/cr package ../couchdb
./bin/cr upload -c "$long_sha" --skip-existing -t "$token" -o $owner -r $repo
git push --tags --force
# clean the directory
rm .cr-release-packages/*
else
echo "--> 'execute' was not provided to the .sh invocation. Skipping..."
fi

done

git checkout $current_sha
exit 0

0 comments on commit 973ac31

Please sign in to comment.