action.yml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: "Setup Bun"
  2. description: "Setup Bun with caching and install dependencies"
  3. inputs:
  4. cross-compile:
  5. description: "Pre-cache canary cross-compile binaries for all targets"
  6. required: false
  7. default: "false"
  8. runs:
  9. using: "composite"
  10. steps:
  11. - name: Cache Bun dependencies
  12. uses: actions/cache@v4
  13. with:
  14. path: ~/.bun/install/cache
  15. key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
  16. restore-keys: |
  17. ${{ runner.os }}-bun-
  18. - name: Get baseline download URL
  19. id: bun-url
  20. shell: bash
  21. run: |
  22. if [ "$RUNNER_ARCH" = "X64" ]; then
  23. case "$RUNNER_OS" in
  24. macOS) OS=darwin ;;
  25. Linux) OS=linux ;;
  26. Windows) OS=windows ;;
  27. esac
  28. echo "url=https://github.com/oven-sh/bun/releases/download/canary/bun-${OS}-x64-baseline.zip" >> "$GITHUB_OUTPUT"
  29. fi
  30. - name: Setup Bun
  31. uses: oven-sh/setup-bun@v2
  32. with:
  33. bun-version-file: ${{ !steps.bun-url.outputs.url && 'package.json' || '' }}
  34. bun-download-url: ${{ steps.bun-url.outputs.url }}
  35. - name: Pre-cache canary cross-compile binaries
  36. if: inputs.cross-compile == 'true'
  37. shell: bash
  38. run: |
  39. BUN_VERSION=$(bun --revision)
  40. if echo "$BUN_VERSION" | grep -q "canary"; then
  41. SEMVER=$(echo "$BUN_VERSION" | sed 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/')
  42. echo "Bun version: $BUN_VERSION (semver: $SEMVER)"
  43. CACHE_DIR="$HOME/.bun/install/cache"
  44. mkdir -p "$CACHE_DIR"
  45. TMP_DIR=$(mktemp -d)
  46. for TARGET in linux-aarch64 linux-x64 linux-x64-baseline linux-aarch64-musl linux-x64-musl linux-x64-musl-baseline darwin-aarch64 darwin-x64 windows-x64 windows-x64-baseline; do
  47. DEST="$CACHE_DIR/bun-${TARGET}-v${SEMVER}"
  48. if [ -f "$DEST" ]; then
  49. echo "Already cached: $DEST"
  50. continue
  51. fi
  52. URL="https://github.com/oven-sh/bun/releases/download/canary/bun-${TARGET}.zip"
  53. echo "Downloading $TARGET from $URL"
  54. if curl -sfL -o "$TMP_DIR/bun.zip" "$URL"; then
  55. unzip -qo "$TMP_DIR/bun.zip" -d "$TMP_DIR"
  56. if echo "$TARGET" | grep -q "windows"; then
  57. BIN_NAME="bun.exe"
  58. else
  59. BIN_NAME="bun"
  60. fi
  61. mv "$TMP_DIR/bun-${TARGET}/$BIN_NAME" "$DEST"
  62. chmod +x "$DEST"
  63. rm -rf "$TMP_DIR/bun-${TARGET}" "$TMP_DIR/bun.zip"
  64. echo "Cached: $DEST"
  65. # baseline bun resolves "bun-darwin-x64" to the baseline cache key
  66. # so copy the modern binary there too
  67. if [ "$TARGET" = "darwin-x64" ]; then
  68. BASELINE_DEST="$CACHE_DIR/bun-darwin-x64-baseline-v${SEMVER}"
  69. if [ ! -f "$BASELINE_DEST" ]; then
  70. cp "$DEST" "$BASELINE_DEST"
  71. echo "Cached (baseline alias): $BASELINE_DEST"
  72. fi
  73. fi
  74. else
  75. echo "Skipped: $TARGET (not available)"
  76. fi
  77. done
  78. rm -rf "$TMP_DIR"
  79. else
  80. echo "Not a canary build ($BUN_VERSION), skipping pre-cache"
  81. fi
  82. - name: Install dependencies
  83. run: bun install
  84. shell: bash