From dd7202fbae2630df849b5536dd028a1a80684110 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 17:58:05 +0000 Subject: [PATCH 01/10] workflow work --- .github/workflows/unit-tests.yml | 72 +++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9d1abad5e1d78..29d896aa81750 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - 2.4-develop + - nx-work permissions: contents: write @@ -12,13 +13,28 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - # TODO environment set up: WARDEN - - name: Install / setups Nx + - name: Checkout PR commit + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: main + + - name: Fetch base + working-directory: ./main + run: git fetch origin ${{ github.event.pull_request.base.ref }} + + - 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 +43,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: npm run print-affected -- --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 From 2617ee08074158d5d8bc1e6856471dd25eb0ce11 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:02:21 +0000 Subject: [PATCH 02/10] testing --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 29d896aa81750..df5d6e71c3bea 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -45,7 +45,7 @@ jobs: - name: Print Affected working-directory: ./main - run: npm run print-affected -- --base=remotes/origin/${{ github.event.pull_request.base.ref }} + run: nx print-affected -- --base=remotes/origin/${{ github.event.pull_request.base.ref }} # TODO environment set up: WARDEN From a0234a5a22a0cc7361947b71bff8ef0eba0aad56 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:13:54 +0000 Subject: [PATCH 03/10] test --- .github/workflows/unit-tests.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index df5d6e71c3bea..38076024026fa 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -24,6 +24,29 @@ jobs: 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: Checkout Nx Repo uses: actions/checkout@v3 with: From 78f36f211335dd395a87fe9a2349af8a4e875aab Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:22:04 +0000 Subject: [PATCH 04/10] test --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 38076024026fa..02d3e93e364d3 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -68,7 +68,7 @@ jobs: - name: Print Affected working-directory: ./main - run: nx print-affected -- --base=remotes/origin/${{ github.event.pull_request.base.ref }} + run: nx print-affected --head=HEAD --base=remotes/origin/${{ github.event.pull_request.base.ref }} # TODO environment set up: WARDEN From b02585a049605756628f205e5d6bf4fb2fd38944 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:38:37 +0000 Subject: [PATCH 05/10] test --- .github/workflows/unit-tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 02d3e93e364d3..05848c1d5a35c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -24,6 +24,13 @@ jobs: working-directory: ./main run: git fetch origin ${{ github.event.pull_request.base.ref }} + - name: aaaaaa + working-directory: ./main + run: | + git branch + git branch --show-current + git merge-base --fork-point "remotes/origin/nx-work" "HEAD" + - name: Install Composer uses: php-actions/composer@v6 with: From 43c0818420264358e56ffd5118a5ed57a3d57240 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:43:33 +0000 Subject: [PATCH 06/10] test --- .github/workflows/unit-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 05848c1d5a35c..3ef50cef6bf76 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -27,6 +27,8 @@ jobs: - name: aaaaaa working-directory: ./main run: | + git branch + git switch -c pr git branch git branch --show-current git merge-base --fork-point "remotes/origin/nx-work" "HEAD" From 8bf35bee37de782a2aebd3d95c8a4c6e724fa53d Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 18:46:54 +0000 Subject: [PATCH 07/10] test --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 3ef50cef6bf76..4b49ee1a5f6b9 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,6 +19,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} path: main + fetch-depth: 0 - name: Fetch base working-directory: ./main From 2a44ff604ad7fd4392da97205ac7f25a23a750d3 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Mar 2023 19:13:16 +0000 Subject: [PATCH 08/10] testing --- .github/workflows/unit-tests.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 4b49ee1a5f6b9..9de781824797d 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,21 +19,13 @@ jobs: 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: aaaaaa - working-directory: ./main - run: | - git branch - git switch -c pr - git branch - git branch --show-current - git merge-base --fork-point "remotes/origin/nx-work" "HEAD" - - name: Install Composer uses: php-actions/composer@v6 with: From d66cc900dfe71d0f747d342e8b80362d3feaf903 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 7 Mar 2023 13:03:26 +0000 Subject: [PATCH 09/10] work on workflow --- .github/workflows/unit-tests.yml | 85 +------------------------------- 1 file changed, 2 insertions(+), 83 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9de781824797d..ddbf865d77beb 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,86 +13,5 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - - - 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: 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="../nx" - cp -r ${NXDIR}/nx ./ - cp ${NXDIR}/nx.json ./ - cp ${NXDIR}/package.json ./ - cp ${NXDIR}/package-lock.json ./ - cp ${NXDIR}/phpunit.mage-os.nx.xml ./phpunit.nx.xml - npm ci - npm run generate-workspace - - - 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 - + - name: Run Unit Tests + uses: adamzero1/temp-repo2/blob/main/.github/workflows/mageos-unit-tests.yml@main \ No newline at end of file From 2552ce7caf23a4596b057f8b95a201c237fcadcb Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 7 Mar 2023 13:12:03 +0000 Subject: [PATCH 10/10] workflow work --- .github/workflows/unit-tests.yml | 86 ++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ddbf865d77beb..dbb49903e2509 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,5 +1,5 @@ name: Unit Tests - +run-name: ${{ github.actor }} is running Unit Tests on: pull_request: branches: @@ -13,5 +13,85 @@ jobs: unit-tests: runs-on: ubuntu-latest steps: - - name: Run Unit Tests - uses: adamzero1/temp-repo2/blob/main/.github/workflows/mageos-unit-tests.yml@main \ No newline at end of file + - 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: 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="../nx" + cp -r ${NXDIR}/nx ./ + cp ${NXDIR}/nx.json ./ + cp ${NXDIR}/package.json ./ + cp ${NXDIR}/package-lock.json ./ + cp ${NXDIR}/phpunit.mage-os.nx.xml ./phpunit.nx.xml + npm ci + npm run generate-workspace + + - 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 +