-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from 1Password/update-dependencies
Updating to use latest Connect and Connect Operator versions
- Loading branch information
Showing
5 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |