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

MacOS tests on GitHub CI/CD #635

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b799ab1
Will this work?
ribalba Dec 27, 2023
867ee38
next test
ribalba Dec 27, 2023
dd1e5e4
testing if setup works
ribalba Dec 28, 2023
a2ece1e
upterm in VM to check out whats going on
dan-mm Jan 12, 2024
032765d
updated macos action with docker install
dan-mm Jan 12, 2024
0d64a0a
missed shell
dan-mm Jan 12, 2024
1e23306
run without upterm
dan-mm Jan 12, 2024
1c1284b
add ssh back
dan-mm Jan 12, 2024
35c07d4
limit ssh access
dan-mm Jan 15, 2024
4de1277
earlier upterm to debug issue
dan-mm Jan 15, 2024
7ec92f9
see current status without ssh
dan-mm Jan 15, 2024
d0e4dbc
add test command back
dan-mm Jan 15, 2024
b8c4158
different way to generate random passwords for mac
dan-mm Feb 17, 2024
2f81e9f
Merge branch 'main' into github-action-mac
dan-mm Feb 17, 2024
0783dd1
install scripts only generate default password if one wasn't passed i…
dan-mm Feb 17, 2024
e7e2d8c
install linux/mac script: moved rest of checks in if clause; revert c…
dan-mm Feb 17, 2024
1fae7c7
- test action now has macos capabilities; dev_no_build is now default…
dan-mm Feb 23, 2024
5599288
Merge branch 'main' into github-action-mac
dan-mm Feb 23, 2024
34dd60a
no-build mode for install_mac
dan-mm Feb 23, 2024
e793525
fix flag for install_mac
dan-mm Feb 23, 2024
8837482
fix pip install command
dan-mm Feb 23, 2024
8efcbce
Merge branch 'main' into github-action-mac
dan-mm Feb 23, 2024
2edf995
remove python cache for now; revert PR workflow as we have mac workfl…
dan-mm Feb 23, 2024
308ea25
My work (#694)
ribalba Feb 27, 2024
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
83 changes: 15 additions & 68 deletions .github/actions/gmt-pytest/action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: 'GMT Pytest'
description: 'Run Pytest with setup and teardown'
inputs:
metrics-to-turn-off:
description: 'a list of metrics to turn off that is passed to the disable metrics script'
required: false
default: ''
gmt-directory:
description: 'The root directory of the gmt repository'
required: false
Expand All @@ -25,82 +21,33 @@ runs:
with:
python-version: '3.10'

- id: python_cache
uses: actions/cache@v3
with:
path: venv
key: pip-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}-${{ hashFiles('metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt') }}
# - id: python_cache
# uses: actions/cache@v3
# with:
# path: venv
# key: pip-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}-${{ hashFiles('metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt') }}

- name: install script and packages
shell: bash
working-directory: ${{ inputs.gmt-directory }}
run: |
./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -n -t
source venv/bin/activate
python3 -m pip install -r requirements-dev.txt
python3 -m pip install -r metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt

- name: disable unneeded metric providers and run test setup script
- name: Install docker for MacOS
if: runner.os == 'macOS'
shell: bash
working-directory: ${{ inputs.gmt-directory }}
run: |
source venv/bin/activate
python3 disable_metric_providers.py ${{ inputs.metrics-to-turn-off }}
cd tests && python3 setup-test-env.py --no-docker-build
bash -x ./install_mac.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142
source venv/bin/activate && pip install -r requirements-dev.txt

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ inputs.github-token }}

- name: Build docker-compose
id: build-docker-compose
shell: bash
working-directory: ${{ inputs.gmt-directory }}/docker
run: |
{ DOCKER_OUTPUT=$(docker buildx bake --file test-compose.yml --file docker-compose-cache.json 2>&1); DOCKER_EXIT_CODE=$?; } || true
if [ "$DOCKER_EXIT_CODE" -ne 0 ]; then
echo "Docker build failed with exit code $DOCKER_EXIT_CODE"
echo "buildx output:"
echo $DOCKER_OUTPUT
if echo "$DOCKER_OUTPUT" | grep -q "403 Forbidden"; then
echo "Docker build failed due to permissions issue. Continuing..."
else
exit 1
fi
fi

