Skip to content

Commit

Permalink
feat: Update version to 1.0.0
Browse files Browse the repository at this point in the history
Update the version from 0.1.0 to 1.0.0 in pyproject.toml file and add a new __version__.py file with the updated version number "1.0.0". Also, include a description for the argument parser in args.py and provide a link to the project repository.

For more details, see: https://github.com/25077667/cg

feat: Add copy_artifact_dest and copy_artifact_path options

Add support for specifying the destination directory for copied artifacts and the path of the artifact to be copied. This allows more flexibility in handling artifacts generated during the workflow execution.

- Added `copy_artifact_dest` option to specify destination directory for copied artifacts
- Added `copy_artifact_path` parameter to define path of specific artifact to be copied
- Updated workflow steps to include copying artifact based on architecture into designated release folder

feat: Update release workflow to correctly extract and upload artifacts

- Use the current working directory variable to set the base path
- Create a temporary mount directory in runner's temp folder
- Mount the output image into the temporary mount directory
- Create a 'release' folder in the current directory for artifact extraction
- Copy artifacts from mounted location to local 'release' folder for upload via actions/upload-artifact

This commit updates the release workflow in '.github/workflows/release.yml'
to improve artifact extraction and uploading process.

feat: Update release workflow to upload image artifact

Add a step to extract and upload the image artifact for debugging
purposes. Now, the workflow uploads the image file instead of the elf
file. Also, commented out uploading elf file for now.

feat: Add script to extract binary from ARM Linux image

Add a new script `armlinux_loopdev_extract.sh` to extract the binary
file from an ARM Linux image. This script sets up loop devices, mounts
the partition, and copies the binary file to the specified output file.

The script checks if the necessary arguments are provided and verifies
the existence of the image file. It then sets up a loop device for the
image, identifies and mounts the second partition, copies the binary,
and unmounts/detaches loop devices upon completion.

The addition enhances automation by facilitating extraction of binaries
from ARM Linux images efficiently.
  • Loading branch information
25077667 committed May 18, 2024
1 parent fd239eb commit 2a78e1c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,46 @@ jobs:
matrix:
arch: [armv7l, aarch64]
include:
- arch: armv6l
- arch: armv7l
cpu: cortex-a7
base_image: raspios_lite:latest
cpu_info: cpuinfo/raspberrypi_zero2_w
image_additional_mb: 1024
copy_artifacts_on_fail: yes
copy_artifact_dest: /release
- arch: aarch64
cpu: cortex-a53
base_image: raspios_lite_arm64:latest
cpu_info: cpuinfo/raspberrypi_zero2_w_arm64
image_additional_mb: 1024
copy_artifacts_on_fail: yes
copy_artifact_dest: /release
steps:
- uses: actions/checkout@v4
- uses: pguyot/arm-runner-action@v2
id: arm_runner_install
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
cpu_info: ${{ matrix.cpu_info }}
shell: bash
image_additional_mb: ${{ matrix.image_additional_mb }}
copy_artifacts_on_fail: ${{ matrix.copy_artifacts_on_fail }}
copy_artifact_path: cg-${{ matrix.arch }}.elf
commands: |
apt-get update -y
apt-get install python3-dev python3 python3-pip patchelf ccache -y --no-install-recommends
pip install poetry --break-system-packages
poetry install
df -h
ci/build_nuitka/unix.sh
mkdir -p ${{ matrix.copy_artifact_dest }}
- name: Extract Artifact from output image
run: |
sudo apt-get install -y fdisk parted
chmod +x ./ci/armlinux_loopdev_extract.sh
./ci/armlinux_loopdev_extract.sh ${{ steps.arm_runner_install.outputs.image }} cg-${{ matrix.arch }}.elf
- name: Upload Artifact (ARM)
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -160,7 +171,7 @@ jobs:
commit: ${{ github.sha }}
draft: false
prerelease: false
artifacts: release/*.elf release/*.exe release/*.macho
artifacts: "release/*/cg-*.*"
env:
GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN2 }}
TAG_NAME: ${{ env.TAG_NAME }}
Expand Down
89 changes: 89 additions & 0 deletions ci/armlinux_loopdev_extract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

