|
| 1 | +name: Build Photon |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + paths: |
| 7 | + - 'photon/**' |
| 8 | + - '.github/workflows/build-photon.yml' |
| 9 | + pull_request: |
| 10 | + branches: [ main ] |
| 11 | + paths: |
| 12 | + - 'photon/**' |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +env: |
| 16 | + CARGO_TERM_COLOR: always |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build Photon - ${{ matrix.os }} |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - os: ubuntu-latest |
| 26 | + target: x86_64-unknown-linux-gnu |
| 27 | + artifact_name: photon |
| 28 | + asset_name: photon-linux-x86_64 |
| 29 | + - os: windows-latest |
| 30 | + target: x86_64-pc-windows-msvc |
| 31 | + artifact_name: photon.exe |
| 32 | + asset_name: photon-windows-x86_64.exe |
| 33 | + - os: macos-latest |
| 34 | + target: x86_64-apple-darwin |
| 35 | + artifact_name: photon |
| 36 | + asset_name: photon-macos-x86_64 |
| 37 | + - os: macos-latest |
| 38 | + target: aarch64-apple-darwin |
| 39 | + artifact_name: photon |
| 40 | + asset_name: photon-macos-aarch64 |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout repository |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Setup Rust toolchain |
| 47 | + uses: dtolnay/rust-toolchain@stable |
| 48 | + with: |
| 49 | + targets: ${{ matrix.target }} |
| 50 | + |
| 51 | + - name: Cache cargo registry |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: ~/.cargo/registry |
| 55 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 56 | + |
| 57 | + - name: Cache cargo index |
| 58 | + uses: actions/cache@v4 |
| 59 | + with: |
| 60 | + path: ~/.cargo/git |
| 61 | + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
| 62 | + |
| 63 | + - name: Cache cargo build |
| 64 | + uses: actions/cache@v4 |
| 65 | + with: |
| 66 | + path: photon/target |
| 67 | + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} |
| 68 | + |
| 69 | + - name: Build Photon |
| 70 | + working-directory: photon |
| 71 | + run: cargo build --release --target ${{ matrix.target }} |
| 72 | + |
| 73 | + - name: Run tests |
| 74 | + working-directory: photon |
| 75 | + run: cargo test --release --target ${{ matrix.target }} |
| 76 | + |
| 77 | + - name: Strip binary (Linux and macOS) |
| 78 | + if: matrix.os != 'windows-latest' |
| 79 | + working-directory: photon |
| 80 | + run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} |
| 81 | + |
| 82 | + - name: Rename binary |
| 83 | + working-directory: photon |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + mkdir -p artifacts |
| 87 | + cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} artifacts/${{ matrix.asset_name }} |
| 88 | +
|
| 89 | + - name: Upload artifact |
| 90 | + uses: actions/upload-artifact@v4 |
| 91 | + with: |
| 92 | + name: ${{ matrix.asset_name }} |
| 93 | + path: photon/artifacts/${{ matrix.asset_name }} |
| 94 | + if-no-files-found: error |
| 95 | + |
| 96 | + build-info: |
| 97 | + name: Build Information |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: build |
| 100 | + steps: |
| 101 | + - name: Checkout repository |
| 102 | + uses: actions/checkout@v4 |
| 103 | + |
| 104 | + - name: Get Photon version |
| 105 | + id: version |
| 106 | + working-directory: photon |
| 107 | + run: | |
| 108 | + VERSION=$(grep '^version = ' Cargo.toml | head -1 | cut -d'"' -f2) |
| 109 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 110 | + echo "Photon version: $VERSION" |
| 111 | +
|
| 112 | + - name: Create build info |
| 113 | + run: | |
| 114 | + cat > build-info.txt << EOF |
| 115 | + Photon Build Information |
| 116 | + ======================== |
| 117 | + Version: ${{ steps.version.outputs.version }} |
| 118 | + Commit: ${{ github.sha }} |
| 119 | + Branch: ${{ github.ref_name }} |
| 120 | + Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 121 | + Workflow: ${{ github.workflow }} |
| 122 | + Run Number: ${{ github.run_number }} |
| 123 | + |
| 124 | + Available Artifacts: |
| 125 | + - photon-linux-x86_64 (Linux x86_64) |
| 126 | + - photon-windows-x86_64.exe (Windows x86_64) |
| 127 | + - photon-macos-x86_64 (macOS Intel) |
| 128 | + - photon-macos-aarch64 (macOS Apple Silicon) |
| 129 | + |
| 130 | + Repository: ${{ github.repository }} |
| 131 | + Actor: ${{ github.actor }} |
| 132 | + EOF |
| 133 | + cat build-info.txt |
| 134 | +
|
| 135 | + - name: Upload build info |
| 136 | + uses: actions/upload-artifact@v4 |
| 137 | + with: |
| 138 | + name: build-info |
| 139 | + path: build-info.txt |
| 140 | + |
| 141 | + create-release-archive: |
| 142 | + name: Create Release Archive |
| 143 | + runs-on: ubuntu-latest |
| 144 | + needs: build |
| 145 | + steps: |
| 146 | + - name: Download all artifacts |
| 147 | + uses: actions/download-artifact@v4 |
| 148 | + with: |
| 149 | + path: artifacts |
| 150 | + |
| 151 | + - name: Display structure |
| 152 | + run: ls -R artifacts |
| 153 | + |
| 154 | + - name: Create combined archive |
| 155 | + run: | |
| 156 | + cd artifacts |
| 157 | + # Move binaries to root level |
| 158 | + find . -type f -name "photon*" -exec mv {} . \; |
| 159 | + # Remove empty directories |
| 160 | + find . -type d -empty -delete |
| 161 | + # Create archive |
| 162 | + tar -czf photon-all-platforms.tar.gz photon-* |
| 163 | + zip -r photon-all-platforms.zip photon-* |
| 164 | +
|
| 165 | + - name: Upload combined archive (tar.gz) |
| 166 | + uses: actions/upload-artifact@v4 |
| 167 | + with: |
| 168 | + name: photon-all-platforms-tar |
| 169 | + path: artifacts/photon-all-platforms.tar.gz |
| 170 | + |
| 171 | + - name: Upload combined archive (zip) |
| 172 | + uses: actions/upload-artifact@v4 |
| 173 | + with: |
| 174 | + name: photon-all-platforms-zip |
| 175 | + path: artifacts/photon-all-platforms.zip |
0 commit comments