diff --git a/.drone.yml b/.drone.yml index f9285fb521..0a9596c1ee 100644 --- a/.drone.yml +++ b/.drone.yml @@ -14,18 +14,18 @@ steps: from_secret: LOG_PASSWORD GIT_USERNAME: from_secret: GIT_USERNAME - GIT_TOKEN: + GITHUB_TOKEN: from_secret: GIT_TOKEN commands: - - scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0 + - scripts/checkIfRunDrone.sh $DRONE_PULL_REQUEST || exit 0 - emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 & - sed -i s'#false#true#'g app/src/main/res/values/setup.xml - ./gradlew assembleGplayDebugAndroidTest - scripts/wait_for_emulator.sh - ./gradlew installGplayDebugAndroidTest - scripts/wait_for_server.sh "server" - - scripts/deleteOldComments.sh "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN - - ./gradlew createGplayDebugCoverageReport -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN + - scripts/deleteOldComments.sh "stable" "IT" $DRONE_PULL_REQUEST + - ./gradlew createGplayDebugCoverageReport -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "IT" $DRONE_PULL_REQUEST services: - name: server @@ -74,13 +74,13 @@ steps: from_secret: LOG_PASSWORD GIT_USERNAME: from_secret: GIT_USERNAME - GIT_TOKEN: + GITHUB_TOKEN: from_secret: GIT_TOKEN commands: - - scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0 + - scripts/checkIfRunDrone.sh $DRONE_PULL_REQUEST || exit 0 - emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 & - sed -i s'#false#true#'g app/src/main/res/values/setup.xml - - scripts/runCombinedTest.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER + - scripts/runCombinedTest.sh $DRONE_PULL_REQUEST $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER services: - name: server @@ -125,7 +125,7 @@ steps: environment: GIT_USERNAME: from_secret: GIT_USERNAME - GIT_TOKEN: + GITHUB_TOKEN: from_secret: GIT_TOKEN LOG_USERNAME: from_secret: LOG_USERNAME diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 08f4be8ddf..a8d40902ca 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -10,7 +10,22 @@ jobs: analysis: runs-on: ubuntu-latest steps: + - name: Setup variables + id: get-vars + run: | + if [ -z "$GITHUB_HEAD_REF" ]; then + # push + echo "::set-output name=branch::$GITHUB_REF_NAME" + echo "::set-output name=pr::$GITHUB_RUN_ID" + else + # pull request + echo "::set-output name=branch::$GITHUB_HEAD_REF" + echo "::set-output name=pr::${{ github.event.pull_request.number }}" + fi - uses: actions/checkout@v3 + with: + repository: ${{ steps.get-vars.outputs.repo }} + ref: ${{ steps.get-vars.outputs.branch }} - name: Set up JDK 11 uses: actions/setup-java@v3 with: @@ -20,7 +35,9 @@ jobs: run: | python3 -m pip install defusedxml - name: Run analysis wrapper + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | mkdir -p $HOME/.gradle echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties - scripts/analysis/analysis-wrapper.sh ${{ secrets.GIT_USERNAME }} ${{ secrets.GIT_TOKEN }} ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ steps.get-vars.outputs.pr }} + scripts/analysis/analysis-wrapper.sh ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ steps.get-vars.outputs.pr }} diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index b870b09ed1..14a394543c 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -31,6 +31,7 @@ jobs: 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=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties @@ -38,4 +39,4 @@ jobs: 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 scripts/QA_keystore.jks app/build/outputs/apk/qa/debug/qa-debug-*.apk - sudo scripts/uploadArtifact.sh $LOG_USERNAME $LOG_PASSWORD ${{github.event.number}} ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }} + sudo scripts/uploadArtifact.sh $LOG_USERNAME $LOG_PASSWORD ${{github.event.number}} ${{github.event.number}} diff --git a/.github/workflows/screenShotTest.yml b/.github/workflows/screenShotTest.yml index 6d294b5709..6138deaf21 100644 --- a/.github/workflows/screenShotTest.yml +++ b/.github/workflows/screenShotTest.yml @@ -59,8 +59,10 @@ jobs: run: ./gradlew assembleGplayDebug - name: Delete old comments + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: ${{ always() }} - run: scripts/deleteOldComments.sh "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }} + run: scripts/deleteOldComments.sh "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}} - name: Run screenshot tests uses: reactivecircus/android-emulator-runner@v2 @@ -74,8 +76,10 @@ jobs: script: ./gradlew uninstallAll gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest -Pandroid.testInstrumentationRunnerArguments.COLOR=${{ matrix.color }} -Pandroid.testInstrumentationRunnerArguments.DARKMODE=${{ matrix.scheme }} - name: upload failing results if: ${{ failure() }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: - scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }} + scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}} - name: Archive Espresso results uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 if: ${{ always() }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 12fc6c664b..b1a452d1f0 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -17,16 +17,20 @@ jobs: distribution: "temurin" java-version: 11 - name: Delete old comments + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: ${{ always() }} - run: scripts/deleteOldComments.sh "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }} + run: scripts/deleteOldComments.sh "test" "Unit" ${{github.event.number}} - name: Run unit tests with coverage uses: gradle/gradle-build-action@v2 with: arguments: jacocoTestGplayDebugUnitTest - name: Upload failing results if: ${{ failure() }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: - scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }} + scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "test" "Unit" ${{github.event.number}} - name: Upload coverage to codecov uses: codecov/codecov-action@v3 with: diff --git a/scripts/analysis/analysis-wrapper.sh b/scripts/analysis/analysis-wrapper.sh index 6a071230e9..40d5ddf974 100755 --- a/scripts/analysis/analysis-wrapper.sh +++ b/scripts/analysis/analysis-wrapper.sh @@ -1,17 +1,16 @@ #!/usr/bin/env bash -#1: GIT_USERNAME -#2: GIT_TOKEN -#3: BRANCH -#4: LOG_USERNAME -#5: LOG_PASSWORD -#6: DRONE_BUILD_NUMBER -#7: PULL_REQUEST_NUMBER +BRANCH=$1 +LOG_USERNAME=$2 +LOG_PASSWORD=$3 +BUILD_NUMBER=$4 +PR_NUMBER=$5 + stableBranch="master" repository="android" -ruby scripts/analysis/lint-up.rb $1 $2 $3 +ruby scripts/analysis/lint-up.rb lintValue=$? curl "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "/tmp/$stableBranch.xml" @@ -23,37 +22,39 @@ spotbugsValue=$? # 1: count was increased # 2: count stayed the same -echo "Branch: $3" +source scripts/lib.sh -if [ $3 = $stableBranch ]; then +echo "Branch: $BRANCH" + +if [ "$BRANCH" = $stableBranch ]; then echo "New spotbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html" - curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html - curl 2>/dev/null -u "$4:$5" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml" --upload-file app/build/reports/spotbugs/gplayDebug.xml + curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html + curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml" --upload-file app/build/reports/spotbugs/gplayDebug.xml if [ $lintValue -ne 1 ]; then echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html" - curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html + curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html exit 0 fi else - if [ -e $6 ]; then + if [ -e "${BUILD_NUMBER}" ]; then 6=$stableBranch"-"$(date +%F) fi - echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/$6.html" - curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$6.html --upload-file app/build/reports/lint/lint.html + echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/${BUILD_NUMBER}.html" + curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/${BUILD_NUMBER}.html" --upload-file app/build/reports/lint/lint.html - echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html" - curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$6.html --upload-file app/build/reports/spotbugs/spotbugs.html + echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html" + curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/${BUILD_NUMBER}.html" --upload-file app/build/reports/spotbugs/spotbugs.html # delete all old comments, starting with Codacy - oldComments=$(curl 2>/dev/null -u $1:$2 -X GET https://api.github.com/repos/nextcloud/android/issues/$7/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) + "|" + (.body | test("

