diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..a4b413c --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,90 @@ +name: Build and Release + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build on ${{ matrix.os }} for ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + arch: [x86_64, ARM64] + include: + - os: ubuntu-latest + arch: ARM64 + target: aarch64-unknown-linux-gnu + - os: ubuntu-latest + arch: x86_64 + target: x86_64-unknown-linux-gnu + - os: macos-latest + arch: ARM64 + target: aarch64-apple-darwin + - os: macos-latest + arch: x86_64 + target: x86_64-apple-darwin + - os: windows-latest + arch: ARM64 + target: aarch64-pc-windows-msvc + - os: windows-latest + arch: x86_64 + target: x86_64-pc-windows-msvc + + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + default: true + + - name: Build binary + run: cargo build --release --target ${{ matrix.target }} + + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + with: + name: py-init-cleaner-${{ matrix.target }} + path: target/${{ matrix.target }}/release/py-init-cleaner + + release: + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Download all artifacts + uses: actions/download-artifact@v2 + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload Release Asset + run: | + for filename in py-init-cleaner-*; do + echo "Uploading $filename" + asset_path="./$filename" + asset_name="$filename" + asset_content_type="application/octet-stream" + curl \ + -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: $asset_content_type" \ + -H "Accept: application/vnd.github.v3+json" \ + --data-binary @$asset_path \ + "${{ steps.create_release.outputs.upload_url }}?name=$(urlencode $asset_name)" + done + shell: bash diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f757c92..3d8dc10 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,7 @@ -- id: py-init-cleaner - name: Python Init Cleaner - description: Pre-commit hook to clean your python __init__.py files automatically - entry: py-init-cleaner - language: script - types: [python] - files: __init__\.py$ +- id: py-init-cleaner + name: Python __init__.py Cleaner + description: Pre-commit hook to clean up __init__.py files automatically. + entry: scripts/bootstrap.sh + language: script + types: [python] + files: __init__\.py$ diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..af47185 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Define the base URL for the GitHub releases +REPO_URL="https://github.com/chainyo/py-init-cleaner/releases/latest/download" + +# Determine platform details +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +if [[ "$ARCH" == "x86_64" ]]; then + ARCH="x86_64" +elif [[ "$ARCH" == "aarch64" ]]; then + ARCH="ARM64" +else + echo "Unsupported architecture: $ARCH" + exit 1 +fi + +# Construct the binary name and URL +BINARY_NAME="py-init-cleaner-${OS}-${ARCH}" +DOWNLOAD_URL="$REPO_URL/$BINARY_NAME" + +# Download the binary +curl -L $DOWNLOAD_URL -o $BINARY_NAME + +# Make the binary executable +chmod +x $BINARY_NAME + +# Execute the binary +./$BINARY_NAME "$@"