From baf580eb11a6e00aa5898e84f7478b8a1abead5d Mon Sep 17 00:00:00 2001 From: halis Date: Mon, 1 Jul 2024 23:15:20 +0300 Subject: [PATCH] chore(server): create github actions precheck.yaml --- .github/workflows/prcheck.yaml | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/prcheck.yaml diff --git a/.github/workflows/prcheck.yaml b/.github/workflows/prcheck.yaml new file mode 100644 index 0000000..38fda08 --- /dev/null +++ b/.github/workflows/prcheck.yaml @@ -0,0 +1,76 @@ +name: check on pr + +on: + pull_request: + types: + - opened + - synchronize + branches: + - main + paths: + - 'packages/api/**' + +jobs: + build: + + runs-on: ubuntu-latest + + services: + test-db: + image: mariadb:latest + ports: + - 3307:3306 + env: + MYSQL_DATABASE: app + MYSQL_USER: user + MYSQL_PASSWORD: secret + MYSQL_ROOT_PASSWORD: secret + options: >- + --health-cmd="mysqladmin ping -uuser -psecret --silent" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '21' + + - name: Install Maven dependencies + run: mvn install -DskipTests + working-directory: packages/api + + - name: Run Spotless check + run: mvn spotless:check + working-directory: packages/api + + - name: Wait for test-db to be ready + run: | + echo "Waiting for test-db to be ready..." + for i in {1..30}; do + if [ "$(docker inspect --format='{{.State.Health.Status}}' $(docker ps -q --filter name=test-db))" == "healthy" ]; then + echo "test-db is healthy!" + exit 0 + fi + echo "Waiting for test-db to be healthy... ($i/30)" + sleep 10 + done + echo "test-db failed to become healthy" + exit 1 + + - name: Run tests + env: + SPRING_DATASOURCE_URL: jdbc:mariadb://localhost:3307/app + SPRING_DATASOURCE_USERNAME: user + SPRING_DATASOURCE_PASSWORD: secret + run: mvn test + working-directory: packages/api + + - name: Build project + run: mvn clean package + working-directory: packages/api