generated from habedi/template-python-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
98 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
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 |
---|---|---|
|
@@ -77,3 +77,4 @@ stage/ | |
prime/ | ||
*.snap | ||
test.csv | ||
snap/ |
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 |
---|---|---|
@@ -1,30 +1,57 @@ | ||
#!/bin/bash | ||
|
||
SNAP_DIR="snapcraft_files" | ||
# Directory containing versioned Snapcraft files | ||
SNAPCRAFT_FILES_DIR="snapcraft_files" | ||
|
||
# Function to compare semantic versions | ||
# Function to compare semantic versions and find the highest | ||
get_highest_version() { | ||
# List all directories matching the pattern "vX.X.X" | ||
versions=$(ls -d ${SNAP_DIR}/v* 2>/dev/null | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -V) | ||
# Find directories matching the pattern "vX.X.X" and extract valid semantic versions | ||
versions=$(ls -d ${SNAPCRAFT_FILES_DIR}/v* 2>/dev/null | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -V) | ||
|
||
# If no valid versions found, return | ||
if [[ -z "$versions" ]]; then | ||
echo "No valid semantic version directories found in '$SNAP_DIR'." | ||
exit 1 | ||
fi | ||
# If no valid versions are found, exit with an error | ||
if [[ -z "$versions" ]]; then | ||
echo "Error: No valid semantic version directories found in '$SNAPCRAFT_FILES_DIR'." | ||
exit 1 | ||
fi | ||
|
||
# Get the highest version | ||
highest_version=$(echo "$versions" | tail -n 1) | ||
echo "$highest_version" | ||
# Return the highest version | ||
echo "$versions" | tail -n 1 | ||
} | ||
|
||
# Get the highest version | ||
FOLDER_NAME=$(get_highest_version) | ||
VERSION="${FOLDER_NAME#v}" # Remove the 'v' prefix | ||
echo "Highest version: $highest_version" | ||
|
||
# Build the Snap package | ||
pushd "$SNAP_DIR/v$VERSION" || exit | ||
SNAPCRAFT_BUILD_ENVIRONMENT=multipass snapcraft # Build the package using multipass | ||
mv -f *.snap ../../ # Move the built snap file to the root directory | ||
popd || exit | ||
if [[ $? -ne 0 ]]; then | ||
exit 1 | ||
fi | ||
|
||
# Remove the 'v' prefix to get the version number | ||
VERSION="${FOLDER_NAME#v}" | ||
echo "Detected highest version: $VERSION" | ||
|
||
# Handle the `--just-prepare` argument | ||
if [[ "$1" == "--just-prepare" ]]; then | ||
echo "Preparing Snapcraft files for version $VERSION..." | ||
mkdir -p snap | ||
cp -f "$SNAPCRAFT_FILES_DIR/$FOLDER_NAME/snapcraft.yaml" snap/snapcraft.yaml | ||
echo "Snapcraft.yaml prepared in the 'snap' directory." | ||
exit 0 | ||
fi | ||
|
||
# Build the Snap package for the highest version | ||
echo "Building Snap package for version $VERSION..." | ||
if pushd "$SNAPCRAFT_FILES_DIR/v$VERSION" > /dev/null; then | ||
SNAPCRAFT_BUILD_ENVIRONMENT=multipass snapcraft # Build the package using Multipass | ||
if [[ $? -eq 0 ]]; then | ||
echo "Build successful. Moving Snap package to the root directory..." | ||
mv -f *.snap ../../ # Move the built snap file to the root directory | ||
else | ||
echo "Error: Snap build failed." | ||
exit 1 | ||
fi | ||
popd > /dev/null || exit | ||
else | ||
echo "Error: Failed to access directory '$SNAPCRAFT_FILES_DIR/v$VERSION'." | ||
exit 1 | ||
fi | ||
|
||
echo "Snap package build process completed." |
This file was deleted.
Oops, something went wrong.