Codacy.*") | tostring)' | grep "true|true" | tr -d "\"" | cut -f1 -d"|") + oldComments=$(curl_gh -X GET "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" | jq '.[] | select((.user.login | contains("github-actions")) and (.body | test("

Codacy.*"))) | .id') - echo $oldComments | while read comment ; do - curl 2>/dev/null -u $1:$2 -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment + echo "$oldComments" | while read -r comment ; do + curl_gh -X DELETE "https://api.github.com/repos/nextcloud/$repository/issues/comments/$comment" done # check library, only if base branch is master - baseBranch=$(scripts/analysis/getBranchBase.sh $1 $2 $7 | tr -d "\"") + baseBranch=$(scripts/analysis/getBranchBase.sh "${PR_NUMBER}" | tr -d "\"") if [ $baseBranch = "master" -a $(grep "androidLibraryVersion = \"master-SNAPSHOT\"" build.gradle -c) -ne 1 ]; then checkLibraryMessage="

Android-library is not set to master branch in build.gradle

" checkLibrary=1 @@ -88,7 +89,7 @@ else lintWarningNew=0 fi - lintResultOld=$(curl 2>/dev/null https://raw.githubusercontent.com/nextcloud/android/$stableBranch/scripts/analysis/lint-results.txt) + lintResultOld=$(curl 2>/dev/null "https://raw.githubusercontent.com/nextcloud/$repository/$stableBranch/scripts/analysis/lint-results.txt") lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ") if ( [ -z $lintErrorOld ] ); then lintErrorOld=0 @@ -106,9 +107,9 @@ else codacyResult="" fi - lintResult="

Lint

Type$stableBranchPR
Warnings"$lintWarningOld""$lintWarningNew"
Errors"$lintErrorOld""$lintErrorNew"
" + lintResult="

Lint

Type$stableBranchPR
Warnings$lintWarningOld$lintWarningNew
Errors$lintErrorOld$lintErrorNew
" - spotbugsResult="

SpotBugs

$(scripts/analysis/spotbugsComparison.py "/tmp/$stableBranch.xml" app/build/reports/spotbugs/gplayDebug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")" + spotbugsResult="

SpotBugs

$(scripts/analysis/spotbugsComparison.py "/tmp/$stableBranch.xml" app/build/reports/spotbugs/gplayDebug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")" if ( [ $lintValue -eq 1 ] ) ; then lintMessage="

Lint increased!

" @@ -131,7 +132,7 @@ else fi payload="{ \"body\" : \"$codacyResult $lintResult $spotbugsResult $checkLibraryMessage $lintMessage $spotbugsMessage $gplayLimitation $notNull\" }" - curl -u "$1:$2" -X POST "https://api.github.com/repos/nextcloud/android/issues/$7/comments" -d "$payload" + curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" -d "$payload" if [ ! -z "$gplayLimitation" ]; then exit 1 diff --git a/scripts/analysis/getBranchBase.sh b/scripts/analysis/getBranchBase.sh index 9838cd7680..42acd1f10f 100755 --- a/scripts/analysis/getBranchBase.sh +++ b/scripts/analysis/getBranchBase.sh @@ -1,9 +1,11 @@ #!/bin/bash -# $1: username, $2: password/token, $3: pull request number +PR_NUMBER=$1 -if [ -z $3 ] ; then +source scripts/lib.sh + +if [ -z "${PR_NUMBER}" ] ; then echo "master"; else - curl 2>/dev/null -u $1:$2 https://api.github.com/repos/nextcloud/android/pulls/$3 | jq .base.ref + curl_gh "https://api.github.com/repos/nextcloud/android/pulls/${PR_NUMBER}" | jq .base.ref fi diff --git a/scripts/analysis/lint-up.rb b/scripts/analysis/lint-up.rb index 525273c175..c9d4864133 100644 --- a/scripts/analysis/lint-up.rb +++ b/scripts/analysis/lint-up.rb @@ -1,14 +1,14 @@ ## Script from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017 # adapts to drone, use git username / token as parameter +# TODO cleanup this script, it has a lot of unused stuff + + Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 puts "=================== starting Android Lint Entropy Reducer ====================" -# get args -git_user, git_token, git_branch = ARGV - # ======================== SETUP ============================ # User name for git commits made by this script. @@ -169,25 +169,18 @@ end # write new results to file (will overwrite existing, or create new) File.write(previous_lint_report, "DO NOT TOUCH; GENERATED BY DRONE\n" + error_warning_string) -# push changes to github (if this script is run locally, we don't want to overwrite git username and email, so save temporarily) -previous_git_username, _ = Open3.capture2('git config user.name') -previous_git_username = previous_git_username.strip - -previous_git_email, _ = Open3.capture3('git config user.email') -previous_git_email = previous_git_email.strip - # update git user name and email for this script -system ("git config --local user.name '" + git_user + "'") -system ("git config --local user.email 'android@nextcloud.com'") +system ("git config --local user.name 'github-actions'") +system ("git config --local user.email 'github-actions@github.com'") # add previous Lint result file to git system ('git add ' + PREVIOUS_LINT_RESULTS_FILE) # commit changes -system({"GIT_COMMITTER_NAME" => git_user, "GIT_COMMITTER_EMAIL" => "android@nextcloud.com", "GIT_AUTHOR_EMAIL" => "android@nextcloud.com"}, 'git commit -sm "Analysis: update lint results to reflect reduced error/warning count"') +system('git commit -sm "Analysis: update lint results to reflect reduced error/warning count"') # push to origin -system ('git push origin HEAD:' + git_branch) +system ('git push') puts "SUCCESS: count was reduced" exit 0 # success diff --git a/scripts/checkIfRunDrone.sh b/scripts/checkIfRunDrone.sh index fab5ab7361..fadc475537 100755 --- a/scripts/checkIfRunDrone.sh +++ b/scripts/checkIfRunDrone.sh @@ -1,12 +1,14 @@ #!/bin/sh -e -if [ -z $3 ] ; then +PR_NUMBER=$1 + +if [ -z "$PR_NUMBER" ] ; then echo "Merge commit to master -> continue with CI" exit 0 fi -export BRANCH=$(scripts/analysis/getBranchBase.sh $1 $2 $3 | sed s'/"//'g) -if [ $(git diff --name-only origin/$BRANCH | grep -cE "^app/src|screenshots|build.gradle|.drone.yml") -eq 0 ] ; then +export BRANCH=$(scripts/analysis/getBranchBase.sh "$PR_NUMBER" | sed 's/"//g') +if [ "$(git diff --name-only "origin/$BRANCH" | grep -cE "^app/src|screenshots|build.gradle|.drone.yml")" -eq 0 ] ; then echo "No source files changed" exit 1 else diff --git a/scripts/deleteOldComments.sh b/scripts/deleteOldComments.sh index 2b1901f3be..179bfec287 100755 --- a/scripts/deleteOldComments.sh +++ b/scripts/deleteOldComments.sh @@ -2,25 +2,25 @@ #1: BRANCH #2: TYPE #3: PR -#4: GITHUB_TOKEN BRANCH=$1 TYPE=$2 PR=$3 -GITHUB_TOKEN=$4 + +source scripts/lib.sh BRANCH_TYPE=$BRANCH-$TYPE # delete all old comments, matching this type echo "Deleting old comments for $BRANCH_TYPE" -oldComments=$(curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X GET https://api.github.com/repos/nextcloud/android/issues/$PR/comments | jq --arg TYPE $BRANCH_TYPE '.[] | (.id |tostring) + "|" + (.user.login | test("(nextcloud-android-bot|github-actions)") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|") +oldComments=$(curl_gh -X GET https://api.github.com/repos/nextcloud/android/issues/$PR/comments | jq --arg TYPE $BRANCH_TYPE '.[] | (.id |tostring) + "|" + (.user.login | test("(nextcloud-android-bot|github-actions)") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|") count=$(echo -n "$oldComments" | grep -c '^') echo "Found $count old comments" if [ "$count" -gt 0 ]; then echo "$oldComments" | while read comment ; do echo "Deleting comment: $comment" - curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment + curl_gh -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment done fi diff --git a/scripts/lib.sh b/scripts/lib.sh new file mode 100644 index 0000000000..e995473997 --- /dev/null +++ b/scripts/lib.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# +# Nextcloud Android Library is available under MIT license +# +# @author Álvaro Brey Vilas +# Copyright (C) 2022 Álvaro Brey Vilas +# Copyright (C) 2022 Nextcloud GmbH +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +## 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/scripts/runAllScreenshotCombinations b/scripts/runAllScreenshotCombinations index 1239b9e227..a2f26a32cc 100755 --- a/scripts/runAllScreenshotCombinations +++ b/scripts/runAllScreenshotCombinations @@ -42,9 +42,9 @@ do -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \ -Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \ -Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" /dev/null \ - && scripts/deleteOldComments.sh "$1-$darkMode-$color" "Screenshot" "$4" "$GIT_TOKEN" \ + && scripts/deleteOldComments.sh "$1-$darkMode-$color" "Screenshot" "$4" \ || resultCode=1 && scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$4" \ - "$1-$darkMode-$color" "Screenshot" "$4" "$GIT_TOKEN" + "$1-$darkMode-$color" "Screenshot" "$4" fi done diff --git a/scripts/runCombinedTest.sh b/scripts/runCombinedTest.sh index 3b30f36312..80c8ac87da 100755 --- a/scripts/runCombinedTest.sh +++ b/scripts/runCombinedTest.sh @@ -1,13 +1,11 @@ #!/bin/bash -GIT_USERNAME=$1 -GIT_TOKEN=$2 -DRONE_PULL_REQUEST=$3 -LOG_USERNAME=$4 -LOG_PASSWORD=$5 -DRONE_BUILD_NUMBER=$6 +DRONE_PULL_REQUEST=$1 +LOG_USERNAME=$2 +LOG_PASSWORD=$3 +DRONE_BUILD_NUMBER=$4 -scripts/deleteOldComments.sh "master" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN +scripts/deleteOldComments.sh "master" "IT" "$DRONE_PULL_REQUEST" ./gradlew assembleGplayDebugAndroidTest @@ -19,7 +17,7 @@ scripts/wait_for_server.sh "server" stat=$? if [ ! $stat -eq 0 ]; then - bash scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "master" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN + bash scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$DRONE_BUILD_NUMBER" "master" "IT" "$DRONE_PULL_REQUEST" fi curl -Os https://uploader.codecov.io/latest/linux/codecov diff --git a/scripts/uploadArtifact.sh b/scripts/uploadArtifact.sh index d9a58e00d6..d4990a84e0 100755 --- a/scripts/uploadArtifact.sh +++ b/scripts/uploadArtifact.sh @@ -4,7 +4,6 @@ #2: LOG_PASSWORD #3: DRONE_BUILD_NUMBER #4: DRONE_PULL_REQUEST -#5: GITHUB_TOKEN DAV_URL=https://nextcloud.kaminsky.me/remote.php/webdav/android-artifacts/ PUBLIC_URL=https://www.kaminsky.me/nc-dev/android-artifacts @@ -12,7 +11,8 @@ USER=$1 PASS=$2 BUILD=$3 PR=$4 -GITHUB_TOKEN=$5 + +source scripts/lib.sh if ! test -e app/build/outputs/apk/qa/debug/qa-debug-*.apk ; then exit 1 @@ -20,10 +20,10 @@ fi echo "Uploaded artifact to $DAV_URL/$BUILD.apk" # delete all old comments, starting with "APK file:" -oldComments=$(curl 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X GET https://api.github.com/repos/nextcloud/android/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"|") +oldComments=$(curl_gh -X GET https://api.github.com/repos/nextcloud/android/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 2>/dev/null --header "authorization: Bearer $GITHUB_TOKEN" -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment + curl_gh -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment done apt-get -y install qrencode @@ -32,4 +32,4 @@ 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 --header "authorization: Bearer $GITHUB_TOKEN" -X POST https://api.github.com/repos/nextcloud/android/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. \" }" +curl_gh -X POST https://api.github.com/repos/nextcloud/android/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. \" }" diff --git a/scripts/uploadReport.sh b/scripts/uploadReport.sh index 2786eb12df..81538c1ca3 100755 --- a/scripts/uploadReport.sh +++ b/scripts/uploadReport.sh @@ -1,26 +1,7 @@ #!/usr/bin/env bash -curl_gh() { - curl \ - --header "authorization: Bearer $GITHUB_TOKEN" \ - "$@" -} - -deleteOldComments() { - # delete all old comments, matching this type - echo "Deleting old comments for $BRANCH_TYPE" - oldComments=$(curl_gh > /dev/null 2>&1 -X GET https://api.github.com/repos/nextcloud/android/issues/$PR/comments | jq --arg TYPE $BRANCH_TYPE '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|") - count=$(echo $oldComments | grep true | wc -l) - echo "Found $count old comments" - - echo $oldComments | while read comment ; do - echo "Deleting comment: $comment" - curl_gh > /dev/null 2>&1 -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment - done -} - upload() { - deleteOldComments + scripts/deleteOldComments.sh "$BRANCH" "$TYPE" "$PR" cd $1 @@ -41,7 +22,6 @@ upload() { #4: BRANCH (stable or master) #5: TYPE (IT or Unit) #6: DRONE_PULL_REQUEST -#7: GITHUB_TOKEN URL=https://nextcloud.kaminsky.me/remote.php/webdav/android-integrationTests ID=$3 @@ -50,7 +30,8 @@ PASS=$2 BRANCH=$4 TYPE=$5 PR=$6 -GITHUB_TOKEN="$7" + +source scripts/lib.sh REMOTE_FOLDER=$ID-$TYPE-$BRANCH-$(date +%H-%M) BRANCH_TYPE=$BRANCH-$TYPE