Skip to content

Commit

Permalink
Version command (#78)
Browse files Browse the repository at this point in the history
* New version file

* script refactoring

* New command

* clean up

* new env var

* Fixing issues

---------

Co-authored-by: Maksym Bilan <>
  • Loading branch information
maximbilan authored Dec 23, 2024
1 parent 75d59ee commit daa85dd
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:

- name: Run script file
run: |
chmod +x ./scripts/get_version.sh
chmod +x ./scripts/deploy_functions.sh
./scripts/deploy_functions.sh
env:
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.6
3 changes: 2 additions & 1 deletion function.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package capymind
import (
"log"
"net/http"
"os"

"github.com/GoogleCloudPlatform/functions-framework-go/functions"
"github.com/capymind/internal/bot"
"github.com/capymind/internal/scheduler"
)

func init() {
log.Printf("Version: %s", AppVersion)
log.Printf("Version: %s", os.Getenv("APP_VERSION"))

functions.HTTP("handler", handler)
functions.HTTP("schedule", schedule)
Expand Down
1 change: 1 addition & 0 deletions internal/bot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
Language Command = "/language"
Settings Command = "/settings"
Help Command = "/help"
Version Command = "/version"

// Hidden user commands
Timezone Command = "/timezone"
Expand Down
2 changes: 2 additions & 0 deletions internal/bot/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func handleSession(session *Session) {
startFeedback(session)
case Help:
handleHelp(session)
case Version:
handleVersion(session)
case SleepAnalysis:
handleSleepAnalysis(session)
case WeeklyAnalysis:
Expand Down
8 changes: 8 additions & 0 deletions internal/bot/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package bot

import "os"

func handleVersion(session *Session) {
versionStr := "Version: " + os.Getenv("APP_VERSION")
setOutputText(versionStr, session)
}
29 changes: 7 additions & 22 deletions scripts/bump_version.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
#!/bin/bash

# Get the directory of this script
SCRIPT_DIR=$(dirname "$0")

# Path to the version.go file (adjusted for the relative path)
VERSION_FILE="$SCRIPT_DIR/../version.go"

# Check if version.go exists
if [[ ! -f "$VERSION_FILE" ]]; then
echo "Error: $VERSION_FILE not found."
exit 1
fi

# Path to get_version.sh
GET_VERSION_SCRIPT="$SCRIPT_DIR/get_version.sh"

# Import the current version using the get_version.sh script
CURRENT_VERSION=$("$GET_VERSION_SCRIPT")
# Get current version
source ./scripts/get_version.sh
CURRENT_VERSION=$(get_version)

if [[ $? -ne 0 ]]; then
echo "Error: Failed to read the current version."
Expand Down Expand Up @@ -47,11 +33,10 @@ fi
# Construct the new version
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"

# Update the version in the file
sed -i.bak -E "s/(const AppVersion = \")[0-9]+\.[0-9]+\.[0-9]+(\".*)/\1${NEW_VERSION}\2/" "$VERSION_FILE"
# Write the new version to the VERSION file
SCRIPT_DIR=$(dirname "$0")
VERSION_FILE="$SCRIPT_DIR/../VERSION"
echo "$NEW_VERSION" > "$VERSION_FILE"

# Print success message
echo "Version bumped from $CURRENT_VERSION to $NEW_VERSION in $VERSION_FILE"

# Optional: Remove the backup file created by sed
rm -f "${VERSION_FILE}.bak"
20 changes: 3 additions & 17 deletions scripts/create_tag.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
#!/bin/bash

# Get the directory of this script
SCRIPT_DIR=$(dirname "$0")

# Path to the version.go file (adjusted for the relative path)
VERSION_FILE="$SCRIPT_DIR/../version.go"

# Check if version.go exists
if [[ ! -f "$VERSION_FILE" ]]; then
echo "Error: $VERSION_FILE not found."
exit 1
fi

# Path to get_version.sh
GET_VERSION_SCRIPT="$SCRIPT_DIR/get_version.sh"

# Import the current version using the get_version.sh script
CURRENT_VERSION=$("$GET_VERSION_SCRIPT")
# Get current version
source ./scripts/get_version.sh
CURRENT_VERSION=$(get_version)

# Create a new tag
git tag -a "releases/$CURRENT_VERSION" -m "$CURRENT_VERSION"
Expand Down
6 changes: 5 additions & 1 deletion scripts/deploy_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ RUNTIME="go122"
# Set the project ID
PROJECT_ID=$CAPY_PROJECT_ID

# Get current version
source ./scripts/get_version.sh
APP_VERSION=$(get_version)

# Set environment variables
ENV_PARAMS=("CAPY_PROJECT_ID=$CAPY_PROJECT_ID" "CAPY_SERVER_REGION=$CAPY_SERVER_REGION" "CLOUD=true")
ENV_PARAMS=("CAPY_PROJECT_ID=$CAPY_PROJECT_ID" "CAPY_SERVER_REGION=$CAPY_SERVER_REGION" "CLOUD=true" "APP_VERSION=$APP_VERSION")
ENV_VARS=""
for PARAM in "${ENV_PARAMS[@]}"; do
ENV_VARS+="$PARAM,"
Expand Down
31 changes: 12 additions & 19 deletions scripts/get_version.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#!/bin/bash

# File containing the version constant (relative to the script location)
VERSION_FILE="./version.go"
get_version() {
local script_dir version_file
script_dir=$(dirname "$0")
version_file="$script_dir/../VERSION"

# Pattern to match the version line
VERSION_PATTERN='const AppVersion = "'
if [[ ! -f "$version_file" ]]; then
echo "Error: $version_file not found." >&2
exit 1
fi

# Check if version.go exists
if [[ ! -f "$VERSION_FILE" ]]; then
echo "Error: $VERSION_FILE not found."
exit 1
fi
cat "$version_file"
}

# Extract the current version
CURRENT_VERSION=$(grep "$VERSION_PATTERN" "$VERSION_FILE" | sed -E 's/.*"([0-9]+\.[0-9]+\.[0-9]+)".*/\1/')

if [[ -z "$CURRENT_VERSION" ]]; then
echo "Error: Could not find the current version in $VERSION_FILE"
exit 1
fi

# Output the current version
echo "$CURRENT_VERSION"
CURRENT_VERSION=$(get_version)
echo "The current version is: $CURRENT_VERSION"

0 comments on commit daa85dd

Please sign in to comment.