Skip to content

Commit

Permalink
Build and run on windows on GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Nov 20, 2023
1 parent 07fa48e commit 5fac09c
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 43 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/buildNative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
HYDRA_NATIVE_BUILD: true
runs-on: ${{ matrix.os }}
steps:
- name: Log free memory
- if: startsWith(matrix.os,'ubuntu')
name: Log free memory
run: free -s 1 -h -c 3
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -59,6 +60,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: "Install all with Maven"
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: mvn --batch-mode clean install -pl !org.nzbhydra:linux-amd64-release,!org.nzbhydra:linux-arm64-release,!org.nzbhydra:windows-release,!org.nzbhydra:generic-release -DskipTests -T 1C

- name: "Run unit tests"
Expand All @@ -80,28 +82,35 @@ jobs:
mvn --batch-mode -Pnative clean native:compile -DskipTests
- name: "Upload linux artifact"
if: steps.changed-files-specific.outputs.any_changed == 'true'
if: steps.changed-files-specific.outputs.any_changed == 'true' && startsWith(matrix.os,'ubuntu')
uses: actions/upload-artifact@v3
with:
name: coreLinux
path: core/target/core

- name: "Upload windows artifact"
if: steps.changed-files-specific.outputs.any_changed == 'true' && startsWith(matrix.os,'windows')
uses: actions/upload-artifact@v3
with:
name: coreWindows
path: core/target/core.exe

- name: "Copy artifact to include folder"
if: steps.changed-files-specific.outputs.any_changed == 'true'
if: steps.changed-files-specific.outputs.any_changed == 'true' && startsWith(matrix.os,'ubuntu')
run: |
mv core/target/core ./docker/nativeTest/
chmod +x ./docker/nativeTest/core
- name: "Login to GitHub Container Registry"
if: steps.changed-files-specific.outputs.any_changed == 'true'
if: steps.changed-files-specific.outputs.any_changed == 'true' && startsWith(matrix.os,'ubuntu')
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "Build core and push container"
if: steps.changed-files-specific.outputs.any_changed == 'true'
- name: "Build and push core container"
if: steps.changed-files-specific.outputs.any_changed == 'true' && startsWith(matrix.os,'ubuntu')
run: |
cp other/wrapper/nzbhydra2wrapperPy3.py ./docker/nativeTest/
cd ./docker/nativeTest/
Expand Down
139 changes: 129 additions & 10 deletions .github/workflows/system-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ jobs:
docker tag mockserver:3.1.0 ghcr.io/theotherp/mockserver:3.1.0
docker push ghcr.io/theotherp/mockserver:3.1.0
runSystemTests:
runSystemTestsLinux:
needs: [ waitForNative, buildMockserver ]
runs-on: ubuntu-latest
strategy:
matrix:
test: [ { port: 5076, name: core }, { port: 5077, name: v1Migration } ]
env:
spring_profiles_active: build,systemtest,${{ matrix.test.name }}
spring_profiles_active: build,systemtest,testdocker,${{ matrix.test.name }}
nzbhydra_port: ${{ matrix.test.port }}
nzbhydra.port: ${{ matrix.test.port }}
nzbhydra_name: ${{ matrix.test.name }}
Expand All @@ -83,8 +83,8 @@ jobs:
distribution: 'adopt'
cache: 'maven'

- name: "Install"
run: mvn --batch-mode clean install -DskipTests -pl org.nzbhydra:nzbhydra2,org.nzbhydra:shared,org.nzbhydra:mapping,org.nzbhydra:assertions
- name: "Install maven"
run: mvn --batch-mode clean install -DskipTests -pl org.nzbhydra:nzbhydra2,org.nzbhydra:shared,org.nzbhydra:mapping,org.nzbhydra:assertions

