diff --git a/.gitea/probe/pe.cs b/.gitea/probe/pe.cs new file mode 100644 index 00000000..0465517a --- /dev/null +++ b/.gitea/probe/pe.cs @@ -0,0 +1,51 @@ +// Lists the Win32 resources of PE files: icon group, version and manifest must be present in a published apphost. +using System.Reflection.PortableExecutable; +using System.Text; + +var failures = 0; +foreach (var path in args) failures += Check(path); +return failures; + +static int Check(string path) +{ + using var fs = File.OpenRead(path); + using var pe = new PEReader(fs); + var header = pe.PEHeaders.PEHeader!; + var dir = header.ResourceTableDirectory; + Console.WriteLine($"{Path.GetFileName(path)}: {fs.Length:N0} bytes, subsystem {header.Subsystem}, resources {dir.Size:N0} bytes"); + if (dir.Size == 0) { Console.WriteLine(" MISSING: no resource section"); return 1; } + var root = pe.GetSectionData(dir.RelativeVirtualAddress); + var types = new List(); + foreach (var (id, offset) in Entries(root, 0)) + { + types.Add(id); + var label = id switch { 3 => "ICON", 14 => "GROUP_ICON", 16 => "VERSION", 24 => "MANIFEST", _ => "type " + id }; + var count = 0; + foreach (var (_, nameOffset) in Entries(root, offset & 0x7FFFFFFF)) + foreach (var (_, dataOffset) in Entries(root, nameOffset & 0x7FFFFFFF)) + { + count++; + if (id != 24) continue; + var entry = root.GetReader(); + entry.Offset = (int)dataOffset; + int rva = entry.ReadInt32(), size = entry.ReadInt32(); + var block = pe.GetSectionData(rva).GetReader(); + var text = Encoding.UTF8.GetString(block.ReadBytes(Math.Min(size, block.Length))); + Console.WriteLine($" manifest {size} bytes, dpiAwareness: {text.Contains("PerMonitorV2", StringComparison.Ordinal)}"); + } + Console.WriteLine($" {label}: {count}"); + } + var ok = types.Contains(14) && types.Contains(16) && types.Contains(24); + Console.WriteLine(ok ? " OK: icon, version and manifest present" : " MISSING: icon, version or manifest"); + return ok ? 0 : 1; +} + +static List<(int Id, uint Offset)> Entries(PEMemoryBlock root, uint directoryOffset) +{ + var r = root.GetReader(); + r.Offset = (int)directoryOffset + 12; + var count = r.ReadUInt16() + r.ReadUInt16(); + var list = new List<(int, uint)>(); + for (var i = 0; i < count; i++) list.Add(((int)(r.ReadUInt32() & 0x7FFFFFFF), r.ReadUInt32())); + return list; +} diff --git a/.gitea/workflows/probe.yml b/.gitea/workflows/probe.yml new file mode 100644 index 00000000..f8e296eb --- /dev/null +++ b/.gitea/workflows/probe.yml @@ -0,0 +1,129 @@ +# Temporary probe of the Gitea runner (deleted after use): tools, contexts, services, registry, cross-publishing. +name: Probe + +on: + push: + branches: [ci-probe] + workflow_dispatch: + +permissions: + contents: read + packages: write + +jobs: + default-image: + runs-on: ubuntu-latest + steps: + - name: Environment + run: | + head -3 /etc/os-release || true + for t in bash node git docker ruby curl jq python3 pwsh 7z zip unzip openssl dotnet; do printf '%-8s %s\n' "$t" "$(command -v $t || echo -)"; done + nproc; free -m || true; df -h / /tmp | cat + echo "server_url=${{ github.server_url }} api_url=${{ github.api_url }} repo=${{ github.repository }} owner=${{ github.repository_owner }} actor=${{ github.actor }}" + echo "ref=${{ github.ref }} ref_name=${{ github.ref_name }} sha=${{ github.sha }} run=${{ github.run_number }} id=${{ github.run_id }} event=${{ github.event_name }}" + echo "GITEA_ACTIONS=$GITEA_ACTIONS GITHUB_ACTIONS=$GITHUB_ACTIONS RUNNER_OS=$RUNNER_OS RUNNER_TEMP=$RUNNER_TEMP" + echo "GITHUB_STEP_SUMMARY=$GITHUB_STEP_SUMMARY GITHUB_OUTPUT=$GITHUB_OUTPUT GITHUB_ENV=$GITHUB_ENV" + echo "vars.PROBE='${{ vars.PROBE }}' secrets.RELEASES_TOKEN set: ${{ secrets.RELEASES_TOKEN != '' }}" + ls -l /var/run/docker.sock || true + docker version 2>&1 | head -20 || true + - name: Workflow commands + run: | + echo "::notice title=Probe::a notice" + echo "::warning title=Probe::a warning" + echo "::group::a group"; echo inside; echo "::endgroup::" + echo "## Summary from the probe" >> "$GITHUB_STEP_SUMMARY" + + sdk: + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/dotnet/sdk:10.0 + services: + postgres: + image: postgres:17 + env: + POSTGRES_USER: titano + POSTGRES_PASSWORD: titano-ci + POSTGRES_DB: titano_test + defaults: + run: + shell: bash + env: + DOTNET_NOLOGO: "1" + DOTNET_CLI_TELEMETRY_OPTOUT: "1" + steps: + - name: Context + run: | + echo "job.services.postgres.id='${{ job.services.postgres.id }}' network='${{ job.services.postgres.network }}'" + echo "job.container.id='${{ job.container.id }}' network='${{ job.container.network }}'" + echo "hostname=$(hostname) workspace=$GITHUB_WORKSPACE pwd=$(pwd) user=$(id)" + getent hosts postgres || echo "postgres does not resolve" + ls -l /var/run/docker.sock || true + for t in node git docker ruby curl jq python3 openssl 7z zip unzip pwsh tar gzip; do printf '%-8s %s\n' "$t" "$(command -v $t || echo -)"; done + nproc; free -m; df -h / /tmp "$GITHUB_WORKSPACE" | cat + dotnet --list-sdks + head -3 /etc/os-release + - name: Checkout with git (no node) + env: + TOKEN: ${{ github.token }} + run: | + git config --global --add safe.directory "$PWD" + git init -q . + git remote add origin "${{ github.server_url }}/${{ github.repository }}.git" + auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0) + time git -c http.extraheader="Authorization: basic $auth" fetch -q --depth=1 origin "${{ github.sha }}" + git checkout -q FETCH_HEAD + git log --oneline -1 + - name: PostgreSQL service reachable + run: | + for i in $(seq 1 90); do + if (echo > /dev/tcp/postgres/5432) 2>/dev/null; then echo "postgres:5432 open after ${i}s"; break; fi + sleep 1 + done + - name: Build Tools, cross-publish App and Setup (win-x64) + run: | + set -o pipefail + time dotnet build src/Titano.Tools/Titano.Tools.csproj -c Release -nologo -clp:NoSummary 2>&1 | tail -5 + common="-c Release -r win-x64 --self-contained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=none -nologo" + time dotnet publish src/Titano.App/Titano.App.csproj $common -p:PublishReadyToRun=true -o out/app 2>&1 | tail -15 + time dotnet publish src/Titano.Setup/Titano.Setup.csproj $common -p:PublishReadyToRun=true -o out/setup 2>&1 | tail -15 + time dotnet publish src/Titano.Server/Titano.Server.csproj $common -o out/server 2>&1 | tail -5 + ls -la out/app out/setup out/server + - name: PE resources of the cross-published programs + run: | + mkdir -p /tmp/pecheck && cp .gitea/probe/pe.cs /tmp/pecheck/pe.cs + cd /tmp/pecheck && dotnet run pe.cs -- "$GITHUB_WORKSPACE/out/app/Titano.exe" "$GITHUB_WORKSPACE/out/setup/Titano.Setup.exe" "$GITHUB_WORKSPACE/out/server/Titano.Server.exe" + - name: Pack an installer on Linux + run: | + dotnet src/Titano.Tools/bin/Release/net10.0/Titano.Tools.dll pack-installer --setup out/setup/Titano.Setup.exe --product Titano \ + --component "Titano=out/app" --version 0.0.1 --out out/Titano-Setup-0.0.1.exe + ls -la out/*.exe + cd /tmp/pecheck && dotnet run pe.cs -- "$GITHUB_WORKSPACE/out/Titano-Setup-0.0.1.exe" + + docker-cli: + runs-on: ubuntu-latest + container: + image: docker:27-cli + steps: + - name: Host daemon through the socket + run: | + docker version + docker info --format 'name={{.Name}} os={{.OperatingSystem}} arch={{.Architecture}} cpus={{.NCPU}} mem={{.MemTotal}} root={{.DockerRootDir}}' + docker info --format '{{json .RegistryConfig.IndexConfigs}}' + docker buildx version || true + docker buildx ls || true + docker image ls --format '{{.Repository}}:{{.Tag}} {{.Size}}' | head -30 + - name: Registry login (client) and pull (daemon) + env: + TOKEN: ${{ github.token }} + run: | + for host in gitea.encke-hake.ts.net 192.168.30.23:3000; do + if echo "$TOKEN" | docker login "$host" -u "${{ github.actor }}" --password-stdin; then echo "login $host OK"; else echo "login $host FAILED"; fi + docker pull "$host/balbosoft/chronos-probe-missing:latest" 2>&1 | tail -2 || true + done + + ruby: + runs-on: ubuntu-latest + container: + image: ruby:3.3-alpine + steps: + - run: ruby -v && ruby -ryaml -e 'puts YAML.safe_load("a: 1").inspect' && (command -v git || echo "no git")