Skip to content

Commit

Permalink
Merge pull request #7 from 1Password/update-dependencies
Browse files Browse the repository at this point in the history
Updating to use latest Connect and Connect Operator versions
  • Loading branch information
jillianwilson authored Apr 12, 2021
2 parents 0460ee4 + 042cf43 commit 030a301
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export MAIN_BRANCH ?= main

.PHONY: release/prepare release/tag .check_git_clean

GIT_BRANCH := $(shell git symbolic-ref --short HEAD)
WORKTREE_CLEAN := $(shell git status --porcelain 1>/dev/null 2>&1; echo $$?)
SCRIPTS_DIR := $(CURDIR)/scripts

versionFile = $(CURDIR)/.VERSION
curVersion := $(shell cat $(versionFile) | sed 's/^v//')

## Release functions =====================

release/prepare: .check_git_clean ## Updates changelog and creates release branch (call with 'release/prepare version=<new_version_number>')

@test $(version) || (echo "[ERROR] version argument not set."; exit 1)
@git fetch --quiet origin $(MAIN_BRANCH)

@echo $(version) | tr -d '\n' | tee $(versionFile) &>/dev/null

@NEW_VERSION=$(version) $(SCRIPTS_DIR)/prepare-release.sh

release/tag: .check_git_clean ## Creates git tag
@git pull --ff-only
@echo "Applying tag 'v$(curVersion)' to HEAD..."
@git tag --sign "v$(curVersion)" -m "Release v$(curVersion)"
@echo "[OK] Success!"
@echo "Remember to call 'git push --tags' to persist the tag."

## Helper functions =====================

.check_git_clean:
ifneq ($(GIT_BRANCH), $(MAIN_BRANCH))
@echo "[ERROR] Please checkout default branch '$(MAIN_BRANCH)' and re-run this command."; exit 1;
endif
ifneq ($(WORKTREE_CLEAN), 0)
@echo "[ERROR] Uncommitted changes found in worktree. Address them and try again."; exit 1;
endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ $ helm install --set connect.applicationName=connect connect ./connect
| operator.serviceAccount.annotations | object | `{}` | Annotations for the 1Password Connect Service Account |
| operator.serviceAccount.create | boolean | `false` | Denotes whether or not a service account will be created for the 1Password Connect Operator |
| operator.serviceAccount.name | string | `"onepassword-connect-operator"` | The name of the 1Password Conenct Operator |
| operator.version | string | `"0.0.1"` | T 1Password Connect Operator version to pull |
| operator.version | string | `"1.0.0"` | T 1Password Connect Operator version to pull |
| operator.token.key | string | `"token"` | The key for the 1Password Connect token stored in the 1Password token secret |
| operator.token.name | string | `"onepassword-token"` | The name of Kubernetes Secret containing the 1Password Connect API token |
| operator.token.value | string | `"onepassword-token"` | An API token generated for 1Password Connect to be used by the Connect Operator |
Expand Down
4 changes: 2 additions & 2 deletions connect/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: onepassword-connect
version: 0.0.1
version: 1.0.0
description: A Helm chart for deploying 1Password Connect and the 1Password Connect Kubernetes Operator
keywords:
- "1Password"
Expand All @@ -11,4 +11,4 @@ maintainers: # (optional)
- name: 1Password Secrets Integrations Team
email: support+business@1password.com
icon: https://1password.com/img/logo-v1.svg
appVersion: "0.5"
appVersion: "1.0.0"
4 changes: 2 additions & 2 deletions connect/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ connect:
type: emptyDir
values: {}
imagePullPolicy: IfNotPresent
version: "0.5"
version: "1.0.0"

namespace: default

Expand All @@ -27,7 +27,7 @@ operator:
imagePullPolicy: IfNotPresent
imageRepository: 1password/onepassword-operator
pollingInterval: 10
version: "0.0.1"
version: "1.0.0"
watchNamespace:
- "default"
token:
Expand Down
104 changes: 104 additions & 0 deletions scripts/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
#
# prepare-release.sh
# (Note: This should be called by `make release/prepare` because it depends
# on several variables set by the Makefile)
#
# Performs release preparation tasks:
# - Creates a release branch
# - Renames "LATEST" section to the new version number
# - Adds new "LATEST" entry to the changelog
#
##############################################
set -Eeuo pipefail

if [[ -z "${NEW_VERSION:-}" ]]; then
echo "[ERROR] NEW_VERSION environment variable not defined." >&2
exit 1
fi

# Script called from within a git repo?
if [[ $(git rev-parse --is-inside-work-tree &>/dev/null) -ne 0 ]]; then
echo "[ERROR] Current directory (${SRCDIR}) is not a git repository" >&2
exit 1
fi

REPO_ROOT=$(git rev-parse --show-toplevel)
CHANGELOG_FILENAME=${CHANGELOG:-"CHANGELOG.md"}

# normalize version by removing `v` prefix
VERSION_NUM=${NEW_VERSION/#v/}
RELEASE_BRANCH=$(printf "release/v%s" "${VERSION_NUM}")

function updateChangelog() {
local tmpfile

trap '[ -e "${tmpfile}" ] && rm "${tmpfile}"' RETURN

local changelogFile
changelogFile=$(printf "%s/%s" "${REPO_ROOT}" "${CHANGELOG_FILENAME}")

# create Changelog file if not exists
if ! [[ -f "${REPO_ROOT}/${CHANGELOG_FILENAME}" ]]; then
touch "${REPO_ROOT}/${CHANGELOG_FILENAME}" && \
git add "${REPO_ROOT}/${CHANGELOG_FILENAME}"
fi

tmpfile=$(mktemp)

# Replace "Latest" in the top-most changelog block with new version
# Then push a new "latest" block to top of the changelog
awk 'NR==1, /---/{ sub(/START\/LATEST/, "START/v'${VERSION_NUM}'"); sub(/# Latest/, "# v'${VERSION_NUM}'") } {print}' \
"${changelogFile}" > "${tmpfile}"

# Inserts "Latest" changelog HEREDOC at the top of the file
cat - "${tmpfile}" << EOF > "${REPO_ROOT}/${CHANGELOG_FILENAME}"
[//]: # (START/LATEST)
# Latest
## Features
* A user-friendly description of a new feature. {issue-number}
## Fixes
* A user-friendly description of a fix. {issue-number}
## Security
* A user-friendly description of a security fix. {issue-number}
---
EOF
}

function _main() {

# Stash version changes
git stash push &>/dev/null

if ! git checkout -b "${RELEASE_BRANCH}" origin/"${MAIN_BRANCH:-main}"; then
echo "[ERROR] Could not check out release branch." >&2
git stash pop &>/dev/null
exit 1
fi

# Add the version changes to release branch
git stash pop &>/dev/null

updateChangelog

cat << EOF
[SUCCESS] Changelog updated & release branch created:
New Version: ${NEW_VERSION}
Release Branch: ${RELEASE_BRANCH}
Next steps:
1. Edit the changelog notes in ${CHANGELOG_FILENAME}
2. Commit changes to the release branch
3. Push changes to remote => git push origin ${RELEASE_BRANCH}
EOF
exit 0
}

_main

0 comments on commit 030a301

Please sign in to comment.