diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9d1abad5e1d78..dbb49903e2509 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,9 +1,10 @@ name: Unit Tests - +run-name: ${{ github.actor }} is running Unit Tests on: pull_request: branches: - 2.4-develop + - nx-work permissions: contents: write @@ -12,13 +13,52 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - # TODO environment set up: WARDEN + - name: Checkout PR commit + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: main + # Need to do this otherwise Nx cant determine diff + fetch-depth: 0 + + - name: Fetch base + working-directory: ./main + run: git fetch origin ${{ github.event.pull_request.base.ref }} + + - name: Install Composer + uses: php-actions/composer@v6 + with: + # Run the dummy help command after installing Composer (otherwise defaults to install) + command: help + + - name: Get Composer Cache Directory + id: composer-cache + working-directory: ./main + run: echo "composer_cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Install Composer Cache + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.composer_cache_dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/main/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install Composer Dependencies + working-directory: ./main + run: composer install - - name: Install / setups Nx + - name: Checkout Nx Repo + uses: actions/checkout@v3 + with: + repository: adamzero1/nx-for-php + path: nx + + - name: Install / setup Nx + working-directory: ./main run: | npm install -g nx@15.4.1 - NXDIR=/workspaces/nx-for-php - git clone https://github.com/adamzero1/nx-for-php.git ${NXDIR} + NXDIR="../nx" cp -r ${NXDIR}/nx ./ cp ${NXDIR}/nx.json ./ cp ${NXDIR}/package.json ./ @@ -27,25 +67,31 @@ jobs: npm ci npm run generate-workspace - - name: Dependency Comment - env: - GITHUB_URL: ${{ github.event.pull_request.comments_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - AFFECTED_OUTPUT=/tmp/affect.json - nx print-affected --files=app/code/Magento/AdminAnalytics/Model/ResourceModel/Viewer/Logger.php > ${AFFECTED_OUTPUT} - AFFECTED_COUNT=$(jq '.projects | length' ${AFFECTED_OUTPUT}) - TOTAL_COUNT=$(jq '.projectGraph.nodes | length' ${AFFECTED_OUTPUT}) - PERCENTAGE=$(php -r "printf('%.2f', ((${AFFECTED_COUNT}/${TOTAL_COUNT})*100));") - echo "${AFFECTED_COUNT} / ${TOTAL_COUNT} nodes affected (${PERCENTAGE}%)" - curl -X POST \ - $GITHUB_URL \ - -H "Content-Type: application/json" \ - -H "Authorization: token $GITHUB_TOKEN" \ - --data "{\"body\": \"${${AFFECTED_COUNT} / ${TOTAL_COUNT} nodes affected (${PERCENTAGE}%)}\"}' - - - name: Run unit tests - run: | - nx affected --target=test:unit --files=app/code/Magento/AdminNotification/Model/Feed.php - nx affected --target=test:unit --base=2.4-develop --head=HEAD + - name: Print Affected + working-directory: ./main + run: nx print-affected --head=HEAD --base=remotes/origin/${{ github.event.pull_request.base.ref }} + + # TODO environment set up: WARDEN + + # - name: Dependency Comment + # env: + # GITHUB_URL: ${{ github.event.pull_request.comments_url }} + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # AFFECTED_OUTPUT=/tmp/affect.json + # nx print-affected --files=app/code/Magento/AdminAnalytics/Model/ResourceModel/Viewer/Logger.php > ${AFFECTED_OUTPUT} + # AFFECTED_COUNT=$(jq '.projects | length' ${AFFECTED_OUTPUT}) + # TOTAL_COUNT=$(jq '.projectGraph.nodes | length' ${AFFECTED_OUTPUT}) + # PERCENTAGE=$(php -r "printf('%.2f', ((${AFFECTED_COUNT}/${TOTAL_COUNT})*100));") + # echo "${AFFECTED_COUNT} / ${TOTAL_COUNT} nodes affected (${PERCENTAGE}%)" + # curl -X POST \ + # $GITHUB_URL \ + # -H "Content-Type: application/json" \ + # -H "Authorization: token $GITHUB_TOKEN" \ + # --data "{\"body\": \"${${AFFECTED_COUNT} / ${TOTAL_COUNT} nodes affected (${PERCENTAGE}%)}\"}' + + # - name: Run unit tests + # run: | + # nx affected --target=test:unit --files=app/code/Magento/AdminNotification/Model/Feed.php + # nx affected --target=test:unit --base=2.4-develop --head=HEAD