|
| 1 | +name: Build Release Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + macos: |
| 9 | + name: Build macOS binary |
| 10 | + runs-on: macos-15 |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Build macOS binary |
| 16 | + run: swift build -c release --arch arm64 --arch x86_64 -Xswiftc -Osize |
| 17 | + |
| 18 | + - name: Strip macOS binary |
| 19 | + run: strip -rSTx .build/apple/Products/Release/subtree |
| 20 | + |
| 21 | + - name: Test binary functionality |
| 22 | + run: | |
| 23 | + .build/apple/Products/Release/subtree --help |
| 24 | + echo "✅ macOS binary responds to --help" |
| 25 | + |
| 26 | + - name: Upload artifacts |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: subtree_macos |
| 30 | + path: .build/apple/Products/Release/subtree |
| 31 | + retention-days: 5 |
| 32 | + |
| 33 | + linux: |
| 34 | + name: Build Linux binaries |
| 35 | + runs-on: ubuntu-20.04 |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Set up Docker Buildx |
| 41 | + uses: docker/setup-buildx-action@v3 |
| 42 | + |
| 43 | + - name: Install cross-binutils for aarch64 |
| 44 | + run: sudo apt install -y binutils-aarch64-linux-gnu |
| 45 | + |
| 46 | + - name: Build and export binaries |
| 47 | + uses: docker/build-push-action@v5 |
| 48 | + with: |
| 49 | + context: . |
| 50 | + platforms: linux/amd64,linux/arm64 |
| 51 | + target: output |
| 52 | + outputs: type=local,dest=artifacts |
| 53 | + |
| 54 | + - name: Test and organize binaries |
| 55 | + run: | |
| 56 | + # Test that binaries were built successfully |
| 57 | + echo "✅ Linux AMD64 binary built: $(file artifacts/linux_amd64/subtree)" |
| 58 | + echo "✅ Linux ARM64 binary built: $(file artifacts/linux_arm64/subtree)" |
| 59 | + |
| 60 | + # Strip and organize AMD64 binary |
| 61 | + strip artifacts/linux_amd64/subtree |
| 62 | + mv artifacts/linux_amd64/subtree "${HOME}/subtree_linux" |
| 63 | + |
| 64 | + # Strip and organize ARM64 binary |
| 65 | + aarch64-linux-gnu-strip artifacts/linux_arm64/subtree |
| 66 | + mv artifacts/linux_arm64/subtree "${HOME}/subtree_linux_aarch64" |
| 67 | + |
| 68 | + - name: Upload AMD64 Artifact |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: subtree_linux |
| 72 | + path: ~/subtree_linux |
| 73 | + retention-days: 5 |
| 74 | + |
| 75 | + - name: Upload ARM64 Artifact |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: subtree_linux_aarch64 |
| 79 | + path: ~/subtree_linux_aarch64 |
| 80 | + retention-days: 5 |
| 81 | + |
| 82 | + upload: |
| 83 | + name: Upload release artifacts |
| 84 | + runs-on: ubuntu-20.04 |
| 85 | + needs: [macos, linux] |
| 86 | + steps: |
| 87 | + - name: Checkout the repository |
| 88 | + uses: actions/checkout@v4 |
| 89 | + |
| 90 | + - name: Download artifacts |
| 91 | + uses: actions/download-artifact@v4 |
| 92 | + with: |
| 93 | + path: downloaded_artifacts |
| 94 | + |
| 95 | + - name: Display structure of downloaded files |
| 96 | + run: ls -R downloaded_artifacts |
| 97 | + |
| 98 | + - name: Prepare release binaries |
| 99 | + run: | |
| 100 | + VERSION="${{ github.event.release.tag_name }}" |
| 101 | + |
| 102 | + # Copy and rename binaries for release upload |
| 103 | + cp downloaded_artifacts/subtree_macos/subtree "subtree_${VERSION}_macos" |
| 104 | + cp downloaded_artifacts/subtree_linux/subtree_linux "subtree_${VERSION}_linux_x86_64" |
| 105 | + cp downloaded_artifacts/subtree_linux_aarch64/subtree_linux_aarch64 "subtree_${VERSION}_linux_arm64" |
| 106 | + |
| 107 | + # Make all binaries executable |
| 108 | + chmod +x subtree_${VERSION}_* |
| 109 | + |
| 110 | + - name: Build artifact bundle |
| 111 | + run: | |
| 112 | + VERSION="${{ github.event.release.tag_name }}" |
| 113 | + BUNDLE_DIR="subtree.artifactbundle" |
| 114 | + |
| 115 | + mkdir -p "${BUNDLE_DIR}" |
| 116 | + |
| 117 | + # Organize binaries by platform (universal macOS binary) |
| 118 | + mkdir -p "${BUNDLE_DIR}/macos" |
| 119 | + mkdir -p "${BUNDLE_DIR}/linux-x86_64" |
| 120 | + mkdir -p "${BUNDLE_DIR}/linux-arm64" |
| 121 | + |
| 122 | + # Copy binaries to bundle structure |
| 123 | + cp downloaded_artifacts/subtree_macos/subtree "${BUNDLE_DIR}/macos/subtree" |
| 124 | + cp downloaded_artifacts/subtree_linux/subtree_linux "${BUNDLE_DIR}/linux-x86_64/subtree" |
| 125 | + cp downloaded_artifacts/subtree_linux_aarch64/subtree_linux_aarch64 "${BUNDLE_DIR}/linux-arm64/subtree" |
| 126 | + |
| 127 | + # Create artifact bundle manifest |
| 128 | + cat > "${BUNDLE_DIR}/artifactbundle.json" << EOF |
| 129 | + { |
| 130 | + "schemaVersion": "1.0", |
| 131 | + "artifacts": { |
| 132 | + "subtree": { |
| 133 | + "version": "${VERSION}", |
| 134 | + "type": "executable", |
| 135 | + "variants": [ |
| 136 | + { |
| 137 | + "path": "macos/subtree", |
| 138 | + "supportedTriples": ["arm64-apple-macosx", "x86_64-apple-macosx"] |
| 139 | + }, |
| 140 | + { |
| 141 | + "path": "linux-x86_64/subtree", |
| 142 | + "supportedTriples": ["x86_64-unknown-linux-gnu"] |
| 143 | + }, |
| 144 | + { |
| 145 | + "path": "linux-arm64/subtree", |
| 146 | + "supportedTriples": ["aarch64-unknown-linux-gnu"] |
| 147 | + } |
| 148 | + ] |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + EOF |
| 153 | + |
| 154 | + # Create zip archive |
| 155 | + zip -r "subtree.artifactbundle.zip" "${BUNDLE_DIR}" |
| 156 | + |
| 157 | + - name: Upload release binaries |
| 158 | + uses: skx/github-action-publish-binaries@master |
| 159 | + env: |
| 160 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + with: |
| 162 | + args: 'subtree_${{ github.event.release.tag_name }}_macos subtree_${{ github.event.release.tag_name }}_linux_x86_64 subtree_${{ github.event.release.tag_name }}_linux_arm64 subtree.artifactbundle.zip' |
0 commit comments