diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 83f73daaaa..f4a053915b 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -17,16 +17,16 @@ on: jobs: pytest: - uses: ./.github/workflows/r-pytest.yml + uses: hotosm/gh-workflows/.github/workflows/test_pytest_compose.yml@main with: - # TODO update to build image prior to test, like r-pytest.yml? - # Would prevent failures if the CI image does not contain new deps yet image_tag: ci-${{ github.ref_name }} docker_compose_service: api secrets: inherit frontend-tests: - uses: ./.github/workflows/r-frontend_tests.yml + uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@main + with: + working_dir: src/frontend backend-build: uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main diff --git a/.github/workflows/pr_test_backend.yml b/.github/workflows/pr_test_backend.yml index c229ad63c3..e7eb79d9ed 100644 --- a/.github/workflows/pr_test_backend.yml +++ b/.github/workflows/pr_test_backend.yml @@ -14,7 +14,7 @@ on: jobs: pytest: - uses: ./.github/workflows/r-pytest.yml + uses: hotosm/gh-workflows/.github/workflows/test_pytest_compose.yml@main with: docker_compose_service: api cache_imgs: | diff --git a/.github/workflows/pr_test_frontend.yml b/.github/workflows/pr_test_frontend.yml index 43c2d7b858..0a2bb7bcdb 100644 --- a/.github/workflows/pr_test_frontend.yml +++ b/.github/workflows/pr_test_frontend.yml @@ -14,4 +14,6 @@ on: jobs: frontend-tests: - uses: ./.github/workflows/r-frontend_tests.yml + uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@main + with: + working_dir: src/frontend diff --git a/.github/workflows/r-frontend_tests.yml b/.github/workflows/r-frontend_tests.yml deleted file mode 100644 index 0d62d57a0e..0000000000 --- a/.github/workflows/r-frontend_tests.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Frontend Tests - -on: - workflow_call: - -jobs: - test: - name: Run Frontend Tests - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: pnpm/action-setup@v2 - with: - version: 8 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: "pnpm" - cache-dependency-path: "src/frontend/pnpm-lock.yaml" - - - name: Install dependencies - working-directory: src/frontend - run: pnpm install - - - name: Test Frontend - working-directory: src/frontend - run: pnpm run test diff --git a/.github/workflows/r-pytest.yml b/.github/workflows/r-pytest.yml deleted file mode 100644 index f1ef0e8cca..0000000000 --- a/.github/workflows/r-pytest.yml +++ /dev/null @@ -1,156 +0,0 @@ -name: pytest - -on: - workflow_call: - inputs: - image_tag: - description: "Optional image tag override." - required: false - type: string - cache_imgs: - description: "Space separated list of images to cache on each run (e.g. to avoid rate limiting)." - required: false - type: string - docker_compose_file: - description: "The docker compose file used to run the test." - required: false - type: string - default: docker-compose.yml - docker_compose_service: - description: "The docker compose service to run the test against." - required: true - type: string - environment: - description: "The environment to use for testing." - required: false - type: string - default: "test" - -jobs: - check-img-cache: - runs-on: ubuntu-latest - if: ${{ inputs.cache_imgs }} - environment: - name: ${{ inputs.environment }} - outputs: - cache-hit: ${{ steps.image-cache.outputs.cache-hit }} - steps: - - id: image-cache - uses: actions/cache@v3 - with: - path: /tmp/images - key: image-cache-${{ runner.os }} - - backend-test-build: - uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main - needs: [check-img-cache] - if: ${{ needs.check-img-cache.outputs.cache-hit != 'true' }} - with: - context: src/backend - build_target: ci - image_name: ghcr.io/${{ github.repository }}/backend - image_tags: ${{ inputs.image_tag && format('ghcr.io/{0}/backend:{1}', github.repository, inputs.image_tag) || '' }} - build_args: | - APP_VERSION=${{ github.ref_name }} - COMMIT_REF=${{ github.sha }} - # Build temp image for PR, no multi-arch or scan required - multi_arch: false - scan: false - cache: false - - run-pytest: - runs-on: ubuntu-latest - needs: [backend-test-build] - # Ensure it runs, even if backend-test-build does not run - if: always() - environment: - name: ${{ inputs.environment }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - id: image-cache - if: ${{ inputs.cache_imgs }} - uses: actions/cache@v3 - with: - path: /tmp/images - key: image-cache-${{ runner.os }} - - - name: Save Local Images - if: ${{ inputs.cache_imgs && steps.image-cache.outputs.cache-hit != 'true' }} - run: | - # Function to pull and package Docker image - function pull_and_package_image() { - local image=$1 - echo "Processing image ${image}" - docker pull "${image}" - - if [ $? -eq 0 ]; then - img_underscores=${image//[:\/.]/_} - echo "Packaging image to /tmp/images/${img_underscores}.tar" - docker image save "${image}" --output "/tmp/images/${img_underscores}.tar" - else - echo "Failed to pull the image: ${image}" - fi - } - - # Make artifact dir - mkdir -p /tmp/images - - images_array=(${{ inputs.cache_imgs }}) - echo "Images to cache: ${images_array}" - - # Iterate through dependency images - for image in "${images_array[@]}"; do - pull_and_package_image "$image" - done - - # Cache backend build (fallback to ci-development tag) - image_tag=${{ needs.backend-test-build.outputs.image_tag }} - image="ghcr.io/${{ github.repository }}/backend:${image_tag}" - pull_and_package_image "$image" - echo "API_TAG_OVERRIDE=${image_tag}" >> $GITHUB_ENV - - - name: Load Cached Imgs - if: ${{ inputs.cache_imgs && steps.image-cache.outputs.cache-hit == 'true' }} - run: | - for image_tar in /tmp/images/*; do - docker image load --input $image_tar || true - done - - # Set API_TAG_OVERRIDE if not set - echo "Getting backend image tag via docker" - image=$(\ - docker image ls \ - --filter=reference='ghcr.io/${{ github.repository }}/backend' \ - --format='{{.Tag}}'\ - ) - image_tag="${image##*:}" - echo "Image Tag: $image_tag" - echo "API_TAG_OVERRIDE=${image_tag}" >> $GITHUB_ENV - - - name: Vars and Secrets to Env - env: - API_TAG_OVERRIDE: ${{ env.API_TAG_OVERRIDE || 'ci-development' }} - GIT_BRANCH: ${{ github.ref_name }} - VARS_CONTEXT: ${{ toJson(vars) }} - SECRETS_CONTEXT: ${{ toJson(secrets) }} - run: | - to_envs() { jq -r "to_entries[] | \"\(.key)=\(.value)\""; } - - echo "API_TAG_OVERRIDE=${API_TAG_OVERRIDE}" >> $GITHUB_ENV - echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV - echo "${VARS_CONTEXT}" | to_envs >> $GITHUB_ENV - echo "${SECRETS_CONTEXT}" | to_envs >> $GITHUB_ENV - - - name: Create .env file - run: env > .env - - - name: Run PyTest - run: | - docker compose --file ${{ inputs.docker_compose_file }} \ - run ${{ inputs.docker_compose_service }} \ - wait-for-it fmtm-db:5432 --strict \ - -- wait-for-it central:8383 --strict --timeout=30 \ - -- pytest