Skip to content

Commit

Permalink
App Version (#75)
Browse files Browse the repository at this point in the history
* bump minor version script

* create tag empty script

* get_version script

* use get_version script

* create tag script

* deploy yml update

* Fixing other scripts

* print version

---------

Co-authored-by: Maksym Bilan <>
  • Loading branch information
maximbilan authored Dec 23, 2024
1 parent 51e196f commit 75d59ee
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 12 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/bump_minor_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Bump Minor Version

on:
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
setup-telegram-bot:
name: Bump Minor Version
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run script file
run: |
chmod +x ./scripts/get_version.sh
chmod +x ./scripts/bump_version.sh
./scripts/bump_version.sh --minor
shell: bash

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
branch: 'bump-minor-version'
delete-branch: true
commit-message: 'Bump minor version'
title: 'Bump minor version'
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/bump_patch_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:

- name: Run script file
run: |
chmod +x ./scripts/get_version.sh
chmod +x ./scripts/bump_version.sh
./scripts/bump_version.sh
shell: bash
Expand Down
50 changes: 48 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

jobs:
setup-telegram-bot:
deploy:
name: Deploy Google Cloud Functions
runs-on: ubuntu-latest
environment: production
Expand Down Expand Up @@ -34,4 +34,50 @@ jobs:
env:
CAPY_PROJECT_ID: ${{ secrets.CAPY_PROJECT_ID }}
CAPY_SERVER_REGION: ${{ secrets.CAPY_SERVER_REGION }}
shell: bash
shell: bash

create-tag:
name: Create Tag
runs-on: ubuntu-latest
needs: deploy
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run script file
run: |
chmod +x ./scripts/get_version.sh
chmod +x ./scripts/create_tag.sh
./scripts/create_tag.sh
shell: bash

bump-version:
name: Bump Patch Version
runs-on: ubuntu-latest
needs: create-tag
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run script file
run: |
chmod +x ./scripts/get_version.sh
chmod +x ./scripts/bump_version.sh
./scripts/bump_version.sh
shell: bash

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
branch: 'bump-patch-version'
delete-branch: true
commit-message: 'Bump patch version'
title: 'Bump patch version'
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package capymind

import (
"log"
"net/http"

"github.com/GoogleCloudPlatform/functions-framework-go/functions"
Expand All @@ -9,6 +10,8 @@ import (
)

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

functions.HTTP("handler", handler)
functions.HTTP("schedule", schedule)
functions.HTTP("sendMessage", sendMessage)
Expand Down
23 changes: 13 additions & 10 deletions scripts/bump_version.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/bin/bash

# File containing the version constant (relative to the script location)
VERSION_FILE="./version.go"
# 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

# Pattern to match the version line
VERSION_PATTERN='const AppVersion = "'
# Path to get_version.sh
GET_VERSION_SCRIPT="$SCRIPT_DIR/get_version.sh"

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

if [[ -z "$CURRENT_VERSION" ]]; then
echo "Error: Could not find the current version in $VERSION_FILE"
if [[ $? -ne 0 ]]; then
echo "Error: Failed to read the current version."
exit 1
fi

Expand Down Expand Up @@ -45,10 +48,10 @@ fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"

# Update the version in the file
sed -i.bak -E "s/$VERSION_PATTERN[0-9]+\.[0-9]+\.[0-9]+\"/$VERSION_PATTERN${NEW_VERSION}\"/" "$VERSION_FILE"
sed -i.bak -E "s/(const AppVersion = \")[0-9]+\.[0-9]+\.[0-9]+(\".*)/\1${NEW_VERSION}\2/" "$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"
rm -f "${VERSION_FILE}.bak"
25 changes: 25 additions & 0 deletions scripts/create_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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")

# Create a new tag
git tag -a "releases/$CURRENT_VERSION" -m "$CURRENT_VERSION"

# Push the tag to the remote repository
git push origin "releases/$CURRENT_VERSION"
24 changes: 24 additions & 0 deletions scripts/get_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# File containing the version constant (relative to the script location)
VERSION_FILE="./version.go"

# Pattern to match the version line
VERSION_PATTERN='const AppVersion = "'

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

# 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"

0 comments on commit 75d59ee

Please sign in to comment.