|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +env: |
| 15 | + CARGO_TERM_COLOR: always |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + name: Build for ${{ matrix.target }} |
| 20 | + runs-on: ${{ matrix.os }} |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + # Linux x86_64 |
| 26 | + - target: x86_64-unknown-linux-gnu |
| 27 | + os: ubuntu-latest |
| 28 | + asset_name: aimit-linux-x86_64 |
| 29 | + # # Linux ARM64 |
| 30 | + # - target: aarch64-unknown-linux-gnu |
| 31 | + # os: ubuntu-latest |
| 32 | + # asset_name: aimit-linux-aarch64 |
| 33 | + # macOS x86_64 (Intel) |
| 34 | + - target: x86_64-apple-darwin |
| 35 | + os: macos-latest |
| 36 | + asset_name: aimit-macos-x86_64 |
| 37 | + # macOS ARM64 (Apple Silicon) |
| 38 | + - target: aarch64-apple-darwin |
| 39 | + os: macos-latest |
| 40 | + asset_name: aimit-macos-aarch64 |
| 41 | + # Windows x86_64 |
| 42 | + - target: x86_64-pc-windows-msvc |
| 43 | + os: windows-latest |
| 44 | + asset_name: aimit-windows-x86_64.exe |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Install Rust |
| 51 | + uses: dtolnay/rust-toolchain@stable |
| 52 | + with: |
| 53 | + targets: ${{ matrix.target }} |
| 54 | + |
| 55 | + - name: Cache cargo registry |
| 56 | + uses: actions/cache@v4 |
| 57 | + with: |
| 58 | + path: | |
| 59 | + ~/.cargo/registry |
| 60 | + ~/.cargo/git |
| 61 | + target |
| 62 | + key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} |
| 63 | + restore-keys: | |
| 64 | + ${{ runner.os }}-cargo-${{ matrix.target }}- |
| 65 | +
|
| 66 | + - name: Build |
| 67 | + run: cargo build --release --target ${{ matrix.target }} |
| 68 | + |
| 69 | + - name: Upload artifact |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: ${{ matrix.asset_name }} |
| 73 | + path: target/${{ matrix.target }}/release/aimit${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }} |
| 74 | + |
| 75 | + release: |
| 76 | + name: Create Release |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: build |
| 79 | + if: github.event_name == 'release' |
| 80 | + steps: |
| 81 | + - name: Download all artifacts |
| 82 | + uses: actions/download-artifact@v4 |
| 83 | + |
| 84 | + - name: Create release archive |
| 85 | + run: | |
| 86 | + mkdir -p release-binaries |
| 87 | + for artifact_dir in */; do |
| 88 | + artifact_name=$(basename "$artifact_dir") |
| 89 | + echo "Processing artifact: $artifact_name" |
| 90 | + if [[ "$artifact_name" == *"windows"* ]]; then |
| 91 | + # Find the .exe file and copy it with a unique name |
| 92 | + exe_file=$(find "$artifact_dir" -name "*.exe" -type f | head -1) |
| 93 | + if [[ -n "$exe_file" ]]; then |
| 94 | + cp "$exe_file" "release-binaries/$artifact_name.exe" |
| 95 | + echo "Copied Windows binary: $exe_file -> release-binaries/$artifact_name.exe" |
| 96 | + fi |
| 97 | + else |
| 98 | + # Find the binary file and copy it with a unique name |
| 99 | + binary_file=$(find "$artifact_dir" -type f -executable | head -1) |
| 100 | + if [[ -n "$binary_file" ]]; then |
| 101 | + cp "$binary_file" "release-binaries/$artifact_name" |
| 102 | + echo "Copied binary: $binary_file -> release-binaries/$artifact_name" |
| 103 | + fi |
| 104 | + fi |
| 105 | + done |
| 106 | +
|
| 107 | + # List what we have |
| 108 | + echo "Files in release-binaries:" |
| 109 | + ls -la release-binaries/ |
| 110 | +
|
| 111 | + # Create a zip file with all binaries |
| 112 | + cd release-binaries |
| 113 | + zip -r ../aimit-binaries.zip . |
| 114 | + cd .. |
| 115 | +
|
| 116 | + - name: Upload release assets |
| 117 | + uses: actions/upload-release-asset@v1 |
| 118 | + env: |
| 119 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + with: |
| 121 | + upload_url: ${{ github.event.release.upload_url }} |
| 122 | + asset_path: ./aimit-binaries.zip |
| 123 | + asset_name: aimit-binaries.zip |
| 124 | + asset_content_type: application/zip |
| 125 | + |
| 126 | + update-binaries: |
| 127 | + name: Update Binary Files |
| 128 | + runs-on: ubuntu-latest |
| 129 | + needs: build |
| 130 | + if: github.ref == 'refs/heads/main' |
| 131 | + steps: |
| 132 | + - name: Checkout code |
| 133 | + uses: actions/checkout@v4 |
| 134 | + with: |
| 135 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + |
| 137 | + - name: Download all artifacts |
| 138 | + uses: actions/download-artifact@v4 |
| 139 | + |
| 140 | + - name: Prepare binaries for bin directory |
| 141 | + run: | |
| 142 | + mkdir -p bin |
| 143 | + for artifact_dir in */; do |
| 144 | + artifact_name=$(basename "$artifact_dir") |
| 145 | + echo "Processing artifact: $artifact_name" |
| 146 | + |
| 147 | + # Skip the bin directory itself |
| 148 | + if [[ "$artifact_name" == "bin" ]]; then |
| 149 | + echo "Skipping bin directory" |
| 150 | + continue |
| 151 | + fi |
| 152 | + |
| 153 | + if [[ "$artifact_name" == *"windows"* ]]; then |
| 154 | + # Find the .exe file and copy it |
| 155 | + exe_file=$(find "$artifact_dir" -name "*.exe" -type f | head -1) |
| 156 | + if [[ -n "$exe_file" ]]; then |
| 157 | + cp "$exe_file" "bin/aimit.exe" |
| 158 | + echo "Copied Windows binary: $exe_file -> bin/aimit.exe" |
| 159 | + fi |
| 160 | + else |
| 161 | + # Find the binary file and copy it |
| 162 | + binary_file=$(find "$artifact_dir" -type f -executable | head -1) |
| 163 | + if [[ -n "$binary_file" ]]; then |
| 164 | + cp "$binary_file" "bin/aimit" |
| 165 | + echo "Copied binary: $binary_file -> bin/aimit" |
| 166 | + fi |
| 167 | + fi |
| 168 | + done |
| 169 | +
|
| 170 | + # List what we have |
| 171 | + echo "Files in bin directory:" |
| 172 | + ls -la bin/ |
| 173 | +
|
| 174 | + - name: Commit and push binaries |
| 175 | + run: | |
| 176 | + git config --local user.email "action@github.com" |
| 177 | + git config --local user.name "GitHub Action" |
| 178 | + git add bin/ |
| 179 | + if git diff --staged --quiet; then |
| 180 | + echo "No changes to commit" |
| 181 | + else |
| 182 | + git commit -m "Update binaries for release ${{ github.sha }}" |
| 183 | + git push |
| 184 | + fi |
0 commit comments