- name: Start Test container
- name: Build test image and start test containers
shell: bash
working-directory: ${{ inputs.gmt-directory }}/tests
working-directory: ${{ inputs.gmt-directory }}
run: |
source ../venv/bin/activate && python3 setup-test-env.py
source ../venv/bin/activate && ./start-test-containers.sh -d

- name: Sleep for 10 seconds
run: sleep 10s
shell: bash

# - name: Setup upterm session
# uses: lhotari/action-upterm@v1

- name: Run Tests
continue-on-error: true
shell: bash
working-directory: ${{ inputs.gmt-directory }}/tests
run: |
source ../venv/bin/activate
python3 -m ${{ inputs.tests-command }} -rA | tee /tmp/test-results.txt

- name: Display Results
shell: bash
if: always()
working-directory: ${{ inputs.gmt-directory }}
run: |
cat /tmp/test-results.txt | grep -oPz '(=*) short test summary(.*\n)*' >> $GITHUB_STEP_SUMMARY
source ../venv/bin/activate && python3 -m pytest -rA

- name: Stop Containers
shell: bash
Expand Down
79 changes: 0 additions & 79 deletions .github/workflows/codeql.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Install Docker on macOS

on: [push] # or any other event

jobs:
install-docker:
runs-on: macos-13

steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
submodules: 'true'

- name: Setup Docker on macOS
uses: douglascamata/setup-docker-macos-action@v1-alpha
with:
colima-network-address: 'true'

- name: 'Setup, Run, and Teardown Tests'
uses: ./.github/actions/gmt-pytest
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .github/workflows/tests-vm-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
- name: 'Setup, Run, and Teardown Tests'
uses: ./.github/actions/gmt-pytest
with:
metrics-to-turn-off: '--categories RAPL Machine Sensors Debug CGroupV2 MacOS GPU --providers PsuEnergyAcSdiaMachineProvider'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Eco CI Energy Estimation - Get Measurement
Expand Down
20 changes: 9 additions & 11 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ measurement:
#--- Architecture - MacOS
macos:
#--- MacOS: On Mac you only need this provider. Please remove all others!
powermetrics.provider.PowermetricsProvider:
resolution: 99
cpu.utilization.mach.system.provider.CpuUtilizationMachSystemProvider:
resolution: 99
#--- Architecture - Common
Expand All @@ -137,16 +135,16 @@ measurement:
#-- This is a default configuration. Please change this to your system!
# CPUChips: 1
# TDP: 65
# psu.energy.ac.xgboost.machine.provider.PsuEnergyAcXgboostMachineProvider:
# resolution: 99
psu.energy.ac.xgboost.machine.provider.PsuEnergyAcXgboostMachineProvider:
resolution: 99
#-- This is a default configuration. Please change this to your system!
# CPUChips: 1
# HW_CPUFreq: 3200
# CPUCores: 4
# CPUThreads: 4
# TDP: 65
# HW_MemAmountGB: 16
# Hardware_Availability_Year: 2011
CPUChips: 1
HW_CPUFreq: 3200
CPUCores: 4
CPUThreads: 4
TDP: 65
HW_MemAmountGB: 16
Hardware_Availability_Year: 2011
#--- END


Expand Down
10 changes: 4 additions & 6 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ if [[ -z $metrics_url ]] ; then
metrics_url=${metrics_url:-"http://metrics.green-coding.internal:9142"}
fi

if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi

default_password=${password_from_file:-$(generate_random_password 12)}

if [[ -z "$db_pw" ]] ; then
if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi
default_password=${password_from_file:-$(generate_random_password 12)}
read -sp "Please enter the new password to be set for the PostgreSQL DB (default: $default_password): " db_pw
echo "" # force a newline, because read -sp will consume it
db_pw=${db_pw:-"$default_password"}
Expand Down
45 changes: 24 additions & 21 deletions install_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ function print_message {
}

function generate_random_password() {
local length=$1
LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c "$length"
echo
echo "yourfixedinputstring" | tr -dc 'A-Za-z0-9' | head -c "$length"
}

db_pw=''
api_url=''
metrics_url=''
no_build=false

