diff --git a/.github/workflows/QA_keystore.jks b/.github/workflows/QA_keystore.jks new file mode 100644 index 00000000..2b8fb9bc Binary files /dev/null and b/.github/workflows/QA_keystore.jks differ diff --git a/.github/workflows/QA_keystore.jks.license b/.github/workflows/QA_keystore.jks.license new file mode 100644 index 00000000..7ec21443 --- /dev/null +++ b/.github/workflows/QA_keystore.jks.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors +SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only diff --git a/.github/workflows/lib.sh b/.github/workflows/lib.sh new file mode 100644 index 00000000..42f4b55b --- /dev/null +++ b/.github/workflows/lib.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2022 Álvaro Brey +# SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only +# + +## This file is intended to be sourced by other scripts + + +function err() { + echo >&2 "$@" +} + + +function curl_gh() { + if [[ -n "$GITHUB_TOKEN" ]] + then + curl \ + --silent \ + --header "Authorization: token $GITHUB_TOKEN" \ + "$@" + else + err "WARNING: No GITHUB_TOKEN found. Skipping API call" + fi + +} diff --git a/.github/workflows/lib.sh.license b/.github/workflows/lib.sh.license new file mode 100644 index 00000000..162c9615 --- /dev/null +++ b/.github/workflows/lib.sh.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2019-2025 Nextcloud GmbH and Nextcloud contributors +SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 00000000..1caff321 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,55 @@ +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2023 Andy Scherzinger +# SPDX-License-Identifier: MIT +name: "QA" + +on: + pull_request: + branches: [ main, master, stable-* ] + +permissions: + pull-requests: write + contents: read + +concurrency: + group: qa-build-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + qa: + runs-on: ubuntu-latest + steps: + - name: Check if secrets are available + run: echo "ok=${{ secrets.KS_PASS != '' }}" >> "$GITHUB_OUTPUT" + id: check-secrets + + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + if: ${{ steps.check-secrets.outputs.ok == 'true' }} + with: + persist-credentials: false + + - name: set up JDK 17 + uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0 + if: ${{ steps.check-secrets.outputs.ok == 'true' }} + with: + distribution: "temurin" + java-version: 17 + + - name: Build QA + if: ${{ steps.check-secrets.outputs.ok == 'true' }} + env: + KS_PASS: ${{ secrets.KS_PASS }} + KEY_PASS: ${{ secrets.KEY_PASS }} + LOG_USERNAME: ${{ secrets.LOG_USERNAME }} + LOG_PASSWORD: ${{ secrets.LOG_PASSWORD }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -p "$HOME/.gradle" + echo "org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g" > "$HOME/.gradle/gradle.properties" + echo "org.gradle.caching=true; org.gradle.parallel=true; org.gradle.configureondemand=true; kapt.incremental.apt=true" >> "$HOME/.gradle/gradle.properties" + sed -i "/qa/,/\}/ s/versionCode .*/versionCode ${{github.event.number}} /" "app/build.gradle" + sed -i "/qa/,/\}/ s/versionName .*/versionName \"${{github.event.number}}\"/" "app/build.gradle" + ./gradlew assembleQaDebug + $(find /usr/local/lib/android/sdk/build-tools/*/apksigner | sort | tail -n1) sign --ks-pass pass:"$KS_PASS" --key-pass pass:"$KEY_PASS" --ks-key-alias key0 --ks ".github/workflows/QA_keystore.jks" "app/build/outputs/apk/qa/debug/*qa-debug*.apk" + .github/workflows/uploadArtifact.sh "$LOG_USERNAME" "$LOG_PASSWORD" "${{github.event.number}}" "${{github.event.number}}" "$GITHUB_TOKEN" diff --git a/.github/workflows/uploadArtifact.sh b/.github/workflows/uploadArtifact.sh new file mode 100755 index 00000000..fa263064 --- /dev/null +++ b/.github/workflows/uploadArtifact.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# +# SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2019-2022 Tobias Kaminsky +# SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only +# + +#1: LOG_USERNAME +#2: LOG_PASSWORD +#3: DRONE_BUILD_NUMBER +#4: DRONE_PULL_REQUEST + + +PUBLIC_URL=https://www.kaminsky.me/nc-dev/android-artifacts +USER=$1 +PASS=$2 +BUILD=$3 +PR=$4 +GITHUB_TOKEN=$5 +DAV_URL=https://nextcloud.kaminsky.me/remote.php/dav/files/$USER/android-artifacts/ + +source .github/workflows/lib.sh +REPO=$(cat scripts/repo) + +if ! test -e app/build/outputs/apk/qa/debug/*qa-debug*.apk ; then + exit 1 +fi +echo "Uploaded artifact to $DAV_URL/$BUILD.apk" + +# delete all old comments, starting with "APK file:" +oldComments=$(curl_gh -X GET https://api.github.com/repos/nextcloud/$REPO/issues/$PR/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("github-actions") | tostring) + "|" + (.body | test("APK file:.*") | tostring)' | grep "true|true" | tr -d "\"" | cut -f1 -d"|") + +echo $oldComments | while read comment ; do + curl_gh -X DELETE https://api.github.com/repos/nextcloud/$REPO/issues/comments/$comment +done + +sudo apt-get -y install qrencode + +qrencode -o $PR.png "$PUBLIC_URL/$BUILD.apk" + +curl -u $USER:$PASS -X PUT $DAV_URL/$BUILD.apk --upload-file app/build/outputs/apk/qa/debug/*qa-debug*.apk +curl -u $USER:$PASS -X PUT $DAV_URL/$BUILD.png --upload-file $PR.png +curl_gh -X POST https://api.github.com/repos/nextcloud/$REPO/issues/$PR/comments -d "{ \"body\" : \"APK file: $PUBLIC_URL/$BUILD.apk

![qrcode]($PUBLIC_URL/$BUILD.png)

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app. \" }"