- name: "Create docker network"
run: docker network create systemtest
Expand All @@ -96,9 +96,9 @@ jobs:
- name: "Run docker compose"
run: |
cd docker
cd docker/docker-compose-systemtest/linux
docker-compose up -d
cd ..
cd ../../..
- name: "Wait for healthy containers"
run: |
Expand All @@ -118,7 +118,7 @@ jobs:
- name: "Write docker-compose logs"
if: always()
run: |
cd docker
cd docker/docker-compose-systemtest/linux
echo "Writing docker compose logs to files"
docker-compose logs --no-color radarr > docker-compose-radarr.log
docker-compose logs --no-color sonarr > docker-compose-sonarr.log
Expand All @@ -127,19 +127,20 @@ jobs:
docker-compose logs --no-color v1Migration > docker-compose-v1Migration.log
echo "Found log files:"
find . -name "*.log"
cd ..
cd ../../..
- name: "Truncate large log files"
if: always()
# If the logs are larger than 1MB there's probably something wrong
run: |
shopt -s globstar
for d in ./**/*.log ; do (truncate --size=1M $d); done
- name: "Upload data folder artifact"
uses: actions/upload-artifact@v3
if: always()
with:
name: data
name: dataLinux
path: /tmp/hydra

- name: "Upload test logs artifact"
Expand All @@ -154,7 +155,7 @@ jobs:
if: always()
with:
name: ${{ matrix.test.name }}-docker-logs
path: docker/*.log
path: docker/docker-compose-systemtest/linux/*.log

- name: "Create test Report"
uses: dorny/test-reporter@v1
Expand All @@ -164,3 +165,121 @@ jobs:
name: System test report ${{ matrix.test.name }}
path: "**/surefire-reports/*.xml"
reporter: java-junit




runSystemTestsWindows:
needs: [ waitForNative, buildMockserver ]
runs-on: windows-latest
env:
spring_profiles_active: build,systemtest,core,testwindows
nzbhydra_port: 5076
nzbhydra.port: 5076
nzbhydra_name: windows
NZBHYDRANAME: windows
nzbhydra.name: windows
steps:
- name: "Check out source"
uses: actions/checkout@v3

- name: "Download windows artifact from current workflow"
id: "downloadArtifactThisBuild"
continue-on-error: true
uses: actions/download-artifact@master
with:
name: coreWindows
path: ./

- name: "Check if core.exe was downloaded"
id: checkCoreExe
uses: andstor/file-existence-action@v1
with:
files: core.exe

- name: "Download windows artifact from previous workflow if no native build was executed"
if: ${{steps.checkCoreExe.outputs.files_exists == 'false'}}
uses: dawidd6/action-download-artifact@v2
with:
name: coreWindows
#Search for matching artifact in any of the last completed workflows
search_artifacts: true
workflow_conclusion: 'completed'
path: .

- name: "Set up JDK 17"
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'maven'

- name: "Install maven"
run: mvn --batch-mode clean install -DskipTests -pl org.nzbhydra:nzbhydra2,org.nzbhydra:shared,org.nzbhydra:mapping,org.nzbhydra:assertions,org.nzbhydra:mockserver

- name: "Copy mockserver"
run: |
copy other/mockserver/target/*-exec.jar exec.jar
- name: "List files in folder"
run: ls

- name: "Add mockserver to /etc/hosts"
run: |
$file = "C:\Windows\System32\drivers\etc\hosts"
$hostfile = Get-Content $file
$hostfile += "127.0.0.1 mockserver"
Set-Content -Path $file -Value $hostfile -Force
- name: "Start mock server and hydra, run tests"
uses: BerniWittmann/background-server-action@v1
with:
start: ./core.exe directstart, java -jar ./exec.jar
command: mvn --batch-mode test -pl org.nzbhydra.tests:system -DtrimStackTrace=false

- name: "Shutdown hydra"
uses: fjogeleit/http-request-action@v1
if: always()
continue-on-error: true
with:
method: "GET"
url: "http://127.0.0.1:5076/internalapi/control/shutdown"

- name: "Shutdown mockserver"
uses: fjogeleit/http-request-action@v1
if: always()
continue-on-error: true
with:
method: "POST"
url: "http://127.0.0.1:5080/actuator/shutdown"

- name: "Upload data folder artifact"
uses: actions/upload-artifact@v3
if: always()
continue-on-error: true
with:
name: dataWindows
path: data

- name: "Upload test logs artifact"
uses: actions/upload-artifact@v3
if: always()
with:
name: windows-test-logs
path: tests/**/*.log

