action.yml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. - name: Get baseline download URL
  12. id: bun-url
  13. shell: bash
  14. run: |
  15. if [ "$RUNNER_ARCH" = "X64" ]; then
  16. V=$(node -p "require('./package.json').packageManager.split('@')[1]")
  17. case "$RUNNER_OS" in
  18. macOS) OS=darwin ;;
  19. Linux) OS=linux ;;
  20. Windows) OS=windows ;;
  21. esac
  22. echo "url=https://github.com/oven-sh/bun/releases/download/bun-v${V}/bun-${OS}-x64-baseline.zip" >> "$GITHUB_OUTPUT"
  23. fi
  24. - name: Setup Bun
  25. uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
  26. with:
  27. bun-version-file: ${{ !steps.bun-url.outputs.url && 'package.json' || '' }}
  28. bun-download-url: ${{ steps.bun-url.outputs.url }}
  29. - name: Get cache directory
  30. id: cache
  31. shell: bash
  32. run: echo "dir=$(bun pm cache)" >> "$GITHUB_OUTPUT"
  33. - name: Restore Bun dependencies
  34. id: bun-cache
  35. uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  36. with:
  37. path: ${{ steps.cache.outputs.dir }}
  38. key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
  39. restore-keys: |
  40. ${{ runner.os }}-bun-
  41. - name: Install setuptools for distutils compatibility
  42. run: python3 -m pip install setuptools || pip install setuptools || true
  43. shell: bash
  44. - name: Install dependencies
  45. run: |
  46. # Workaround for patched peer variants
  47. # e.g. ./patches/ for standard-openapi
  48. # https://github.com/oven-sh/bun/issues/28147
  49. if [ "$RUNNER_OS" = "Windows" ]; then
  50. bun install --linker hoisted ${{ inputs.install-flags }}
  51. else
  52. bun install ${{ inputs.install-flags }}
  53. fi
  54. shell: bash
  55. - name: Save Bun dependencies
  56. if: steps.bun-cache.outputs.cache-hit != 'true' && github.event_name != 'pull_request' && github.event_name != 'pull_request_target'
  57. uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  58. with:
  59. path: ${{ steps.cache.outputs.dir }}
  60. key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}