while getopts "p:a:m:" o; do
while getopts "p:a:m:n" o; do
case "$o" in
p)
db_pw=${OPTARG}
Expand All @@ -30,6 +29,9 @@ while getopts "p:a:m:" o; do
m)
metrics_url=${OPTARG}
;;
n)
no_build=true
;;
esac
done

Expand All @@ -43,13 +45,13 @@ if [[ -z $metrics_url ]] ; then
metrics_url=${metrics_url:-"http://metrics.green-coding.internal:9142"}
fi

if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi
if [[ -z "$db_pw" ]] ; then
if [[ -f config.yml ]]; then
password_from_file=$(awk '/postgresql:/ {flag=1; next} flag && /password:/ {print $2; exit}' config.yml)
fi

default_password=${password_from_file:-$(generate_random_password 12)}
default_password=${password_from_file:-$(generate_random_password 12)}

if [[ -z "$db_pw" ]] ; then
read -sp "Please enter the new password to be set for the PostgreSQL DB (default: $default_password): " db_pw
echo "" # force a newline, because read -sp will consume it
db_pw=${db_pw:-"$default_password"}
Expand Down Expand Up @@ -109,8 +111,8 @@ echo "ALL ALL=(ALL) NOPASSWD:/usr/bin/killall powermetrics" | sudo tee /etc/sudo
echo "ALL ALL=(ALL) NOPASSWD:/usr/bin/killall -9 powermetrics" | sudo tee /etc/sudoers.d/green_coding_kill_powermetrics_sigkill

print_message "Writing to /etc/hosts file..."
etc_hosts_line_1="127.0.0.1 green-coding-postgres-container"
etc_hosts_line_2="127.0.0.1 ${host_api_url} ${host_metrics_url}"
etc_hosts_line_1="192.168.106.2 green-coding-postgres-container"
etc_hosts_line_2="192.168.106.2 ${host_api_url} ${host_metrics_url}"

# Entry 1 is needed for the local resolution of the containers through the jobs.py and runner.py
if ! sudo grep -Fxq "$etc_hosts_line_1" /etc/hosts; then
Expand All @@ -129,7 +131,7 @@ if [[ ${host_metrics_url} == *".green-coding.internal"* ]];then
fi

if ! command -v stdbuf &> /dev/null; then
print_message "Trying to install 'coreutils' via homebew. If this fails (because you do not have brew or use another package manager), please install it manually ..."
print_message "Trying to install 'coreutils' via homebrew. If this fails (because you do not have brew or use another package manager), please install it manually ..."
brew install coreutils
fi

Expand All @@ -147,16 +149,17 @@ while IFS= read -r subdir; do
fi
done

print_message "Building / Updating docker containers"
docker compose -f docker/compose.yml down
docker compose -f docker/compose.yml build
docker compose -f docker/compose.yml pull

print_message "Updating python requirements"
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
python3 -m pip install -r metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt
if [[ $no_build != true ]] ; then
print_message "Building / Updating docker containers"
docker compose -f docker/compose.yml down
docker compose -f docker/compose.yml build
docker compose -f docker/compose.yml pull

print_message "Updating python requirements"
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
python3 -m pip install -r metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt
fi

echo ""
echo -e "${GREEN}Successfully installed Green Metrics Tool!${NC}"
Expand Down
2 changes: 1 addition & 1 deletion runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self,
self._uri_type = uri_type
self._original_filename = filename
self._branch = branch
self._tmp_folder = '/tmp/green-metrics-tool'
self._tmp_folder = '/Users/runner/tmp/green-metrics-tool'
self._usage_scenario = {}
self._architecture = utils.get_architecture()
self._sci = {'R_d': None, 'R': 0}
Expand Down
2 changes: 1 addition & 1 deletion tests/edit-etc-hosts.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

etc_hosts_line_1="127.0.0.1 test-green-coding-postgres-container"
etc_hosts_line_1="192.168.106.2 test-green-coding-postgres-container"

echo "Writing to /etc/hosts file..."
if ! grep -Fxq "$etc_hosts_line_1" /etc/hosts; then
Expand Down
3 changes: 3 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
no_mac_workflow: tests that cannot be run during in our mac workflows
Loading
Loading