name: CI on: push: branches: - master pull_request: types: [opened, reopened, synchronize] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} cancel-in-progress: true jobs: build: name: Сборка runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: git.jt4d.ru username: ${{ vars.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Install dependencies run: yarn install --frozen-lockfile - name: Check branch name run: yarn lint:branch-name - name: Check branch name characters env: BRANCH: ${{ github.head_ref || github.ref_name }} run: | if ! printf '%s' "$BRANCH" | grep -Eq '^[A-Za-z0-9][A-Za-z0-9.-]*$'; then echo "::error::Недопустимое имя ветки: '$BRANCH'. Разрешены только A-Z a-z 0-9 . -, имя не может быть пустым и начинаться с '-'" exit 1 fi - name: Check migrations list run: yarn ts-node tools/buildDataSource.ts --check - name: Build run: yarn build - name: Check data-source run: yarn ts-node tools/checkDataSource.ts - name: Build web docker image uses: docker/build-push-action@v7 with: context: apps/web file: apps/web/Dockerfile push: true tags: git.jt4d.ru/${{ github.repository }}/web:${{ github.head_ref || github.ref_name }} cache-from: git.jt4d.ru/${{ github.repository }}/web:latest labels: | org.opencontainers.image.ref.name=${{ github.head_ref || github.ref_name }} - name: Copy run: cp yarn.lock apps/api/ - name: Build api docker image uses: docker/build-push-action@v7 with: context: apps/api file: apps/api/Dockerfile push: true tags: git.jt4d.ru/${{ github.repository }}/api:${{ github.head_ref || github.ref_name }} cache-from: git.jt4d.ru/${{ github.repository }}/api:latest labels: | org.opencontainers.image.ref.name=${{ github.head_ref || github.ref_name }} deploy-staging: name: Деплой на стейджинг runs-on: ubuntu-latest needs: build steps: - name: Checkout uses: actions/checkout@v4 - name: Copy docker-compose file uses: appleboy/scp-action@v1 with: host: ${{ vars.STAGING_HOST }} username: ${{ vars.STAGING_USER }} key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }} port: ${{ vars.STAGING_PORT }} source: 'docker-compose.staging.yml' target: /home/${{ vars.STAGING_USER }}/${{ github.event.repository.name }}_${{ github.head_ref || github.ref_name }} - name: Deploy via SSH uses: appleboy/ssh-action@v1 env: DEPLOY_DIR: ${{ github.event.repository.name }}_${{ github.head_ref || github.ref_name }} BRANCH: ${{ github.head_ref || github.ref_name }} with: host: ${{ vars.STAGING_HOST }} username: ${{ vars.STAGING_USER }} key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }} port: ${{ vars.STAGING_PORT }} script_stop: true envs: DEPLOY_DIR,BRANCH script: | set -e cd "/home/${{ vars.STAGING_USER }}/$DEPLOY_DIR" mv -f docker-compose.*.yml docker-compose.yml # \${BRANCH} — литеральный плейсхолдер в docker-compose.staging.yml, # $BRANCH — имя ветки из окружения. sed -i "s/\${BRANCH}/$BRANCH/g" docker-compose.yml docker compose pull --quiet docker compose down docker compose up -d # echo "Список миграций" # docker compose exec -T api node_modules/.bin/typeorm migration:show -d data-source.js # echo "Применение миграций" # docker compose exec -T api node_modules/.bin/typeorm migration:run -t each -d data-source.js # Если migration:run упадёт, prune под `set -e` не выполнится — # почистится на следующем деплое. docker system prune -f - name: Set deployment status env: BRANCH: ${{ github.head_ref || github.ref_name }} DEPLOY_URL: http://${{ github.head_ref || github.ref_name }}.geo-platform.geo-helm.jt4d.ru.net run: | curl -s -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Content-Type: application/json" \ -d '{ "state": "success", "context": "Стенд", "description": "'"$BRANCH"'", "target_url": "'"$DEPLOY_URL"'" }' \ "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}" check: name: Проверка кода runs-on: ubuntu-latest needs: build steps: - name: Checkout uses: actions/checkout@v4 - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: git.jt4d.ru username: ${{ vars.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Install dependencies run: yarn install --frozen-lockfile - name: Lint run: yarn lint:check docs: name: Документация runs-on: ubuntu-latest needs: build container: image: git.jt4d.ru/jt4d/gitea-runner:latest credentials: username: ${{ vars.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} volumes: - '/usr/local/share/.cache:/usr/local/share/.cache' env: YARN_CACHE_FOLDER: /usr/local/share/.cache/yarn steps: - name: Checkout uses: actions/checkout@v4 - name: Build and deploy docs uses: https://git.jt4d.ru/docuservix/docs@next with: prefix: wiki on-broken-links: warn