From b2694c45639520bd7eed353e30e9867657393b69 Mon Sep 17 00:00:00 2001 From: Hassan Abedi Date: Wed, 8 Jan 2025 18:01:31 +0100 Subject: [PATCH] WIP --- .github/workflows/builds.yml | 12 +++--- .gitignore | 1 + build.sh | 67 +++++++++++++++++++++++---------- old/snapcraft.yaml | 73 ------------------------------------ 4 files changed, 55 insertions(+), 98 deletions(-) delete mode 100644 old/snapcraft.yaml diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index a7d7d20..8ce8b90 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -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: diff --git a/.gitignore b/.gitignore index a94c6a5..6e3856f 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,4 @@ stage/ prime/ *.snap test.csv +snap/ diff --git a/build.sh b/build.sh index 9b98fdd..5c0cffd 100644 --- a/build.sh +++ b/build.sh @@ -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." diff --git a/old/snapcraft.yaml b/old/snapcraft.yaml deleted file mode 100644 index 97ef2bb..0000000 --- a/old/snapcraft.yaml +++ /dev/null @@ -1,73 +0,0 @@ -name: duckdb -version: '1.1.3' -summary: DuckDB is a fast DBMS for data analytics with support for SQL and ACID transactions. -description: | - DuckDB is an embeddable SQL OLAP database management system. - It is designed to handle analytical workloads with high performance on modern hardware. - DuckDB is based on a columnar storage model, designed for vectorized query execution, and has fully ACID-compliant - transactions. - - Quick Start: - - Launch the DuckDB CLI: `duckdb` - - Check the version: `select version();` - - Read a CSV file: `select * from read_csv_auto('my_file.csv') limit 100;` - - **Please note that this an unofficial Snap package for DuckDB.** - -base: core24 -confinement: strict -grade: stable -compression: lzo - -license: MIT -website: https://duckdb.org -contact: hassan.abedi.t+duckdb@gmail.com -source-code: https://github.com/duckdb/duckdb -issues: [ https://github.com/duckdb/duckdb/issues, https://github.com/habedi/duckdb-snap/issues ] - -assumes: - - snapd2.38 # Minimum version of Snapd required - -platforms: - amd64: - build-on: [ amd64 ] - build-for: [ amd64 ] - arm64: - build-on: [ arm64 ] - build-for: [ arm64 ] - -parts: - duckdb-amd64: - plugin: dump - source: https://github.com/duckdb/duckdb/releases/download/v1.1.3/duckdb_cli-linux-amd64.zip - source-type: zip - source-checksum: sha256/efd0fccdb1a28d9ec7a6ebfcde59900068b8ba43a846c9b553c0fd2bbe4acf43 - override-build: | - cp $SNAPCRAFT_PART_SRC/duckdb $SNAPCRAFT_PART_INSTALL/duckdb - curl -o LICENSE https://raw.githubusercontent.com/duckdb/duckdb/main/LICENSE - cp LICENSE $SNAPCRAFT_PART_INSTALL/LICENSE - stage: - - duckdb - - LICENSE - duckdb-arm64: - plugin: dump - source: https://github.com/duckdb/duckdb/releases/download/v1.1.3/duckdb_cli-linux-aarch64.zip - source-type: zip - source-checksum: sha256/6e6caaab69a9c8d77c4400e88197695b072a98b678f6f8ffb015af4f02b13618 - override-build: | - cp $SNAPCRAFT_PART_SRC/duckdb $SNAPCRAFT_PART_INSTALL/duckdb - curl -o LICENSE https://raw.githubusercontent.com/duckdb/duckdb/main/LICENSE - cp LICENSE $SNAPCRAFT_PART_INSTALL/LICENSE - stage: - - duckdb - - LICENSE - -apps: - duckdb: - command: duckdb - aliases: [ duckdb-cli ] # Optional alias for the command - plugs: - - home - - removable-media - - network - - network-bind