1
0

action.yml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. name: "Setup Bun"
  2. description: "Setup Bun with caching and install dependencies"
  3. inputs:
  4. bun-version:
  5. description: "Bun version to install instead of the root packageManager version"
  6. required: false
  7. default: ""
  8. install-flags:
  9. description: "Additional flags to pass to 'bun install'"
  10. required: false
  11. default: ""
  12. runs:
  13. using: "composite"
  14. steps:
  15. # node-gyp@latest (invoked via bunx for native install scripts) requires Node >=22;
  16. # some runner images ship an older system Node on PATH
  17. - name: Setup Node
  18. uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
  19. with:
  20. node-version: "24"
  21. - name: Get baseline download URL
  22. id: bun-url
  23. shell: bash
  24. run: |
  25. if [ "$RUNNER_ARCH" = "X64" ]; then
  26. V="${{ inputs.bun-version }}"
  27. if [ -z "$V" ]; then V=$(node -p "require('./package.json').packageManager.split('@')[1]"); fi
  28. TAG=$([ "$V" = "canary" ] && echo "canary" || echo "bun-v${V}")
  29. case "$RUNNER_OS" in
  30. macOS) OS=darwin ;;
  31. Linux) OS=linux ;;
  32. Windows) OS=windows ;;
  33. esac
  34. echo "url=https://github.com/oven-sh/bun/releases/download/${TAG}/bun-${OS}-x64-baseline.zip" >> "$GITHUB_OUTPUT"
  35. fi
  36. - name: Setup Bun
  37. uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
  38. with:
  39. bun-version: ${{ !steps.bun-url.outputs.url && inputs.bun-version || '' }}
  40. bun-version-file: ${{ !steps.bun-url.outputs.url && !inputs.bun-version && 'package.json' || '' }}
  41. bun-download-url: ${{ steps.bun-url.outputs.url }}
  42. - name: Get cache directory
  43. id: cache
  44. shell: bash
  45. run: echo "dir=$(bun pm cache)" >> "$GITHUB_OUTPUT"
  46. - name: Restore Bun dependencies
  47. id: bun-cache
  48. uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  49. with:
  50. path: ${{ steps.cache.outputs.dir }}
  51. key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
  52. restore-keys: |
  53. ${{ runner.os }}-bun-
  54. - name: Install setuptools for distutils compatibility
  55. run: python3 -m pip install setuptools || pip install setuptools || true
  56. shell: bash
  57. - name: Install dependencies
  58. run: |
  59. # Workaround for patched peer variants
  60. # e.g. ./patches/ for standard-openapi
  61. # https://github.com/oven-sh/bun/issues/28147
  62. if [ "$RUNNER_OS" = "Windows" ]; then
  63. bun install --linker hoisted ${{ inputs.install-flags }}
  64. else
  65. bun install ${{ inputs.install-flags }}
  66. fi
  67. shell: bash
  68. - name: Save Bun dependencies
  69. if: steps.bun-cache.outputs.cache-hit != 'true' && github.event_name != 'pull_request' && github.event_name != 'pull_request_target'
  70. uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  71. with:
  72. path: ${{ steps.cache.outputs.dir }}
  73. key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}