diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ecdb0bae3..7b42dcb24e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ cache: - target/ stages: - - auto_update + - test variables: POSTGRES_DB: firefish_db @@ -38,73 +38,14 @@ default: - export PGPASSWORD="${POSTGRES_PASSWORD}" - psql --host postgres --user "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" --command 'CREATE EXTENSION pgroonga' -auto_update: - stage: auto_update +build_test: + stage: test script: - # setup git - - apk add git - - git config user.name 'GitLab CI' - - git config user.email 'noreply@firefish.dev' - - git remote set-url origin "https://${CI_REGISTRY_USER}:${API_TOKEN}@${CI_REPOSITORY_URL#*@}" - # update pnpm lockfile - - pnpm install - # commit - - |- - if [ `git status -s | wc -l` -gt 0 ]; then - git add . - git commit --message 'chore: update lockfile' - git push --push-option=ci.skip origin "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}" - fi - # run format - - pnpm run format - # commit - - |- - if [ `git status -s | wc -l` -gt 0 ]; then - git add . - git commit --message 'chore: format' - git push --push-option=ci.skip origin "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}" - fi - # update packages/backend-rs/src/model/entity - - apk install pkgconfig openssl openssl-dev libssl3 - - cargo install sea-orm-cli - - pnpm --filter backend run build:debug - - pnpm run migrate - - cd packages/backend-rs - - mv src/model/entity src/model/entity.bak - - |- - sea-orm-cli generate entity \ - --output-dir='src/model/entity' \ - --date-time-crate='chrono' \ - --model-extra-attributes='NAPI_EXTRA_ATTR_PLACEHOLDER' \ - --database-url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}" - - |- - for file in src/model/entity/*; do - base=$(basename -- "${file}") - jsname=$(printf '%s\n' "${base%.*}" | perl -pe 's/(^|_)./uc($&)/ge;s/_//g') - attribute=$(printf 'cfg_attr(feature = "napi", napi_derive::napi(object, js_name = "%s", use_nullable = true))' "${jsname}") - sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/${attribute}/" "${file}" - sed -i 's/#\[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)\]/#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, serde::Serialize, serde::Deserialize)]\n#[serde(rename_all = "camelCase")]/' "${file}" - done - - |- - sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, serde::Serialize, serde::Deserialize)]\n#[serde(rename_all = "camelCase")]\n#[cfg_attr(not(feature = "napi"), derive(Clone))]\n#[cfg_attr(feature = "napi", napi_derive::napi(string_enum = "camelCase"))]/' \ - src/model/entity/sea_orm_active_enums.rs - - rm --recursive --force src/model/entity.bak - - cargo fmt --all -- - # commit - - |- - if [ `git status -s | wc -l` -gt 0 ]; then - git add . - git commit --message 'chore (backend-rs): regenerate entity' - git push --push-option=ci.skip origin "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}" - fi - # update packages/backend-rs/index.{js,d.ts} + - pnpm install --frozen-lockfile - pnpm run build:debug - - /bin/cp --force built/index.js index.js - - /bin/cp --force built/index.d.ts index.d.ts - - sed -i 's/^ \*r"/ */g' index.d.ts - - |- - if [ `git status -s | wc -l` -gt 0 ]; then - git add . - git commit --message 'chore (backend-rs): regenerate index' - git push --push-option=ci.skip origin "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}" - fi + - pnpm run migrate + +cargo_test: + stage: test + script: + - cargo test