Skip to content

Commit

Permalink
support of NC26(#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <[email protected]>
Co-authored-by: Andrey Borysenko <[email protected]>
  • Loading branch information
bigcat88 and andrey18106 authored Jul 13, 2023
1 parent 27c42d1 commit 8cefdd2
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 61 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ jobs:
working-directory: apps/${{ env.APP_NAME }}
run: composer i

- name: Set up & run Nextcloud
- name: Set up Nextcloud
env:
DB_PORT: 4444
run: |
mkdir data
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 \
--database-port=$DB_PORT --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass admin
./occ config:system:set loglevel --value=0 --type=integer
./occ config:system:set debug --value=true --type=boolean
./occ config:system:set allow_local_remote_servers --value true
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Tests

on:
pull_request:
paths:
- '.github/workflows/tests.yml'
- 'lib/**'
push:
branches: [main]
paths:
- '.github/workflows/tests.yml'
- 'lib/**'
workflow_dispatch:

jobs:
nc-py-api-pgsql:
runs-on: ubuntu-22.04
name: NC_Py_API • ${{ matrix.server-version }} • 🐘${{ matrix.php-version }} • PgSQL
strategy:
fail-fast: false
matrix:
php-version: [ '8.1' ]
server-version: [ 'stable26', 'stable27' ]
include:
- server-version: "master"
php-version: "8.2"
env:
NEXTCLOUD_URL: "http://localhost:8080/index.php"
APP_ID: "nc_py_api"
APP_PORT: 9009
APP_VERSION: "1.0.0"
APP_SECRET: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E"
SKIP_NC_WO_AE: 1

services:
postgres:
image: ghcr.io/nextcloud/continuous-integration-postgres-14:latest
ports:
- 4444:5432/tcp
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: rootpassword
POSTGRES_DB: nextcloud
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5

steps:
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Set app env
run: echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV

- name: Checkout server
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
submodules: true
repository: nextcloud/server
ref: ${{ matrix.server-version }}

- name: Checkout AppEcosystemV2
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2
with:
php-version: ${{ matrix.php-versions }}
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check composer file existence
id: check_composer
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
with:
files: apps/${{ env.APP_NAME }}/composer.json

- name: Set up dependencies
if: steps.check_composer.outputs.files_exists == 'true'
working-directory: apps/${{ env.APP_NAME }}
run: composer i

- name: Set up Nextcloud
env:
DB_PORT: 4444
run: |
mkdir data
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 \
--database-port=$DB_PORT --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass admin
./occ config:system:set allow_local_remote_servers --value true
./occ app:enable --force ${{ env.APP_NAME }}
patch -p 1 -i apps/${{ env.APP_NAME }}/base_php.patch
- name: Run Nextcloud
run: php -S 127.0.0.1:8080 &

- name: Checkout NcPyApi
uses: actions/checkout@v3
with:
path: nc_py_api
repository: cloud-py-api/nc_py_api

- name: Install NcPyApi
working-directory: nc_py_api
run: python3 -m pip -v install ".[dev]"

- name: Register NcPyApi
run: |
cd nc_py_api
python3 tests/_install.py &
echo $! > /tmp/_install.pid
cd ..
sleep 5s
php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0
php occ app_ecosystem_v2:app:register \
"{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_id\":1,\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"host\":\"localhost\",\"port\":$APP_PORT,\"system_app\":1}" \
-e --force-scopes
kill -15 $(cat /tmp/_install.pid)
timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null
- name: Run NC_Py_API tests
working-directory: nc_py_api
run: python3 -m pytest

- name: Upload NC logs
if: always()
uses: actions/upload-artifact@v3
with:
name: nc_py_api_${{ matrix.server-version }}_${{ matrix.php-version }}_nextcloud.log
path: data/nextcloud.log
if-no-files-found: warn
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Tests - Deploy](https://github.com/cloud-py-api/app_ecosystem_v2/actions/workflows/tests-deploy.yml/badge.svg)](https://github.com/cloud-py-api/app_ecosystem_v2/actions/workflows/tests-deploy.yml)
[![Tests](https://github.com/cloud-py-api/app_ecosystem_v2/actions/workflows/tests.yml/badge.svg)](https://github.com/cloud-py-api/app_ecosystem_v2/actions/workflows/tests.yml)
[![Docs](https://github.com/cloud-py-api/app_ecosystem_v2/actions/workflows/docs.yml/badge.svg)](https://cloud-py-api.github.io/app_ecosystem_v2/)

# Nextcloud App Ecosystem V2
Expand Down
6 changes: 3 additions & 3 deletions lib/Command/Daemon/ListDaemons.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$daemonConfigs = $this->daemonConfigService->getRegisteredDaemonConfigs();
if ($daemonConfigs === null) {
$output->writeln('<error>Failed to get list of daemons.</error>');
return Command::FAILURE;
return 1;
}

if (count($daemonConfigs) === 0) {
$output->writeln('No registered daemon configs.');
return Command::SUCCESS;
return 0;
}

$output->writeln('Registered ExApp daemon configs:');
foreach ($daemonConfigs as $daemon) {
$output->writeln(sprintf('%s. %s [%s]: %s://%s', $daemon->getId(), $daemon->getDisplayName(), $daemon->getAcceptsDeployId(), $daemon->getProtocol(), $daemon->getHost()));
}

return Command::SUCCESS;
return 0;
}
}
4 changes: 2 additions & 2 deletions lib/Command/Daemon/RegisterDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($daemonConfig === null) {
$output->writeln('Failed to register daemon.');
return Command::FAILURE;
return 1;
}

$output->writeln(sprintf('Daemon successfully registered. Daemon config ID: %s', $daemonConfig->getId()));
return Command::SUCCESS;
return 0;
}
}
6 changes: 3 additions & 3 deletions lib/Command/Daemon/UnregisterDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$daemonConfig = $this->daemonConfigService->getDaemonConfig($daemonConfigId);
if ($daemonConfig === null) {
$output->writeln('Daemon config not found.');
return Command::FAILURE;
return 1;
}

if ($this->daemonConfigService->unregisterDaemonConfig($daemonConfig) === null) {
$output->writeln('Failed to unregister daemon config.');
return Command::FAILURE;
return 1;
}

$output->writeln('Daemon config unregistered.');
return Command::SUCCESS;
return 0;
}
}
16 changes: 8 additions & 8 deletions lib/Command/ExApp/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$pathToInfoXml = $input->getOption('info-xml');
if ($pathToInfoXml === null) {
$output->writeln(sprintf('No info.xml specified for %s', $appId));
return Command::INVALID;
return 2;
}

$infoXml = simplexml_load_file($pathToInfoXml);
if ($infoXml === false) {
$output->writeln(sprintf('Failed to load info.xml from %s', $pathToInfoXml));
return Command::INVALID;
return 2;
}
if ($appId !== (string) $infoXml->id) {
$output->writeln(sprintf('ExApp appid %s does not match appid in info.xml (%s)', $appId, $infoXml->id));
return Command::INVALID;
return 2;
}

$exApp = $this->service->getExApp($appId);
if ($exApp !== null) {
$output->writeln(sprintf('ExApp %s already deployed and registered.', $appId));
return Command::INVALID;
return 2;
}

$daemonConfigId = (int) $input->getArgument('daemon-config-id');
$daemonConfig = $this->daemonConfigService->getDaemonConfig($daemonConfigId);
if ($daemonConfig === null) {
$output->writeln(sprintf('Daemon config %s not found.', $daemonConfigId));
return Command::INVALID;
return 2;
}
$deployConfig = $daemonConfig->getDeployConfig();

Expand Down Expand Up @@ -151,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (isset($pullResult['error'])) {
$output->writeln(sprintf('ExApp %s deployment failed. Error: %s', $appId, $pullResult['error']));
return Command::FAILURE;
return 1;
}

if (!isset($startResult['error']) && isset($createResult['Id'])) {
Expand All @@ -168,14 +168,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];
if ($this->heartbeatExApp($resultOutput, $daemonConfig->getId())) {
$output->writeln(json_encode($resultOutput, JSON_UNESCAPED_SLASHES));
return Command::SUCCESS;
return 0;
}

$output->writeln(sprintf('ExApp %s heartbeat check failed. Make sure container started and initialized correctly.', $appId));
} else {
$output->writeln(sprintf('ExApp %s deployment failed. Error: %s', $appId, $startResult['error'] ?? $createResult['error']));
}
return Command::FAILURE;
return 1;
}

private function buildDeployEnvParams(array $params, array $envOptions, array $deployConfig): array {
Expand Down
8 changes: 4 additions & 4 deletions lib/Command/ExApp/Disable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found. Failed to disable.', $appId));
return Command::FAILURE;
return 1;
}
if (!$exApp->getEnabled()) {
$output->writeln(sprintf('ExApp %s already disabled.', $appId));
return Command::SUCCESS;
return 0;
}

if ($this->service->disableExApp($exApp)) {
$output->writeln(sprintf('ExApp %s successfully disabled.', $appId));
return Command::SUCCESS;
return 0;
}

$output->writeln(sprintf('Failed to disable ExApp %s.', $appId));
return Command::FAILURE;
return 1;
}
}
8 changes: 4 additions & 4 deletions lib/Command/ExApp/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($exApp === null) {
$output->writeln(sprintf('ExApp %s not found. Failed to enable.', $appId));
return Command::FAILURE;
return 1;
}
if ($exApp->getEnabled()) {
$output->writeln(sprintf('ExApp %s already enabled.', $appId));
return Command::SUCCESS;
return 0;
}

if ($this->service->enableExApp($exApp)) {
$output->writeln(sprintf('ExApp %s successfully enabled.', $appId));
return Command::SUCCESS;
return 0;
}

$output->writeln(sprintf('Failed to enable ExApp %s.', $appId));
return Command::FAILURE;
return 1;
}
}
4 changes: 2 additions & 2 deletions lib/Command/ExApp/ListExApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
} catch (Exception) {
$output->writeln('<error>Failed to get list of ExApps</error>');
return Command::FAILURE;
return 1;
}
return Command::SUCCESS;
return 0;
}
}
Loading

0 comments on commit 8cefdd2

Please sign in to comment.