From 004a8384478433e4e52646fe7734ce661a379bab Mon Sep 17 00:00:00 2001 From: SuhEugene <32931701+SuhEugene@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:39:57 +0300 Subject: [PATCH] Feat: Enable tests CI --- .github/workflows/test.yml | 81 ++++++++++--------------- scripts/install-spaceman-dmm.sh | 10 +-- test/run-test.sh | 12 ++-- tools/dmitool/check_icon_state_limit.py | 19 ++++-- 4 files changed, 55 insertions(+), 67 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 594b5f0b6f..d24c031a92 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,53 +1,55 @@ name: Тестирование +permissions: + contents: read + on: workflow_dispatch: - push: - branches: - - master pull_request: branches: - - master - - merge-02-05-2021 - - testing + - master220 env: BYOND_MAJOR: "514" - BYOND_MINOR: "1557" - SPACEMAN_DMM_VERSION: suite-1.7 + BYOND_MINOR: "1589" + SPACEMAN_DMM_VERSION: suite-1.7.3 jobs: + PreFlight: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - name: paths-filter + uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 + id: filter + with: + filters: .github/workflow-config/preflight-filters.yml + outputs: + dm: ${{ steps.filter.outputs.dm }} DreamChecker: runs-on: ubuntu-latest + needs: PreFlight + if: needs.PreFlight.outputs.dm == 'true' steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: Setup Cache - uses: actions/cache@v2 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: - path: $HOME/spaceman_dmm/$SPACEMAN_DMM_VERSION + path: ~/spaceman_dmm/${{ env.SPACEMAN_DMM_VERSION }} key: ${{ runner.os }}-spacemandmm-${{ env.SPACEMAN_DMM_VERSION }} - name: Install Dreamchecker run: scripts/install-spaceman-dmm.sh dreamchecker - name: Run Dreamchecker run: ~/dreamchecker - - name: Run Failure Webhook - env: - JOB_STATUS: ${{ job.status }} - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - HOOK_OS_NAME: ${{ runner.os }} - WORKFLOW_NAME: ${{ github.workflow }} - if: ${{ failure() }} - run: | - wget https://raw.githubusercontent.com/DiscordHooks/github-actions-discord-webhook/master/send.sh - chmod +x send.sh - ./send.sh failure $WEBHOOK_URL Code: runs-on: ubuntu-latest + needs: DreamChecker steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: Setup Cache - uses: actions/cache@v2 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: - path: $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR} + path: ~/BYOND-${{ env.BYOND_MAJOR }}.${{ env.BYOND_MINOR }} key: ${{ runner.os }}-byond-${{ env.BYOND_MAJOR }}-${{ env.BYOND_MINOR }} - name: Install Dependencies run: sudo apt-get install -y uchardet @@ -55,26 +57,16 @@ jobs: env: TEST: CODE run: test/run-test.sh - - name: Run Failure Webhook - env: - JOB_STATUS: ${{ job.status }} - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - HOOK_OS_NAME: ${{ runner.os }} - WORKFLOW_NAME: ${{ github.workflow }} - if: ${{ failure() }} - run: | - wget https://raw.githubusercontent.com/DiscordHooks/github-actions-discord-webhook/master/send.sh - chmod +x send.sh - ./send.sh failure $WEBHOOK_URL Maps: runs-on: ubuntu-latest + needs: DreamChecker strategy: matrix: - map_path: [example, sierra, torch, bearcat_inf, away_sites_testing] + map_path: [example, sierra, away_sites_testing] steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - name: Setup Cache - uses: actions/cache@v2 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 with: path: $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR} key: ${{ runner.os }}-byond-${{ env.BYOND_MAJOR }}-${{ env.BYOND_MINOR }} @@ -83,14 +75,3 @@ jobs: TEST: MAP MAP_PATH: ${{ matrix.map_path }} run: test/run-test.sh - - name: Run Failure Webhook - env: - JOB_STATUS: ${{ job.status }} - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - HOOK_OS_NAME: ${{ runner.os }} - WORKFLOW_NAME: ${{ github.workflow }} - if: ${{ failure() }} - run: | - wget https://raw.githubusercontent.com/DiscordHooks/github-actions-discord-webhook/master/send.sh - chmod +x send.sh - ./send.sh failure $WEBHOOK_URL diff --git a/scripts/install-spaceman-dmm.sh b/scripts/install-spaceman-dmm.sh index ccb544bced..7321d48174 100755 --- a/scripts/install-spaceman-dmm.sh +++ b/scripts/install-spaceman-dmm.sh @@ -1,15 +1,15 @@ #!/bin/bash set -euo pipefail -if [ -f "$HOME/spaceman_dmm/$SPACEMAN_DMM_VERSION/$1" ]; +if [ -f ~/spaceman_dmm/$SPACEMAN_DMM_VERSION/$1 ]; then echo "Using cached $1." - cp "$HOME/spaceman_dmm/$SPACEMAN_DMM_VERSION/$1" ~/$1 + cp ~/spaceman_dmm/$SPACEMAN_DMM_VERSION/$1 ~/$1 else wget -O ~/$1 "https://github.com/SpaceManiac/SpacemanDMM/releases/download/$SPACEMAN_DMM_VERSION/$1" - mkdir -p $HOME/spaceman_dmm - cp ~/$1 $HOME/spaceman_dmm/$SPACEMAN_DMM_VERSION + mkdir -p ~/spaceman_dmm + cp ~/$1 ~/spaceman_dmm/$SPACEMAN_DMM_VERSION fi chmod +x ~/$1 -~/$1 --version \ No newline at end of file +~/$1 --version diff --git a/test/run-test.sh b/test/run-test.sh index 2c2f7fa1d3..48d477b2a5 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -198,8 +198,8 @@ function run_code_tests { find_code_deps pip install --user PyYaml -q pip install --user beautifulsoup4 -q + pip install --user Pillow -q shopt -s globstar - run_test "check unit tests contains all maps" "scripts/validateTestingContainsAllMaps.sh" run_test_fail "maps contain no step_[xy]" "grep 'step_[xy]' maps/**/*.dmm" run_test_fail "maps contain no layer adjustments" "grep 'layer = ' maps/**/*.dmm" run_test_fail "maps contain no plane adjustments" "grep 'plane = ' maps/**/*.dmm" @@ -207,12 +207,12 @@ function run_code_tests { run_test_fail "no invalid spans" "grep -En \"<\s*span\s+class\s*=\s*('[^'>]+|[^'>]+')\s*>\" **/*.dm" run_test "code quality checks" "test/check-paths.sh" run_test "indentation check" "awk -f tools/indentation.awk **/*.dm" - run_test "check changelog example unchanged" "md5sum -c - <<< 'a4d3afef6ced70921c88d229b2c21af5 *html/changelogs_infinity/example.yml'" + run_test "check changelog example unchanged" "md5sum -c - <<< '683a3e0d21b90581ae6e4c95052d461e *html/changelogs/example.yml'" run_test "check tags" "python3 tools/TagMatcher/tag-matcher.py ." run_test "check color hex" "python3 tools/ColorHexChecker/color-hex-checker.py ." run_test "check punctuation" "python3 tools/PunctuationChecker/punctuation-checker.py ." - run_test "check icon state limit" "python3 tools/dmitool/check_icon_state_limit.py ." - run_test_ci "check changelog builds" "python3 tools/changelog/ss13_ru_genchangelog.py html/changelog_infinity.html html/changelogs_infinity" + run_test "check icon state limit" "python3 test/check_icon_state_limit.py ." + run_test_ci "check changelog builds" "python3 tools/changelog/ss13_genchangelog.py html/changelog.html html/changelogs" } function run_byond_tests { @@ -226,10 +226,8 @@ function run_byond_tests { if [[ "$CI" == "true" ]]; then msg "installing BYOND" ./install-byond.sh || exit 1 - source $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}/byond/bin/byondsetup + source ~/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}/byond/bin/byondsetup fi - run_test_ci "check globals build" "python3 tools/GenerateGlobalVarAccess/gen_globals.py baystation12.dme code/_helpers/global_access.dm" - run_test "check globals unchanged" "md5sum -c - <<< '7686dffa04ef8cd53faa2b967c12707a *code/_helpers/global_access.dm'" run_test "build map unit tests" "scripts/dm.sh -DUNIT_TEST -M$MAP_PATH baystation12.dme" run_test "check no warnings in build" "grep ', 0 warnings' build_log.txt" run_test "run unit tests" "DreamDaemon baystation12.dmb -invisible -trusted -core 2>&1 | tee log.txt" diff --git a/tools/dmitool/check_icon_state_limit.py b/tools/dmitool/check_icon_state_limit.py index 92efb57753..c436cc3649 100644 --- a/tools/dmitool/check_icon_state_limit.py +++ b/tools/dmitool/check_icon_state_limit.py @@ -1,24 +1,33 @@ import argparse, re, sys from os import path, walk -import dmitool # This import is why this script is here. If someone can import this file cleanly from [repo root]/test/ instead, feel free +from PIL import Image opt = argparse.ArgumentParser() opt.add_argument('dir', help='The directory to scan for *.dmi files with an excess number of icon states.') args = opt.parse_args() +STATE_PATTERN = r'^state\s*=' + +def get_states_count(path): + try: + im = Image.open(path) + return len(re.findall(STATE_PATTERN, im.info["Description"], re.MULTILINE)) + except (Image.UnidentifiedImageError): + print("{0} is not a valid image".format(path)) + exit(1) + if(not path.isdir(args.dir)): print('Not a directory') sys.exit(1) - + bad_dmi_files = [] - + # This section parses all *.dmi files in the given directory, recursively. for root, subdirs, files in walk(args.dir): for filename in files: if filename.endswith('.dmi'): file_path = path.join(root, filename) - dmi_info = dmitool.info(file_path) - number_of_icon_states = len(dmi_info["states"]) + number_of_icon_states = get_states_count(file_path) if number_of_icon_states > 512: bad_dmi_files.append((file_path, number_of_icon_states))