action.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. name: Setup environment
  2. inputs:
  3. cargo-cache-key:
  4. description: The key to cache cargo dependencies. Skips cargo caching if not provided.
  5. required: false
  6. cargo-cache-fallback-key:
  7. description: The fallback key to use when caching cargo dependencies. Default to not using a fallback key.
  8. required: false
  9. cargo-cache-local-key:
  10. description: The key to cache local cargo dependencies. Skips local cargo caching if not provided.
  11. required: false
  12. pnpm:
  13. description: Install pnpm if `true`. Defaults to `false`.
  14. required: false
  15. solana:
  16. description: Install Solana if `true`. Defaults to `false`.
  17. required: false
  18. toolchain:
  19. description: Rust toolchain to install. Comma-separated string of [`build`, `format`, `lint`, `test`].
  20. required: false
  21. runs:
  22. using: 'composite'
  23. steps:
  24. - name: Set Environment Variables
  25. shell: bash
  26. run: |
  27. source ./vars.env
  28. echo "RUST_TOOLCHAIN_NIGHTLY=$RUST_TOOLCHAIN_NIGHTLY" >> "$GITHUB_ENV"
  29. echo "SOLANA_CLI_VERSION=$SOLANA_CLI_VERSION" >> "$GITHUB_ENV"
  30. - name: Setup pnpm
  31. if: ${{ inputs.pnpm == 'true' }}
  32. uses: pnpm/action-setup@v3
  33. - name: Setup Node.js
  34. if: ${{ inputs.pnpm == 'true' }}
  35. uses: actions/setup-node@v4
  36. with:
  37. node-version: 20
  38. cache: 'pnpm'
  39. - name: Install Dependencies
  40. if: ${{ inputs.pnpm == 'true' }}
  41. run: pnpm install --frozen-lockfile
  42. shell: bash
  43. - name: Install Rust 'build' Toolchain
  44. if: ${{ contains(inputs.toolchain, 'build') }}
  45. uses: dtolnay/rust-toolchain@master
  46. with:
  47. toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
  48. - name: Install Rust 'format' Toolchain
  49. if: ${{ contains(inputs.toolchain, 'format') }}
  50. uses: dtolnay/rust-toolchain@master
  51. with:
  52. toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
  53. components: rustfmt
  54. - name: Install Rust 'lint' Toolchain
  55. if: ${{ contains(inputs.toolchain, 'lint') }}
  56. uses: dtolnay/rust-toolchain@master
  57. with:
  58. toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
  59. components: clippy
  60. - name: Install Rust 'test' Toolchain
  61. if: ${{ contains(inputs.toolchain, 'test') }}
  62. uses: dtolnay/rust-toolchain@master
  63. with:
  64. toolchain: ${{ env.RUST_TOOLCHAIN_NIGHTLY }}
  65. - name: Install Solana
  66. if: ${{ inputs.solana == 'true' }}
  67. uses: solana-program/actions/install-solana@v1
  68. with:
  69. version: ${{ env.SOLANA_CLI_VERSION }}
  70. cache: true
  71. - name: Install 'cargo-hack'
  72. if: ${{ contains(inputs.toolchain, 'lint') }}
  73. shell: bash
  74. run: cargo install cargo-hack
  75. - name: Cache Cargo Dependencies
  76. if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
  77. uses: actions/cache@v4
  78. with:
  79. path: |
  80. ~/.cargo/bin/
  81. ~/.cargo/registry/index/
  82. ~/.cargo/registry/cache/
  83. ~/.cargo/git/db/
  84. target/
  85. key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
  86. restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-key }}
  87. - name: Cache Cargo Dependencies With Fallback
  88. if: ${{ inputs.cargo-cache-key && inputs.cargo-cache-fallback-key }}
  89. uses: actions/cache@v4
  90. with:
  91. path: |
  92. ~/.cargo/bin/
  93. ~/.cargo/registry/index/
  94. ~/.cargo/registry/cache/
  95. ~/.cargo/git/db/
  96. target/
  97. key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
  98. restore-keys: |
  99. ${{ runner.os }}-${{ inputs.cargo-cache-key }}
  100. ${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}-${{ hashFiles('**/Cargo.lock') }}
  101. ${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}
  102. - name: Cache Local Cargo Dependencies
  103. if: ${{ inputs.cargo-cache-local-key }}
  104. uses: actions/cache@v4
  105. with:
  106. path: |
  107. .cargo/bin/
  108. .cargo/registry/index/
  109. .cargo/registry/cache/
  110. .cargo/git/db/
  111. key: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}-${{ hashFiles('**/Cargo.lock') }}
  112. restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}