# Check if the user provided an image file and output file
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <image_file> <output_file>"
exit 1
fi

IMG_FILE=$1
OUTPUT_FILE=$2
PWD=$(pwd)
MNT_POINT="$PWD/mnt"

# Check if the file exists
if [ ! -f "$IMG_FILE" ]; then
echo "File not found: $IMG_FILE"
exit 1
fi

# Setup loop device and get partitions info
LOOP_DEVICE=$(sudo losetup -fP --show "$IMG_FILE")

if [ $? -ne 0 ]; then
echo "Failed to setup loop device for $IMG_FILE"
exit 1
fi

echo "Created loopback device ${LOOP_DEVICE}"

# Check the partition table
sudo parted -s "$LOOP_DEVICE" print

# Get partition information
PARTITION_INFO=$(sudo parted -s "$LOOP_DEVICE" unit s print | grep "^ [0-9]")

if [ $? -ne 0 ]; then
echo "Failed to get partition information"
sudo losetup -d "$LOOP_DEVICE"
exit 1
fi

# Parse the second partition details
PARTITION_OFFSET=$(echo "$PARTITION_INFO" | awk 'NR==2 {print $2}' | sed 's/s//')
PARTITION_SIZE=$(echo "$PARTITION_INFO" | awk 'NR==2 {print $4}' | sed 's/s//')

# Create a loop device for the second partition
PARTITION_LOOP_DEVICE=$(sudo losetup -o $((PARTITION_OFFSET * 512)) --sizelimit $((PARTITION_SIZE * 512)) --show -f "$LOOP_DEVICE")

if [ $? -ne 0 ]; then
echo "Failed to create loop device for partition"
sudo losetup -d "$LOOP_DEVICE"
exit 1
fi

# Create the mount point directory if it doesn't exist
mkdir -p $MNT_POINT

# Mount the partition
sudo mount "$PARTITION_LOOP_DEVICE" $MNT_POINT

if [ $? -ne 0 ]; then
echo "Failed to mount partition"
sudo losetup -d "$PARTITION_LOOP_DEVICE"
sudo losetup -d "$LOOP_DEVICE"
exit 1
fi

# Copy the binary file from the mounted partition to the output file
sudo cp $MNT_POINT/cg/*.elf $OUTPUT_FILE

if [ $? -ne 0 ]; then
echo "Failed to copy the binary file"
sudo umount $MNT_POINT
sudo losetup -d "$PARTITION_LOOP_DEVICE"
sudo losetup -d "$LOOP_DEVICE"
exit 1
fi

echo "Binary file copied successfully to $OUTPUT_FILE"

# Cleanup function to unmount and detach loop devices
cleanup() {
sudo umount $MNT_POINT
sudo losetup -d "$PARTITION_LOOP_DEVICE"
sudo losetup -d "$LOOP_DEVICE"
}

# Trap EXIT signal to ensure cleanup is done
trap cleanup EXIT
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cg"
version = "0.1.0"
version = "1.0.0"
description = ""
authors = ["scc <[email protected]>"]
license = "GPL3"
Expand Down
1 change: 1 addition & 0 deletions src/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
21 changes: 20 additions & 1 deletion src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

from argparse import ArgumentParser
import os
from . import __version__


def _get_version() -> str:
return __version__.__version__


DESCRIPTION = """
A tool to generate commit messages based on the current state of a git repository.
For more details, see: https://github.com/25077667/cg
"""


class Args:
Expand All @@ -12,14 +23,22 @@ class Args:
"""

def __init__(self) -> None:
self.parser = ArgumentParser()
self.parser = ArgumentParser(
description=DESCRIPTION,
)
self.parser.add_argument(
"-c",
"--config",
type=str,
default=os.path.join(os.path.expanduser("~"), ".cg", "config.json"),
help="Path to config file",
)
self.parser.add_argument(
"-v",
"--version",
action="version",
version=_get_version(),
)

self.args = self.parser.parse_args()

Expand Down

0 comments on commit 2a78e1c

Please sign in to comment.