From a47f8744f8f10df5f7ff2d67a1626522ae2537af Mon Sep 17 00:00:00 2001 From: Bluub <46396559+GitBluub@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:31:44 +0100 Subject: [PATCH] Fixing ci :) * wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * ci wip * meili env var in example dotenv --- .env.example | 2 - .github/workflows/CI.yml | 167 +++--------------------------------- .github/workflows/back.yml | 98 +++++++++++++++++++++ .github/workflows/front.yml | 95 ++++++++++++++++++++ .github/workflows/scoro.yml | 60 +++++++++++++ docker-compose.dev.yml | 10 +++ docker-compose.yml | 19 ++-- scorometer/main.py | 2 - 8 files changed, 287 insertions(+), 166 deletions(-) create mode 100644 .github/workflows/back.yml create mode 100644 .github/workflows/front.yml create mode 100644 .github/workflows/scoro.yml diff --git a/.env.example b/.env.example index ef910cd..12d242e 100644 --- a/.env.example +++ b/.env.example @@ -20,7 +20,5 @@ API_KEYS=SCOROTEST,ROBOTO,SCORO API_KEY_SCORO_TEST=SCOROTEST API_KEY_ROBOT=ROBOTO API_KEY_SCORO=SCORO -MEILI_HTTP_ADDR="http://meilisearch:7700" MEILI_MASTER_KEY="ghvjkgisbgkbgskegblfqbgjkebbhgwkjfb" - # vi: ft=sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 815cb8f..4f07651 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,166 +1,18 @@ -name: CI - +name: Deploy on: + pull_request: + types: + - closed + branches: + - main push: branches: - - '*' - pull_request: - branches: [ main ] + - main jobs: - -## Build Back ## - - Build_Back: + deployment: runs-on: ubuntu-latest - timeout-minutes: 10 - defaults: - run: - working-directory: ./back - environment: Staging - - steps: - - uses: actions/checkout@v3 - - - name: Build Docker - run: docker build -t testback . - -## Build App ## - - Check_Front: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./front - environment: Staging - steps: - - uses: actions/checkout@v3 - - name: Install Yarn - run: npm install -g yarn - - name: Install dependencies - run: yarn install - - name: Type Check - run: yarn tsc - - name: Check Prettier - run: yarn pretty:check . - - name: Run Linter - run: yarn lint - - Build_Front: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./front - environment: Staging - - steps: - - uses: actions/checkout@v3 - - - name: Install Yarn - run: npm install -g yarn - - - name: Install dependencies - run: yarn install - - - name: 🏗 Setup Expo - uses: expo/expo-github-action@v8 - with: - expo-version: latest - eas-version: latest - token: ${{ secrets.EXPO_TOKEN }} - - name: Build Web App - uses: docker/build-push-action@v3 - with: - context: ./front - push: false - tags: ${{steps.meta_front.outputs.tags}} - build-args: | - API_URL=${{secrets.API_URL}} - SCORO_URL=${{secrets.SCORO_URL}} - - - name: Build Android APK - run: | - eas build -p android --profile production --local --non-interactive - mv *.apk chromacase.apk - - - name: Upload Artifact - if: github.ref == 'refs/heads/main' - uses: actions/upload-artifact@v3 - with: - name: chromacase.apk - path: front/ - -## Test Backend ## - - Test_Back: - runs-on: ubuntu-latest - timeout-minutes: 15 - needs: [ Build_Back ] - environment: Staging - - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - fetch-depth: 0 - - - name: Copy env file to github secret env file - run: cp .env.example .env - - - name: Start the service - run: docker-compose up -d back db - - - name: Perform healthchecks - run: | - docker-compose ps -a - docker-compose logs - wget --retry-connrefused http://localhost:3000 || (docker-compose logs && exit 1) - - - name: Run scorometer tests - run: | - pip install -r scorometer/requirements.txt - export API_KEY_SCORO_TEST=SCOROTEST - export API_KEY_SCORO=SCORO - cd scorometer/tests && ./runner.sh - - - name: Run robot tests - run: | - export API_KEY_ROBOT=ROBOTO - pip install -r back/test/robot/requirements.txt - robot -d out back/test/robot/ - - uses: actions/upload-artifact@v3 - if: always() - with: - name: results - path: out - - - name: Write results to Pull Request and Summary - if: always() && github.event_name == 'pull_request' - uses: joonvena/robotframework-reporter-action@v2.1 - with: - report_path: out/ - gh_access_token: ${{ secrets.GITHUB_TOKEN }} - only_summary: false - - - name: Write results to Summary - if: always() && github.event_name != 'pull_request' - uses: joonvena/robotframework-reporter-action@v2.1 - with: - report_path: out/ - gh_access_token: ${{ secrets.GITHUB_TOKEN }} - only_summary: true - - - name: Remove .env && stop the service - run: docker-compose down && rm .env - -## Test App ## - -## Deployement ## - - Deployement_Docker: - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' - environment: Production + if: github.event.pull_request.merged == true steps: - uses: actions/checkout@v2 @@ -205,6 +57,7 @@ jobs: build-args: | API_URL=${{secrets.API_URL}} SCORO_URL=${{secrets.SCORO_URL}} + - name: Docker meta scorometer id: meta_scorometer uses: docker/metadata-action@v4 diff --git a/.github/workflows/back.yml b/.github/workflows/back.yml new file mode 100644 index 0000000..b9fb24f --- /dev/null +++ b/.github/workflows/back.yml @@ -0,0 +1,98 @@ +name: "Back" +on: + pull_request: + branches: [ main ] + +jobs: + + changes: + runs-on: ubuntu-latest + # Required permissions + permissions: + pull-requests: read + # Set job outputs to values from filter step + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + scoro: ${{ steps.filter.outputs.scoro }} + steps: + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + backend: + - 'backend/**' + frontend: + - 'frontend/**' + scoro: + - 'scorometer/**' + back_build: + runs-on: ubuntu-latest + timeout-minutes: 10 + + needs: changes + if: ${{ needs.changes.outputs.backend == 'true' }} + defaults: + run: + working-directory: ./back + steps: + - uses: actions/checkout@v3 + + - name: Build Docker + run: docker build -t testback . + + + back_test: + runs-on: ubuntu-latest + timeout-minutes: 15 + needs: [ back_build ] + if: ${{ needs.changes.outputs.frontend == 'true' }} + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Copy env file to github secret env file + run: cp .env.example .env + + - name: Build and start the service + run: docker-compose up -d meilisearch back db + + - name: Perform healthchecks + run: | + docker-compose ps -a + docker-compose logs + wget --retry-connrefused http://localhost:3000 || (docker-compose logs && exit 1) + + - name: Run robot tests + run: | + export API_KEY_ROBOT=ROBOTO + pip install -r back/test/robot/requirements.txt + robot -d out back/test/robot/ + - uses: actions/upload-artifact@v3 + if: always() + with: + name: results + path: out + + - name: Write results to Pull Request and Summary + if: always() && github.event_name == 'pull_request' + uses: joonvena/robotframework-reporter-action@v2.1 + with: + report_path: out/ + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + only_summary: false + + - name: Write results to Summary + if: always() && github.event_name != 'pull_request' + uses: joonvena/robotframework-reporter-action@v2.1 + with: + report_path: out/ + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + only_summary: true + + - name: stop the service + run: docker-compose down diff --git a/.github/workflows/front.yml b/.github/workflows/front.yml new file mode 100644 index 0000000..abb5262 --- /dev/null +++ b/.github/workflows/front.yml @@ -0,0 +1,95 @@ +name: "Front" +on: + pull_request: + branches: [ main ] + +jobs: + + changes: + runs-on: ubuntu-latest + # Required permissions + permissions: + pull-requests: read + # Set job outputs to values from filter step + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + scoro: ${{ steps.filter.outputs.scoro }} + steps: + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + backend: + - 'backend/**' + frontend: + - 'frontend/**' + scoro: + - 'scorometer/**' + front_check: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./front + needs: changes + if: ${{ needs.changes.outputs.frontend == 'true' }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'yarn' + cache-dependency-path: front/yarn.lock + - run: yarn install --frozen-lockfile + - name: type check + run: yarn tsc + - name: prettier + run: yarn pretty:check . + - name: eslint + run: yarn lint + + front_build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./front + if: ${{ needs.changes.outputs.frontend == 'true' }} + needs: [ front_check ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'yarn' + cache-dependency-path: front/yarn.lock + - run: yarn install --frozen-lockfile + + - name: 🏗 Setup Expo + uses: expo/expo-github-action@v8 + with: + expo-version: latest + eas-version: latest + token: ${{ secrets.EXPO_TOKEN }} + + - name: Build Web App + uses: docker/build-push-action@v3 + with: + context: ./front + push: false + tags: ${{steps.meta_front.outputs.tags}} + build-args: | + API_URL=${{secrets.API_URL}} + SCORO_URL=${{secrets.SCORO_URL}} + + - name: Build Android APK + run: | + eas build -p android --profile production --local --non-interactive + mv *.apk chromacase.apk + + - name: Upload Artifact + if: github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: chromacase.apk + path: front/ \ No newline at end of file diff --git a/.github/workflows/scoro.yml b/.github/workflows/scoro.yml new file mode 100644 index 0000000..0a10a80 --- /dev/null +++ b/.github/workflows/scoro.yml @@ -0,0 +1,60 @@ +name: "Scoro" +on: + pull_request: + branches: [ main ] + +jobs: + changes: + runs-on: ubuntu-latest + # Required permissions + permissions: + pull-requests: read + # Set job outputs to values from filter step + outputs: + backend: ${{ steps.filter.outputs.backend }} + frontend: ${{ steps.filter.outputs.frontend }} + scoro: ${{ steps.filter.outputs.scoro }} + steps: + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + backend: + - 'backend/**' + frontend: + - 'frontend/**' + scoro: + - 'scorometer/**' + scoro_test: + runs-on: ubuntu-latest + needs: changes + if: ${{ needs.changes.outputs.scoro == 'true' }} + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Copy env file to github secret env file + run: cp .env.example .env + + - name: Build and start the service + run: docker-compose up -d meilisearch back db + + - name: Perform healthchecks + run: | + docker-compose ps -a + docker-compose logs + wget --retry-connrefused http://localhost:3000 || (docker-compose logs && exit 1) + + - name: Run scorometer tests + run: | + export API_KEY_SCORO_TEST=SCOROTEST + export API_KEY_SCORO=SCORO + pip install -r scorometer/requirements.txt + cd scorometer/tests && ./runner.sh + + - name: stop the service + run: docker-compose down diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 9f14f14..c535ba9 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -22,6 +22,9 @@ services: depends_on: db: condition: service_healthy + + meilisearch: + condition: service_healthy env_file: - .env @@ -94,3 +97,10 @@ services: - meilisearch:/meili_data env_file: - .env + + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:7700/health"] + interval: 10s + timeout: 10s + retries: 5 + diff --git a/docker-compose.yml b/docker-compose.yml index 0cddfc4..334ca56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,3 @@ -networks: - loki: - - volumes: db: scoro_logs: @@ -17,11 +13,15 @@ services: depends_on: db: condition: service_healthy + meilisearch: + condition: service_healthy + env_file: - .env volumes: - ./assets:/assets - ./data:/data + scorometer: build: ./scorometer ports: @@ -62,10 +62,19 @@ services: - .env meilisearch: - image: getmeili/meilisearch:v1.4 + image: getmeili/meilisearch:v1.5 ports: - "7700:7700" volumes: - meilisearch:/meili_data env_file: - .env + healthcheck: + test: + - CMD + - wget + - '--no-verbose' + - '--spider' + - 'http://localhost:7700/health' + retries: 3 + timeout: 5s \ No newline at end of file diff --git a/scorometer/main.py b/scorometer/main.py index 58c0cef..45ff4db 100755 --- a/scorometer/main.py +++ b/scorometer/main.py @@ -367,8 +367,6 @@ def handleStartMessage(start_message: StartMessage): try: r = requests.get(f"{BACK_URL}/song/{song_id}", headers=auth_header) r.raise_for_status() - # Delete the guest account after getting song - requests.delete(f"{BACK_URL}/auth/me", headers=auth_header) song_path = r.json()["midiPath"] song_path = song_path.replace("/assets/musics/", MUSICS_FOLDER) except Exception as e: