Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow work #5

Merged
merged 10 commits into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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