Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
habedi committed Jan 8, 2025
1 parent cfdaa7d commit b2694c4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 98 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Step 2: Set up Snapcraft
# Step 2: Prepare Build Environment
- name: Prepare Environment
run: |
bash build.sh --just-prepare
# Step 3: Set up Snapcraft
- name: Set up Snapcraft
uses: snapcore/action-build@v1
id: build
run: |
sudo apt-get update
sudo bash build.sh
with:
snapcraft-channel: stable

# Step 3: Validate the built Snap
# Step 4: Validate the built Snap
- name: Validate Snap
uses: diddlesnaps/snapcraft-review-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ stage/
prime/
*.snap
test.csv
snap/
67 changes: 47 additions & 20 deletions build.sh
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."
73 changes: 0 additions & 73 deletions old/snapcraft.yaml

This file was deleted.

0 comments on commit b2694c4

Please sign in to comment.