|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' # Trigger on tags like v0.1.0, v1.2.3 |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # Needed to create releases and upload assets |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + BINARY_NAME: strux |
| 14 | + STAGING_DIR: staging |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-release: |
| 18 | + name: Build Release Binaries (${{ matrix.target }}) |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + # Linux (GNU) - tar.gz archive |
| 24 | + - os: ubuntu-latest |
| 25 | + target: x86_64-unknown-linux-gnu |
| 26 | + bin_suffix: "" |
| 27 | + archive_format: tar.gz |
| 28 | + archive_command: | |
| 29 | + tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} . |
| 30 | + archive_shell: bash |
| 31 | + |
| 32 | + # macOS (Intel x86_64) - tar.gz archive |
| 33 | + - os: macos-latest |
| 34 | + target: x86_64-apple-darwin |
| 35 | + bin_suffix: "" |
| 36 | + archive_format: tar.gz |
| 37 | + archive_command: | |
| 38 | + tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} . |
| 39 | + archive_shell: bash |
| 40 | + |
| 41 | + # macOS (Apple Silicon arm64) - tar.gz archive |
| 42 | + - os: macos-14 |
| 43 | + target: aarch64-apple-darwin |
| 44 | + bin_suffix: "" |
| 45 | + archive_format: tar.gz |
| 46 | + archive_command: | |
| 47 | + tar czf ${{ env.ARCHIVE_NAME }} -C ${{ env.STAGING_DIR }} . |
| 48 | + archive_shell: bash |
| 49 | + |
| 50 | + # Windows (MSVC x86_64) - zip archive |
| 51 | + - os: windows-latest |
| 52 | + target: x86_64-pc-windows-msvc |
| 53 | + bin_suffix: ".exe" |
| 54 | + archive_format: zip |
| 55 | + archive_command: | |
| 56 | + Compress-Archive -Path ${{ env.STAGING_DIR }}\* -DestinationPath ${{ env.ARCHIVE_NAME }} |
| 57 | + archive_shell: pwsh |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout repository |
| 61 | + uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Install Rust toolchain (stable) |
| 64 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 65 | + with: |
| 66 | + toolchain: stable |
| 67 | + target: ${{ matrix.target }} |
| 68 | + cache: 'cargo' |
| 69 | + |
| 70 | + - name: Build release binary |
| 71 | + run: cargo build --release --target ${{ matrix.target }} --verbose |
| 72 | + |
| 73 | + - name: Prepare archive name |
| 74 | + run: echo "ARCHIVE_NAME=${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive_format }}" >> $GITHUB_ENV |
| 75 | + shell: bash |
| 76 | + |
| 77 | + - name: Create staging directory |
| 78 | + run: mkdir ${{ env.STAGING_DIR }} |
| 79 | + shell: bash |
| 80 | + |
| 81 | + - name: Copy binary to staging directory |
| 82 | + run: | |
| 83 | + set -e |
| 84 | + cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.bin_suffix }} ${{ env.STAGING_DIR }}/ |
| 85 | + shell: bash |
| 86 | + |
| 87 | + - name: Copy documentation and license files to staging directory |
| 88 | + # Copy only LICENSE and README.md, not COMMIT.md |
| 89 | + run: | |
| 90 | + set -e |
| 91 | + cp LICENSE ${{ env.STAGING_DIR }}/ |
| 92 | + cp README.md ${{ env.STAGING_DIR }}/ |
| 93 | + shell: bash |
| 94 | + |
| 95 | + - name: List staging directory contents (for debugging) |
| 96 | + run: ls -R ${{ env.STAGING_DIR }} |
| 97 | + shell: bash |
| 98 | + |
| 99 | + - name: Package release artifacts from staging directory |
| 100 | + run: ${{ matrix.archive_command }} |
| 101 | + shell: ${{ matrix.archive_shell }} |
| 102 | + |
| 103 | + - name: Upload release asset |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: release-assets |
| 107 | + path: ${{ env.ARCHIVE_NAME }} |
| 108 | + |
| 109 | + create-release: |
| 110 | + name: Create GitHub Release |
| 111 | + needs: build-release |
| 112 | + runs-on: ubuntu-latest |
| 113 | + |
| 114 | + steps: |
| 115 | + - name: Download all release assets |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: release-assets |
| 119 | + path: release-assets |
| 120 | + |
| 121 | + - name: List downloaded files (for debugging) |
| 122 | + run: ls -R release-assets |
| 123 | + |
| 124 | + - name: Create Release and Upload Assets |
| 125 | + uses: softprops/action-gh-release@v2 |
| 126 | + with: |
| 127 | + tag_name: ${{ github.ref_name }} |
| 128 | + name: Release ${{ github.ref_name }} |
| 129 | + generate_release_notes: true |
| 130 | + files: release-assets/* |
| 131 | + env: |
| 132 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments