Skip to content

Commit 48467b1

Browse files
committed
ci: automate upgrade testing
Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
1 parent 26c6556 commit 48467b1

4 files changed

Lines changed: 281 additions & 14 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# SPDX-FileCopyrightText: 2023-2024 Jankari Tech Pvt. Ltd.
2+
# SPDX-FileCopyrightText: 2023 Bundesministerium des Innern und für Heimat, PG ZenDiS "Projektgruppe für Aufbau ZenDiS"
3+
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH
4+
# SPDX-License-Identifier: AGPL-3.0-only
5+
#!/usr/bin/env bash
6+
7+
# This bash script is to register and publish the apps in self-hosted appstore.
8+
# To run this script the self-hosted appstore instances must be up and running
9+
10+
set -e
11+
12+
# helper functions
13+
log_error() {
14+
echo -e "\e[31m$1\e[0m"
15+
}
16+
17+
log_info() {
18+
echo -e "\e[37m$1\e[0m"
19+
}
20+
21+
log_success() {
22+
echo -e "\e[32m$1\e[0m"
23+
}
24+
25+
if [ -z "$APP_ID" ] || [ -z "$APP_VERSION" ]; then
26+
log_error "One or more required environment variables are missing: APP_ID, APP_VERSION"
27+
exit 1
28+
fi
29+
30+
# public certificate of the integration app for testing
31+
CERTIFICATE="-----BEGIN CERTIFICATE-----\r\nMIIEEjCCAvoCAhF6MA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD\r\nVQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI\r\nMTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB\r\ndXRob3JpdHkwHhcNMjEwMzE4MTMwMTExWhcNMzEwNjI0MTMwMTExWjAiMSAwHgYD\r\nVQQDDBdpbnRlZ3JhdGlvbl9vcGVucHJvamVjdDCCAiIwDQYJKoZIhvcNAQEBBQAD\r\nggIPADC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r\nMIxSI44hNeixh8Yn9rcy\/LqOUgl0niB5hfAiauRwHcOY5wf1hKE=\r\n-----END CERTIFICATE-----"
32+
SIGNATURE="signature"
33+
34+
registerApps() {
35+
app_name=$1
36+
37+
register_app=$(curl -s -o /dev/null -w "%{http_code}" -X POST -uadmin:admin \
38+
http://localhost:8000/api/v1/apps \
39+
-H "Content-Type: application/json" \
40+
-d "{
41+
\"certificate\": \"${CERTIFICATE}\",
42+
\"signature\": \"${SIGNATURE}\"
43+
}")
44+
if [[ ${register_app} == 201 ]]; then
45+
log_success "\"${app_name}\" has been registered successfully!"
46+
elif [[ ${register_app} == 204 ]]; then
47+
log_info "\"${app_name}\" has been updated!"
48+
elif [[ ${register_app} == 400 ]]; then
49+
log_error "\"${app_name}\" contains invalid characters, the signature!"
50+
exit 1
51+
else
52+
log_error "Failed to register \"${app_name}\""
53+
exit 1
54+
fi
55+
}
56+
57+
publishApps() {
58+
app_name=$1
59+
app_version=$2
60+
61+
register_app=$(curl -s -o /dev/null -w "%{http_code}" -X POST -uadmin:admin \
62+
http://localhost:8000/api/v1/apps/releases \
63+
-H "Content-Type: application/json" \
64+
-d "{
65+
\"download\":\"https://github.com/nextcloud/${app_name}/releases/download/v${app_version}/${app_name}-${app_version}.tar.gz\",
66+
\"signature\": \"${SIGNATURE}\"
67+
}")
68+
if [[ ${register_app} == 200 ]]; then
69+
log_success "\"${app_name} ${app_version}\" has been updated successfully!"
70+
elif [[ ${register_app} == 201 ]]; then
71+
log_success "\"${app_name} ${app_version}\" has been published successfully!"
72+
else
73+
log_error "Failed to publish \"${app_name} ${app_version}\""
74+
exit 1
75+
fi
76+
}
77+
78+
registerApps "$APP_ID"
79+
publishApps "$APP_ID" "$APP_VERSION"

