Skip to content

Commit

Permalink
update build actions and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chainyo committed Apr 20, 2024
1 parent c01788e commit 308e8b0
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 7 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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$
29 changes: 29 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 308e8b0

Please sign in to comment.