kind: pipeline
type: exec
name: Nightly

steps:
  - name: Prepare
    commands:
      - ln -s /var/lib/drone-runner-exec/.local $HOME/.local
      - ln -s /var/lib/drone-runner-exec/fdroid $HOME/fdroid

  - name: Run Tests
    commands:
      - ./ci.py --ci-run-tests
      - sonar-scanner -Dsonar.projectKey=SelfPrivacy-Flutter-App -Dsonar.sources=. -Dsonar.host.url=http://analyzer.lan:9000 -Dsonar.login="$SONARQUBE_TOKEN"
    environment:
      SONARQUBE_TOKEN:
        from_secret: SONARQUBE_TOKEN

  - name: Build Nightly Linux Release Artifact (Binary)
    commands:
      - ./ci.py --ci-build-linux

  - name: Build Nightly Release Artifact (.APK)
    commands:
      - ./ci.py --ci-build-apk

  - name: Sign and Commit Nightly Android Release Artifact (.APK) for F-Droid Repository
    commands:
      - rm -rf $HOME/fdroid/build/org.selfprivacy.app.nightly && mkdir $HOME/fdroid/build/org.selfprivacy.app.nightly
      - git archive --format=tar HEAD | tar x -C $HOME/fdroid/build/org.selfprivacy.app.nightly
      - ./ci.py --sign-apk-fdroid-nightly
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Deploy F-Droid Repository
    commands:
      - ./ci.py --deploy-fdroid-repo
    environment:
      SSH_PRIVATE_KEY:
        from_secret: SSH_PRIVATE_KEY

trigger:
  event:
    - push
  branch:
    - master

node:
  server: builder

---

kind: pipeline
type: exec
name: Release

steps:
  - name: Prepare
    commands:
      - ln -s /var/lib/drone-runner-exec/.local $HOME/.local
      - ln -s /var/lib/drone-runner-exec/fdroid $HOME/fdroid
      - if podman volume exists release; then podman volume rm -f release; podman volume create release; else podman volume create release; fi
      - git config user.email "builder@selfprivacy.org"
      - git config user.name "Builder"

  - name: Create an Empty Gitea Release
    commands:
      - ./ci.py --gitea-create-release
    environment:
      GITEA_RELEASE_TOKEN:
        from_secret: GITEA_RELEASE_TOKEN

  - name: Build Intermediate Linux Release Artifact (Binary)
    commands:
      - ./ci.py --build-linux
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Build Intermediate Android Release Artifact (.APK)
    commands:
      - ./ci.py --build-apk
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Build Intermediate Android Release Artifact (Bundle)
    commands:
      - ./ci.py --build-bundle
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Sign Android Release Artifact (.APK) for Standalone Use
    commands:
      - ./ci.py --sign-apk-standalone
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Sign and Commit Android Release Artifact (.APK) for F-Droid Repository
    commands:
      - rm -rf $HOME/fdroid/build/org.selfprivacy.app && mkdir $HOME/fdroid/build/org.selfprivacy.app
      - git archive --format=tar HEAD | tar x -C $HOME/fdroid/build/org.selfprivacy.app
      - ./ci.py --sign-apk-fdroid
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Sign Android Release Artifact (Bundle) for Google Play
    commands:
      - ./ci.py --sign-bundle
    environment:
      STANDALONE_KEYSTORE_PASS:
        from_secret: STANDALONE_KEYSTORE_PASS
      FDROID_KEYSTORE_PASS:
        from_secret: FDROID_KEYSTORE_PASS
      GOOGLE_KEYSTORE_PASS:
        from_secret: GOOGLE_KEYSTORE_PASS

  - name: Package Linux AppImage Artifact
    commands:
      - ./ci.py --package-linux-appimage

  - name: Package Linux Flatpak Artifact
    commands:
      - ./ci.py --package-linux-flatpak

  - name: Package Linux Archive Artifact
    commands:
      - ./ci.py --package-linux-archive

  - name: Push Artifacts to the Release Volume
    commands:
      - git add -v *.AppImage *.AppImage.zsync *.flatpak *.apk *.apk.idsig *.aab *.tar.zstd
      - git commit -m Release
      - git archive --format=tar HEAD | podman volume import release -

trigger:
  event:
    - tag

node:
  server: builder

---

kind: pipeline
type: exec
name: Deploy

steps:
  - name: Prepare
    commands:
      - ln -s /var/lib/drone-runner-exec/.local $HOME/.local
      - podman unshare podman volume mount release

  - name: Deploy Artifacts to Gitea
    commands:
      - ./ci.py --deploy-gitea-release
    environment:
      GITEA_RELEASE_TOKEN:
        from_secret: GITEA_RELEASE_TOKEN

  - name: Deploy F-Droid Repository
    commands:
      - ./ci.py --deploy-fdroid-repo
    environment:
      SSH_PRIVATE_KEY:
        from_secret: SSH_PRIVATE_KEY

trigger:
  event:
    - tag

node:
  server: builder

depends_on:
  - Release