backend_general.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. name: Backend
  2. on:
  3. push:
  4. branches: [ main ]
  5. paths:
  6. - 'backend'
  7. - 'shared-lib'
  8. pull_request:
  9. branches: [ main ]
  10. jobs:
  11. test:
  12. name: Test
  13. runs-on: ubuntu-latest
  14. services:
  15. postgres:
  16. image: postgres:12
  17. env:
  18. POSTGRES_USER: postgres
  19. POSTGRES_PASSWORD: password
  20. POSTGRES_DB: postgres
  21. ports:
  22. - 5433:5432
  23. env:
  24. SQLX_VERSION: 0.5.7
  25. SQLX_FEATURES: postgres
  26. steps:
  27. - name: Checkout repository
  28. uses: actions/checkout@v2
  29. - name: Cache dependencies
  30. id: cache-dependencies
  31. uses: actions/cache@v2
  32. with:
  33. path: |
  34. ~/.cargo/registry
  35. ~/.cargo/git
  36. target
  37. key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
  38. - name: Install stable toolchain
  39. uses: actions-rs/toolchain@v1
  40. with:
  41. profile: minimal
  42. toolchain: stable
  43. override: true
  44. - name: Cache sqlx-cli
  45. uses: actions/cache@v2
  46. id: cache-sqlx
  47. with:
  48. path: |
  49. ~/.cargo/bin/sqlx
  50. ~/.cargo/bin/cargo-sqlx
  51. key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }}
  52. - name: Install sqlx-cli
  53. uses: actions-rs/cargo@v1
  54. if: steps.cache-sqlx.outputs.cache-hit == false
  55. with:
  56. command: install
  57. args: >
  58. sqlx-cli
  59. --force
  60. --version=${{ env.SQLX_VERSION }}
  61. --features=${{ env.SQLX_FEATURES }}
  62. --no-default-features
  63. --locked
  64. - name: Migrate database
  65. working-directory: backend/
  66. run: |
  67. sudo apt-get install libpq-dev -y
  68. SKIP_DOCKER=true ./scripts/init_database.sh
  69. - name: Check sqlx-data.json is up-to-date
  70. working-directory: backend/
  71. run: |
  72. cargo sqlx prepare --check -- --bin backend
  73. - name: Run cargo test
  74. working-directory: backend/
  75. run: cargo test
  76. fmt:
  77. name: Rustfmt
  78. runs-on: ubuntu-latest
  79. steps:
  80. - uses: actions/checkout@v2
  81. - uses: actions-rs/toolchain@v1
  82. with:
  83. toolchain: stable
  84. override: true
  85. - run: rustup component add rustfmt
  86. working-directory: backend/
  87. - run: cargo fmt --all -- --check
  88. working-directory: backend/
  89. clippy:
  90. name: Clippy
  91. runs-on: ubuntu-latest
  92. services:
  93. postgres:
  94. image: postgres:12
  95. env:
  96. POSTGRES_USER: postgres
  97. POSTGRES_PASSWORD: password
  98. POSTGRES_DB: postgres
  99. ports:
  100. - 5433:5432
  101. env:
  102. SQLX_VERSION: 0.5.7
  103. SQLX_FEATURES: postgres
  104. steps:
  105. - name: Checkout repository
  106. uses: actions/checkout@v2
  107. - name: Install stable toolchain
  108. uses: actions-rs/toolchain@v1
  109. with:
  110. toolchain: stable
  111. components: clippy
  112. override: true
  113. - name: Cache sqlx-cli
  114. uses: actions/cache@v2
  115. id: cache-sqlx
  116. with:
  117. path: |
  118. ~/.cargo/bin/sqlx
  119. key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES }}
  120. - name: Install sqlx-cli
  121. uses: actions-rs/cargo@v1
  122. if: steps.cache-sqlx.outputs.cache-hit == false
  123. with:
  124. command: install
  125. args: >
  126. sqlx-cli
  127. --force
  128. --version=${{ env.SQLX_VERSION }}
  129. --features=${{ env.SQLX_FEATURES }}
  130. --no-default-features
  131. --locked
  132. - name: Migrate database
  133. run: |
  134. sudo apt-get install libpq-dev -y
  135. SKIP_DOCKER=true ./scripts/init_database.sh
  136. - run: rustup component add clippy
  137. working-directory: backend/
  138. - run: cargo clippy -- -D warnings
  139. working-directory: backend/