Skip to content

Commit

Permalink
✨ update release process
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Apr 21, 2024
1 parent 49015cf commit 71c594c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ Auto parsing of arguments and options based on your command configuration:
### Dependencies

- Bash version 5.2 or superior is required (might work with older versions but it is not guaranteed).
- From [GNU coreutils](https://www.gnu.org/software/coreutils/): it uses `rm`, `mv`, `mkdir`, `ln` (for the install).
- [curl][curl] and [tar][tar] are needed only for the self-update command.
- From [GNU coreutils](https://www.gnu.org/software/coreutils/): it uses `rm`, `mv`, `mkdir` for all commands. It uses `chmod`, `ln` for the installation/updates.
- [curl][curl] and [tar][tar] are needed if you want to use the self-update command.

### Automated installation

Expand Down
5 changes: 5 additions & 0 deletions tests.d/1103-self-release/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ DEBUG Checking if the workarea is clean
▶ called io::invoke5 false 0 git update-index --really-refresh
▶ called io::invoke5 false 0 git diff-index --quiet HEAD
INFO The current version of valet is: 1.2.3.
▶ called io::invoke sed -E -i s/VALET_VERSION="[0-9]+\.[^"]+"/VALET_VERSION="aa"/ $GLOBAL_VALET_HOME/valet.d/commands.d/self-install.sh
▶ called io::invoke git add $GLOBAL_VALET_HOME/valet.d/commands.d/self-install.sh
▶ called io::invoke git commit -m :rocket: releasing version 2.0.0
▶ called io::invoke git push origin main
SUCCESS The new version has been committed.
▶ called io::invoke git tag --sort=committerdate --no-color
INFO The last tag is: v1.2.3.
▶ called io::invoke git log --pretty=format:%s v1.2.3..HEAD
Expand Down
29 changes: 19 additions & 10 deletions valet.d/commands.d/self-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Do not run this script with sudo, it will ask for your password when needed.
#
# This script will :
# - Download the latest release from GitHub.
# - Download the given release from GitHub.
# - Copy it in the Valet home directory, which defaults to:
# - '/opt/valet' in case of a multi user installation
# - '~/.local/valet' otherwise
Expand Down Expand Up @@ -46,13 +46,19 @@ if [[ -z "${BASH_VERSION:-}" ]]; then
exit 0
fi

if [[ -z "${VALET_VERSION:-}" ]]; then
VALET_VERSION="0.0.1"
fi

# import the core script (should always be skipped if the command is run from valet)
if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
NOT_EXECUTED_FROM_VALET=true

VALETD_DIR="${BASH_SOURCE[0]}"
if [[ "${VALETD_DIR}" != /* ]]; then
if pushd "${VALETD_DIR%/*}" &>/dev/null; then VALETD_DIR="${PWD}"; popd &>/dev/null || true;
if pushd "${VALETD_DIR%/*}" &>/dev/null; then
VALETD_DIR="${PWD}"
popd &>/dev/null || true
else VALETD_DIR="${PWD}"; fi
else VALETD_DIR="${VALETD_DIR%/*}"; fi
VALETD_DIR="${VALETD_DIR%/*}" # strip directory
Expand Down Expand Up @@ -140,17 +146,21 @@ function selfUpdate() {
local tempDirectory="${TMPDIR:-/tmp}/temp-${BASHPID}.valet.install.d"
mkdir -p "${tempDirectory}" 1>/dev/null || core::fail "Could not create the temporary directory ⌜${tempDirectory}⌝."

# download the latest release and unpack it
local latestReleaseUrl="https://github.com/jcaillon/valet/releases/latest/download/valet.tar.gz"
local latestReleaseFile="${tempDirectory}/valet.tar.gz"
log::info "Downloading the latest release from ⌜${latestReleaseUrl}⌝."
curl -fsSL -o "${latestReleaseFile}" "${latestReleaseUrl}" || core::fail "Could not download the latest release from ⌜${latestReleaseUrl}⌝."
# download the release and unpack it
local releaseUrl="https://github.com/jcaillon/valet/releases/download/v${VALET_VERSION}/valet.tar.gz"
if [[ ${NOT_EXECUTED_FROM_VALET} != "true" ]]; then
VALET_VERSION="latest"
releaseUrl="https://github.com/jcaillon/valet/releases/latest/download/valet.tar.gz"
fi
local releaseFile="${tempDirectory}/valet.tar.gz"
log::info "Downloading the release ⌜${VALET_VERSION}⌝ from ⌜${releaseUrl}⌝."
curl -fsSL -o "${releaseFile}" "${releaseUrl}" || core::fail "Could not download the release ⌜${VALET_VERSION}⌝ from ⌜${releaseUrl}⌝."
log::debug "Unpacking the release in ⌜${GLOBAL_VALET_HOME}⌝."
tar -xzf "${latestReleaseFile}" -C "${tempDirectory}"
tar -xzf "${releaseFile}" -C "${tempDirectory}"
log::debug "The release has been unpacked in ⌜${GLOBAL_VALET_HOME}⌝ with:"$'\n'"${LAST_RETURNED_VALUE}."

# remove the old valet directory and move the new one
${SUDO} rm -f "${latestReleaseFile}"
${SUDO} rm -f "${releaseFile}"
${SUDO} rm -Rf "${GLOBAL_VALET_HOME}"
${SUDO} mv -f "${tempDirectory}" "${GLOBAL_VALET_HOME}"
log::info "Valet has been copied in ⌜${GLOBAL_VALET_HOME}⌝."
Expand Down Expand Up @@ -216,7 +226,6 @@ function selfUpdate() {
fi
}


# if this script is run directly, execute the function, otherwise valet will do it
if [[ ${NOT_EXECUTED_FROM_VALET:-false} == "true" ]]; then
selfUpdate "$@"
Expand Down
11 changes: 11 additions & 0 deletions valet.d/commands.d/self-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ function createRelease() {
version="${version%%$'\n'*}"
log::info "The current version of valet is: ${version}."

# write the current version in the self-install script
# then commit the file
if [[ "${dryRun:-}" != "true" ]]; then
io::invoke sed -E -i "s/VALET_VERSION=\"[0-9]+\.[^\"]+\"/VALET_VERSION=\"aa\"/" "${GLOBAL_VALET_HOME}/valet.d/commands.d/self-install.sh"

io::invoke git add "${GLOBAL_VALET_HOME}/valet.d/commands.d/self-install.sh"
io::invoke git commit -m ":rocket: releasing version ${version}"
io::invoke git push origin main
log::success "The new version has been committed."
fi

# get the current latest tag
local lastTag
io::invoke git tag --sort=committerdate --no-color
Expand Down
2 changes: 1 addition & 1 deletion valet.d/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.315
0.6.317

0 comments on commit 71c594c

Please sign in to comment.