diff --git a/.github/actions/gmt-pytest/action.yml b/.github/actions/gmt-pytest/action.yml index 4d0e104a9..638499c3a 100644 --- a/.github/actions/gmt-pytest/action.yml +++ b/.github/actions/gmt-pytest/action.yml @@ -31,87 +31,23 @@ runs: if: runner.os == 'macOS' shell: bash run: | - brew install docker docker-compose - mkdir -p ~/.docker/cli-plugins - ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose - colima start --network-address + 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: GMT Install - shell: bash - working-directory: ${{ inputs.gmt-directory }} - run: | - if [ "$RUNNER_OS" = "macOS" ]; then - ./install_mac.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -n - else # linux - ./install_linux.sh -p testpw -a http://api.green-coding.internal:9142 -m http://metrics.green-coding.internal:9142 -n -t - fi - 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 - cd tests - python3 setup-test-env.py --no-docker-build - - - 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: Build test image and start test containers shell: bash working-directory: ${{ inputs.gmt-directory }} run: | - source venv/bin/activate - cd tests - ./start-test-containers.sh -d - sleep 10 - cd stress-application - docker build . -t gcb_stress_gmt_run_tmp + source ../venv/bin/activate && python3 setup-test-env.py + source ../venv/bin/activate && ./start-test-containers.sh -d - name: Run Tests continue-on-error: true shell: bash working-directory: ${{ inputs.gmt-directory }} run: | - source venv/bin/activate - cd tests - if [ "$RUNNER_OS" = "macOS" ]; then - python3 -m pytest -m "not no_mac_workflow" -rA | tee /tmp/test-results.txt - else # linux - python3 -m ${{ inputs.tests-command }} -rA | tee /tmp/test-results.txt - fi - - - name: Display Results - shell: bash - if: always() - run: | - if [ "$RUNNER_OS" = "macOS" ]; then - cat /tmp/test-results.txt | grep -Eo '(=*) short test summary(.*\n)*' >> $GITHUB_STEP_SUMMARY - else # linux - cat /tmp/test-results.txt | grep -oPz '(=*) short test summary(.*\n)*' >> $GITHUB_STEP_SUMMARY - fi + source ../venv/bin/activate && python3 -m pytest -rA - name: Stop Containers shell: bash diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 38a577c01..000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,79 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - analyze: - name: Analyze - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners - # Consider using larger runners for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript-typescript', 'python' ] - # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] - # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - queries: security-extended - - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml new file mode 100644 index 000000000..9a2a46382 --- /dev/null +++ b/.github/workflows/docker-test.yml @@ -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 }} diff --git a/config.yml.example b/config.yml.example index aa9704375..9b0d1ca67 100644 --- a/config.yml.example +++ b/config.yml.example @@ -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 @@ -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 diff --git a/install_mac.sh b/install_mac.sh index bad48df59..9df3e4fd1 100755 --- a/install_mac.sh +++ b/install_mac.sh @@ -10,9 +10,7 @@ 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='' @@ -51,7 +49,9 @@ 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"} @@ -111,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 diff --git a/runner.py b/runner.py index 9f6899a8a..0b7db35ab 100755 --- a/runner.py +++ b/runner.py @@ -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} diff --git a/tests/edit-etc-hosts.sh b/tests/edit-etc-hosts.sh index 74780a18e..054c1ead5 100755 --- a/tests/edit-etc-hosts.sh +++ b/tests/edit-etc-hosts.sh @@ -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