- name: "Upload docker logs artifact"
uses: actions/upload-artifact@v3
if: always()
with:
name: windows-docker-logs
path: docker/*.log

- name: "Create test Report"
uses: dorny/test-reporter@v1
if: always()
continue-on-error: true
with:
name: System test report windows
path: "**/surefire-reports/*.xml"
reporter: java-junit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
main.useCsrf=false
nzbhydra.changelogUrl=http://mockserver:5080/changelog
nzbhydra.repositoryBaseUrl=http://mockserver:5080/repos/theotherp/nzbhydra2
nzbhydra.newsUrl=http://mockserver:5080/static/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- PGID=1000
- TZ=Europe/London
volumes:
- ./sonarr/data:/config
- ../../sonarr/data:/config
ports:
- "8989:8989"
networks: [ "systemtest" ]
Expand All @@ -33,7 +33,7 @@ services:
- PGID=1000
- TZ=Europe/London
volumes:
- ./radarr/data:/config
- ../../radarr/data:/config
ports:
- "7878:7878"
networks: [ "systemtest" ]
Expand Down
37 changes: 37 additions & 0 deletions docker/docker-compose-systemtest/windows/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3'
services:
mockserver:
image: ghcr.io/theotherp/mockserver:3.1.0
container_name: mockserver
ports:
- "5080:5080"
environment:
- spring_profiles_active=build,systemtest
network_mode: "host"
restart: unless-stopped
sonarr:
image: lscr.io/linuxserver/sonarr:latest
container_name: sonarr
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ../../sonarr/data:/config
ports:
- "8989:8989"
network_mode: "host"
restart: unless-stopped
radarr:
image: lscr.io/linuxserver/radarr:latest
container_name: radarr
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ../../radarr/data:/config
ports:
- "7878:7878"
network_mode: "host"
restart: unless-stopped
3 changes: 1 addition & 2 deletions docker/radarr/data/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<LaunchBrowser>True</LaunchBrowser>
<ApiKey>apikey</ApiKey>
<AuthenticationMethod>Basic</AuthenticationMethod>
<Branch>nightly</Branch>
<Branch>master</Branch>
<SslCertPath></SslCertPath>
<SslCertPassword></SslCertPassword>
<InstanceName>Radarr</InstanceName>
<AuthenticationRequired>DisabledForLocalAddresses</AuthenticationRequired>
</Config>
6 changes: 5 additions & 1 deletion other/mockserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@
<version>3.0.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
4 changes: 3 additions & 1 deletion other/mockserver/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
server.port=5080
#spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/
warnLogCategory
management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
14 changes: 11 additions & 3 deletions other/wrapper/pyInstaller/windows/nzbhydra2wrapperWindows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3

import logging
# (C) Copyright 2023 TheOtherP ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,12 +16,20 @@
# Just for pyinstaller

import sys
import time

import nzbhydra2wrapperPy3
import systemTray

if __name__ == '__main__':
thread = systemTray.start()
nzbhydra2wrapperPy3.quiet = True
nzbhydra2wrapperPy3.main(sys.argv[1:])
systemTray.stop()
try:
nzbhydra2wrapperPy3.main(sys.argv[1:])
systemTray.stop()
except SystemExit as e:
logging.getLogger('root').info("Wrapper main thread quit")
# For some reason thread / process is kept alive without sleeping
time.sleep(1)
systemTray.stop()
sys.exit(e.code)
2 changes: 1 addition & 1 deletion other/wrapper/pyInstaller/windows/systemTray.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def shutdown():
if result.status_code != 200:
nzbhydra2wrapperPy3.process.terminate()
stop()
elif nzbhydra2wrapperPy3.process is not None:
elif hasattr(nzbhydra2wrapperPy3, "process") and nzbhydra2wrapperPy3.process is not None:
nzbhydra2wrapperPy3.process.terminate()
stop()
else:
Expand Down
Loading

0 comments on commit 5fac09c

Please sign in to comment.