Skip to content

Commit

Permalink
Merge pull request #5 from adamzero1/nx-work-pr-test
Browse files Browse the repository at this point in the history
workflow work
  • Loading branch information
adamzero1 authored Mar 7, 2023
2 parents d00d6b6 + 2552ce7 commit 3e6b095
Showing 1 changed file with 72 additions and 26 deletions.
98 changes: 72 additions & 26 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ./
Expand All @@ -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

0 comments on commit 3e6b095

Please sign in to comment.