Files
myrzx_bot/.github/workflows/web-image.yml
T

142 lines
6.3 KiB
YAML

name: Web image
on:
push:
tags: ["v2.*"]
pull_request:
paths:
- ranch_web/**
- ranch_assistant/**
- tools/check_progression_support.py
- deploy/web/**
- Dockerfile
- .dockerignore
- compose.yaml
- .github/workflows/web-image.yml
workflow_dispatch:
permissions:
contents: read
concurrency:
group: web-image-${{ github.ref }}
cancel-in-progress: false
jobs:
image:
if: github.event.deleted != true
runs-on: ubuntu-latest
timeout-minutes: 25
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Validate source version and publish tag
id: version
env:
EVENT_NAME: ${{ github.event_name }}
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
run: |
python - <<'PY'
import os
from ranch_web import __version__
from ranch_web.updates import current_version_key, validate_image_release
current_version_key(__version__)
publish = os.environ["EVENT_NAME"] == "push" and os.environ["REF_TYPE"] == "tag"
tag = os.environ["REF_NAME"]
if publish:
validate_image_release(os.environ["REPOSITORY"], tag, __version__)
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
print(f"version={__version__}", file=output)
print(f"publish={'true' if publish else 'false'}", file=output)
print(f"tag={tag if publish else ''}", file=output)
PY
- name: Install Web runtime and test dependencies
run: python -m pip install -r ranch_web/requirements-test.txt
- name: Offline primary cultivation and resource admission regression
run: |
python -B -m unittest \
ranch_assistant.tests.test_species_retention_limits \
ranch_assistant.tests.test_primary_cultivation \
ranch_assistant.tests.test_primary_resource_admission -v
- name: Offline commission history and priority regression
run: |
python -B -m unittest \
ranch_assistant.tests.test_commission_history \
ranch_assistant.tests.test_commission_history_review \
ranch_assistant.tests.test_commission_priority \
ranch_web.tests.test_commission_history -v
- name: Offline quick battle and commission input regression
timeout-minutes: 3
run: |
python -B -m unittest \
ranch_assistant.tests.test_battle_quick \
ranch_assistant.tests.test_commission_procurement \
ranch_assistant.tests.test_snapshot_potential_anomalies \
ranch_assistant.tests.test_progression_support \
ranch_web.tests.test_commission_procurement_views -v
- name: Offline updater and task log regression
run: python -B -m unittest ranch_web.tests.test_updates ranch_web.tests.test_web_updater ranch_web.tests.test_private_updates ranch_web.tests.test_web_updater_package ranch_web.tests.test_activity ranch_web.tests.test_task_logs -v
- name: Offline battle transport, recovery, and capability regression
timeout-minutes: 3
run: |
python -B -m unittest \
ranch_assistant.tests.test_battle_worker_transport \
ranch_assistant.tests.test_battle_recovery \
ranch_assistant.tests.test_battle_capability_presentation \
ranch_web.tests.test_lifecycle_recovery -v
- name: Offline Web battle recovery contract and status API regression
timeout-minutes: 3
run: |
python -B -m unittest \
ranch_web.tests.test_battle_recovery_contract \
ranch_web.tests.test_status_recovery_api -v
- name: Offline account recovery regression
run: python -B -m unittest ranch_web.tests.test_run_intent ranch_web.tests.test_scheduler_recovery ranch_web.tests.test_auto_relogin ranch_web.tests.test_connection_state -v
- name: Build image
env:
WEB_VERSION: ${{ steps.version.outputs.version }}
VCS_REF: ${{ github.sha }}
run: docker build --build-arg "WEB_VERSION=$WEB_VERSION" --build-arg "VCS_REF=$VCS_REF" --tag ranch-web-smoke .
- name: Offline container health, persistence permissions, and graceful stop
run: |
docker run --detach --name ranch-web-smoke --network none --read-only \
--cap-drop ALL --security-opt no-new-privileges \
--tmpfs /tmp:rw,noexec,nosuid,size=64m,mode=1777 \
--tmpfs /data:rw,uid=10001,gid=10001,mode=0700 \
--env RANCH_WEB_PASSWORD=ephemeral-offline-ci-only ranch-web-smoke
for attempt in $(seq 1 35); do
health=$(docker inspect --format '{{.State.Health.Status}}' ranch-web-smoke)
if [ "$health" = healthy ]; then break; fi
if [ "$health" = unhealthy ]; then exit 1; fi
sleep 2
done
test "$health" = healthy
docker exec ranch-web-smoke python -c "import importlib.util,os,pathlib; assert os.getuid()==10001; assert importlib.util.find_spec('PySide6') is None; p=pathlib.Path('/data/.permission-check'); p.write_text('ok'); assert p.read_text()=='ok'; p.unlink()"
docker stop --time 120 ranch-web-smoke
test "$(docker inspect --format '{{.State.ExitCode}}' ranch-web-smoke)" = 0
- name: Remove smoke container
if: always()
run: docker rm --force ranch-web-smoke 2>/dev/null || true
- name: Log in to GHCR
if: steps.version.outputs.publish == 'true'
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish only the exact stable 2.x tag
if: steps.version.outputs.publish == 'true'
env:
PUBLISH_TAG: ${{ steps.version.outputs.tag }}
run: |
python -c "import os; from ranch_web.updates import stable_version; stable_version(os.environ['PUBLISH_TAG'])"
docker tag ranch-web-smoke "ghcr.io/attilanet/myrzx_bot-web:$PUBLISH_TAG"
docker push "ghcr.io/attilanet/myrzx_bot-web:$PUBLISH_TAG"