|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_tag: |
| 7 | + description: 'Release tag (e.g., v0.1.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + pull_request: |
| 11 | + |
| 12 | +# Ensure only one release workflow runs at a time |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-bundle: |
| 19 | + name: Build and Bundle Platform |
| 20 | + runs-on: macos-15 # macOS can cross-compile to all targets |
| 21 | + outputs: |
| 22 | + bundle_filename: ${{ steps.bundle.outputs.bundle_filename }} |
| 23 | + defaults: |
| 24 | + run: |
| 25 | + shell: bash |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Install Zig |
| 32 | + uses: mlugg/setup-zig@v2 |
| 33 | + with: |
| 34 | + version: 0.15.2 |
| 35 | + |
| 36 | + - name: Install Rust with cross-compilation targets |
| 37 | + uses: dtolnay/rust-toolchain@stable |
| 38 | + with: |
| 39 | + targets: x86_64-apple-darwin,aarch64-apple-darwin,x86_64-unknown-linux-musl,aarch64-unknown-linux-musl |
| 40 | + |
| 41 | + - name: Build Roc from pinned commit |
| 42 | + run: | |
| 43 | + echo "Building roc from pinned commit..." |
| 44 | + ROC_COMMIT=$(python3 ci/get_roc_commit.py) |
| 45 | +
|
| 46 | + git init roc-src |
| 47 | + cd roc-src |
| 48 | + git remote add origin https://github.com/roc-lang/roc |
| 49 | + git fetch --depth 1 origin "$ROC_COMMIT" |
| 50 | + git checkout --detach "$ROC_COMMIT" |
| 51 | +
|
| 52 | + zig build roc |
| 53 | +
|
| 54 | + echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH" |
| 55 | +
|
| 56 | + - name: Build platform for all targets |
| 57 | + run: ./build.sh --all |
| 58 | + |
| 59 | + - name: Bundle platform |
| 60 | + id: bundle |
| 61 | + run: | |
| 62 | + # Run bundle.sh and capture output |
| 63 | + BUNDLE_OUTPUT=$(./bundle.sh 2>&1) |
| 64 | + echo "$BUNDLE_OUTPUT" |
| 65 | +
|
| 66 | + # Extract the tar.zst filename from "Created: /path/to/HASH.tar.zst" line |
| 67 | + BUNDLE_PATH=$(echo "$BUNDLE_OUTPUT" | grep "^Created:" | awk '{print $2}') |
| 68 | + BUNDLE_FILENAME=$(basename "$BUNDLE_PATH") |
| 69 | +
|
| 70 | + if [ -z "$BUNDLE_FILENAME" ]; then |
| 71 | + echo "Error: Could not extract bundle filename from output" |
| 72 | + echo "Bundle output was:" |
| 73 | + echo "$BUNDLE_OUTPUT" |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +
|
| 77 | + echo "Bundle created: $BUNDLE_FILENAME" |
| 78 | + echo "bundle_filename=$BUNDLE_FILENAME" >> "$GITHUB_OUTPUT" |
| 79 | +
|
| 80 | + - name: Upload bundle artifact |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: platform-bundle |
| 84 | + path: ${{ steps.bundle.outputs.bundle_filename }} |
| 85 | + retention-days: 30 |
| 86 | + |
| 87 | + test-bundle: |
| 88 | + name: Test Bundle (${{ matrix.os }}) |
| 89 | + needs: build-and-bundle |
| 90 | + strategy: |
| 91 | + fail-fast: false |
| 92 | + matrix: |
| 93 | + os: |
| 94 | + - macos-15 # Apple Silicon |
| 95 | + - macos-15-intel # Intel Mac |
| 96 | + - ubuntu-22.04 # Linux x86_64 |
| 97 | + - ubuntu-24.04-arm # Linux ARM64 |
| 98 | + runs-on: ${{ matrix.os }} |
| 99 | + defaults: |
| 100 | + run: |
| 101 | + shell: bash |
| 102 | + |
| 103 | + steps: |
| 104 | + - name: Checkout |
| 105 | + uses: actions/checkout@v4 |
| 106 | + |
| 107 | + - name: Install Zig |
| 108 | + uses: mlugg/setup-zig@v2 |
| 109 | + with: |
| 110 | + version: 0.15.2 |
| 111 | + |
| 112 | + - name: Install Rust |
| 113 | + uses: dtolnay/rust-toolchain@stable |
| 114 | + |
| 115 | + - name: Install expect (Ubuntu) |
| 116 | + if: startsWith(matrix.os, 'ubuntu-') |
| 117 | + run: sudo apt-get install -y expect |
| 118 | + |
| 119 | + - name: Install expect (macOS) |
| 120 | + if: startsWith(matrix.os, 'macos-') |
| 121 | + run: brew install expect |
| 122 | + |
| 123 | + - name: Build Roc from pinned commit |
| 124 | + run: | |
| 125 | + echo "Building roc from pinned commit..." |
| 126 | + ROC_COMMIT=$(python3 ci/get_roc_commit.py) |
| 127 | +
|
| 128 | + git init roc-src |
| 129 | + cd roc-src |
| 130 | + git remote add origin https://github.com/roc-lang/roc |
| 131 | + git fetch --depth 1 origin "$ROC_COMMIT" |
| 132 | + git checkout --detach "$ROC_COMMIT" |
| 133 | +
|
| 134 | + zig build roc |
| 135 | +
|
| 136 | + echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH" |
| 137 | +
|
| 138 | + - name: Download bundle artifact |
| 139 | + uses: actions/download-artifact@v4 |
| 140 | + with: |
| 141 | + name: platform-bundle |
| 142 | + |
| 143 | + - name: Start HTTP server for bundle |
| 144 | + run: | |
| 145 | + # Start Python HTTP server in background on port 8000 |
| 146 | + python3 -m http.server 8000 & |
| 147 | + HTTP_SERVER_PID=$! |
| 148 | + echo "HTTP_SERVER_PID=$HTTP_SERVER_PID" >> "$GITHUB_ENV" |
| 149 | +
|
| 150 | + # Wait for server to start |
| 151 | + sleep 5 |
| 152 | +
|
| 153 | + # Verify server is running and bundle is accessible |
| 154 | + if ! curl -f -I "http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}" > /dev/null 2>&1; then |
| 155 | + echo "Error: HTTP server not accessible or bundle not found" |
| 156 | + kill $HTTP_SERVER_PID || true |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | +
|
| 160 | + echo "HTTP server started on port 8000 (PID: $HTTP_SERVER_PID)" |
| 161 | + echo "Bundle accessible at: http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}" |
| 162 | +
|
| 163 | + - name: Modify examples to use bundled platform |
| 164 | + run: | |
| 165 | + # Replace local platform path with HTTP URL in all examples |
| 166 | + for example in examples/*.roc; do |
| 167 | + sed -i.bak "s|platform \"../platform/main.roc\"|platform \"http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}\"|g" "$example" |
| 168 | + done |
| 169 | +
|
| 170 | + # Show diff for verification |
| 171 | + echo "Modified examples:" |
| 172 | + git diff examples/ | head -50 |
| 173 | +
|
| 174 | + - name: Run tests with bundled platform |
| 175 | + run: | |
| 176 | + # Skip native build since we're using the bundle |
| 177 | + # The test script will detect all targets exist and use bundle testing |
| 178 | + export NO_BUILD=1 |
| 179 | +
|
| 180 | + # Run all tests against the bundled platform |
| 181 | + bash ci/all_tests.sh |
| 182 | +
|
| 183 | + create-release: |
| 184 | + name: Create GitHub Release |
| 185 | + needs: [build-and-bundle, test-bundle] |
| 186 | + runs-on: ubuntu-24.04 |
| 187 | + # Only run on manual trigger |
| 188 | + if: github.event_name == 'workflow_dispatch' |
| 189 | + permissions: |
| 190 | + contents: write |
| 191 | + |
| 192 | + steps: |
| 193 | + - name: Checkout |
| 194 | + uses: actions/checkout@v4 |
| 195 | + |
| 196 | + - name: Download bundle artifact |
| 197 | + uses: actions/download-artifact@v4 |
| 198 | + with: |
| 199 | + name: platform-bundle |
| 200 | + |
| 201 | + - name: Create GitHub Release |
| 202 | + env: |
| 203 | + GH_TOKEN: ${{ github.token }} |
| 204 | + run: | |
| 205 | + BUNDLE_FILE=$(ls *.tar.zst | head -1) |
| 206 | +
|
| 207 | + if [ -z "$BUNDLE_FILE" ]; then |
| 208 | + echo "Error: No bundle file found" |
| 209 | + exit 1 |
| 210 | + fi |
| 211 | +
|
| 212 | + ROC_COMMIT=$(python3 ci/get_roc_commit.py | cut -c1-8) |
| 213 | +
|
| 214 | + # Create release with auto-generated notes |
| 215 | + gh release create "${{ github.event.inputs.release_tag }}" \ |
| 216 | + "$BUNDLE_FILE" \ |
| 217 | + --title "${{ github.event.inputs.release_tag }}" \ |
| 218 | + --generate-notes \ |
| 219 | + --notes "Platform bundle built with Rust (stable) and Roc $ROC_COMMIT" |
| 220 | +
|
| 221 | + echo "Release created: ${{ github.event.inputs.release_tag }}" |
| 222 | + echo "Bundle uploaded: $BUNDLE_FILE" |
0 commit comments