action.yml 2.6 KB

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