.github/workflows/appstore.yml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
6+
# SPDX-FileCopyrightText: 2022 Free Software Foundation Europe e.V. <https://fsfe.org>
7+
#
8+
# SPDX-License-Identifier: CC0-1.0
9+
10+
name: Upgrade Testing
11+
12+
on: [pull_request]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
env:
18+
DJANGO_SETTINGS_MODULE: nextcloudappstore.settings.development
19+
services:
20+
21+
database-mysql:
22+
image: ghcr.io/nextcloud/continuous-integration-mariadb-10.5:latest
23+
env:
24+
MYSQL_ROOT_PASSWORD: 'nextcloud'
25+
MYSQL_PASSWORD: 'nextcloud'
26+
MYSQL_USER: 'nextcloud'
27+
MYSQL_DATABASE: 'nextcloud'
28+
ports:
29+
- 3306:3306
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
34+
with:
35+
path: integration_openproject
36+
37+
- name: Setup NodeJS
38+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238
39+
with:
40+
node-version: 20
41+
42+
- name: Setup npm
43+
run: npm i -g npm
44+
45+
- name: Setup PHP
46+
uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d
47+
with:
48+
php-version: '8.2'
49+
extensions: mbstring, intl, mysql, gd
50+
ini-values: post_max_size=256M, max_execution_time=180
51+
coverage: xdebug
52+
tools: php-cs-fixer, phpunit
53+
54+
- name: Build nextcloud project
55+
# if: ${{ startsWith( steps.tag.outputs.currenttag , 'v' ) }}
56+
# id: build_release
57+
run: |
58+
export DEBIAN_FRONTEND=noninteractive
59+
echo "###### installing nextcloud"
60+
mkdir ~/html
61+
git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b stable29 ~/html/nextcloud
62+
cd ~/html/nextcloud
63+
git submodule update --init
64+
mkdir -p data
65+
# chown -R www-data:www-data config data apps
66+
php occ maintenance:install \
67+
--database mysql \
68+
--database-name nextcloud \
69+
--database-host 127.0.0.1 \
70+
--database-user nextcloud \
71+
--database-pass nextcloud \
72+
--admin-user admin \
73+
--admin-pass admin
74+
php occ maintenance:mode --off
75+
sudo php -S localhost:80 -t ~/html/nextcloud &
76+
77+
- name: Wait for Nextcloud server to be ready
78+
run: |
79+
if ! timeout 5m bash -c '
80+
until curl -s -f http://localhost/status.php | grep '"'"'"installed":true'"'"'; do
81+
echo "[INFO] Waiting for server to be ready..."
82+
sleep 10
83+
done
84+
'; then
85+
echo "[ERROR] Server not ready within 5 minutes."
86+
exit 1
87+
fi
88+
89+
90+
- name: Setup System dependencies for appstore
91+
run: |
92+
sudo apt install -y \
93+
python3-venv \
94+
python3-wheel \
95+
libxslt-dev \
96+
libxml2-dev \
97+
libz-dev \
98+
libpq-dev \
99+
build-essential \
100+
python3-dev \
101+
python3-setuptools \
102+
gettext \
103+
libssl-dev \
104+
libffi-dev \
105+
nodejs \
106+
yarn
107+
108+
- name: Checkout appstore
109+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
110+
with:
111+
repository: nextcloud/appstore
112+
path: appstore
113+
114+
- name: Install Appstore
115+
run: |
116+
cd appstore
117+
python3 -m venv venv
118+
source venv/bin/activate
119+
pip install poetry==1.8.2
120+
make dev-setup
121+
python manage.py runserver &
122+
123+
- name: Check for Appstore
124+
run: |
125+
cd appstore
126+
status=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:8000)
127+
if [ "$status" -eq 200 ]; then
128+
echo "OK"
129+
else
130+
echo "FAILED (status: $status)"
131+
fi
132+
133+
- name: Register and publish apps
134+
env:
135+
APP_ID: integration_openproject
136+
APP_VERSION: 2.9.2
137+
run: |
138+
cd integration_openproject
139+
bash ./.github/scripts/self-hosted-app-store.sh
140+
141+
- name: Configure Nextcloud for testing
142+
run: |
143+
# making the signature verification always pass for testing
144+
# by making the $verified variable true in Installer.php
145+
sed -i.bak 's/$verified = .*/$verified = true;/' /home/runner/html/nextcloud/lib/private/Installer.php || {
146+
echo "::error::Failed to patch Installer.php with sed"
147+
exit 1
148+
}
149+
cd ~/html/nextcloud
150+
php occ config:system:set appstoreurl --value http://localhost:8000/api/v1
151+
php occ config:system:set allow_local_remote_servers --value true
152+
php occ app:install integration_openproject
153+
154+
- name: Register and publish next release of the app
155+
env:
156+
APP_ID: integration_openproject
157+
APP_VERSION: 2.10.0
158+
run: |
159+
cd integration_openproject
160+
bash ./.github/scripts/self-hosted-app-store.sh
161+
162+
- name: upgrade apps
163+
run: |
164+
cd ~/html/nextcloud
165+
# latest data didn't get fetched properly, so we need to clear the appstore cache
166+
echo "" > ~/html/nextcloud/data/appdata_*/appstore/apps.json
167+
php occ app:update --allow-unstable integration_openproject
168+
169+
- name: API Tests
170+
env:
171+
NEXTCLOUD_BASE_URL: http://localhost
172+
run: |
173+
cd integration_openproject
174+
# build apps
175+
make
176+
# Run API tests
177+
make api-test
178+
179+
# - name: Setup Debug Session
180+
# uses: csexton/debugger-action@master
181+
182+
# - name: Configure Nextcloud for testing
183+
# run: |
184+
# ls -l
185+
186+
# cd ~/html/nextcloud
187+
# ls -l
188+
# php occ app:install integration_openproject

.github/workflows/ci-workflow.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33
name: CI
44

5-
on:
6-
push:
7-
branches:
8-
- 'master'
9-
pull_request:
10-
paths-ignore:
11-
- '**.md'
12-
- '**.txt'
13-
- '**.sh'
14-
- 'dev/**'
15-
- 'l10n/**'
16-
- 'img/**'
17-
- 'docker-compose*'
5+
# on:
6+
# push:
7+
# branches:
8+
# - 'master'
9+
# pull_request:
10+
# paths-ignore:
11+
# - '**.md'
12+
# - '**.txt'
13+
# - '**.sh'
14+
# - 'dev/**'
15+
# - 'l10n/**'
16+
# - 'img/**'
17+
# - 'docker-compose*'
1818

1919
concurrency:
2020
group: ${{ github.workflow }}-${{ github.ref }}

.github/workflows/reuse.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
name: REUSE Compliance Check
1111

12-
on: [pull_request]
12+
# on: [pull_request]
1313

1414
permissions:
1515
contents: read

0 commit comments

Comments
 (0)