clone:
  git:
    image: woodpeckerci/plugin-git
    settings:
      depth: 1

steps:
  changelog:
      image: debian
      commands:
        - apt update
        - apt install git -y
        - mkdir dist
        - git log --oneline --decorate --since="7.days" --pretty="## %s%n%an%n%aD%n%b" > dist/README.md || echo "Could not write changelog!" >> dist/README.md #Get that changelog

  version-tag:
    image: debian
    commands:
      - sed -i -e "s/INTERNAL-BUILD/${CI_COMMIT_TAG}/g" game/options.rpy #Change the internal build name to the tagged version
      - sed -i -e "s/INTERNAL-BUILD/${CI_COMMIT_TAG}/g" android.json         
    when:
      - event: tag
  
  version-cron:
    image: debian
    commands:
      - sed -i -e "s/INTERNAL-BUILD/${CI_COMMIT_SHA}/g" game/options.rpy #if no tag, make it the commit num
      - sed -i -e "s/INTERNAL-BUILD/${CI_COMMIT_SHA}/g" android.json 
    when:
      - event: cron

  build:
    image: openjdk:21-jdk-bookworm
    commands:
      - apt update
      - apt install libgl1 patch -y
      - sed -i -e "s/VERSION/${RenpyVersion}/g" game/options.rpy #Change the renpy version to the woodpecker reuqested one.
        #Get Renkit
      - wget -qO- "https://github.com/kobaltcore/renkit/releases/download/v${RenkitVersion}/renkit-x86_64-unknown-linux-gnu.tar.xz" | tar -Jax --directory=/tmp/
      - /tmp/renkit-x86_64-unknown-linux-gnu/renconstruct build "." dist/
      - mkdir "dist/android"
      - mv dist/*.apk "dist/android"
      - cd /tmp/

  archival-sha:
    image: debian
    commands:
      - apt update
      - apt install curl bash -y
      - curl https://git.cavemanon.xyz/Cavemanon/Woodpecker-Webdav/raw/branch/master/push.sh > /tmp/push.sh ## I'd use a proper docker container, but dockerhub is owned by the CIA and I refuse to deal with that (also I don't care to maintain it or set it up). #TODO: merge this script as apart of the file so we don't make unnecessary network requests every time we build.
      - chmod +x /tmp/push.sh
      - PLUGIN_USERNAME=$RELEASESMITHNEXTCLOUDUSERNAME PLUGIN_PASSWORD=$RELEASESMITHNEXTCLOUDPASSWORD PLUGIN_DESTINATION=https://cloud.dev.cavemanon.xyz/remote.php/dav/files/ReleaseSmith/Snoot%20Game/Internal%20Builds/nightly-${CI_COMMIT_SHA}/ PLUGIN_MAKE_FOLDER_AT=https://cloud.dev.cavemanon.xyz/remote.php/dav/files/ReleaseSmith/Snoot%20Game/Internal%20Builds/nightly-${CI_COMMIT_SHA}/ PLUGIN_FILE_GLOB=dist/* /tmp/push.sh #sovl
      - rm -rf "dist"
    secrets: [ releasesmithnextcloudusername, releasesmithnextcloudpassword ]
    when:
      - event: cron
        cron: "nightly"
  
  archival-tag:
    image: debian
    commands:
      - apt update
      - apt install curl bash -y
      - curl https://git.cavemanon.xyz/Cavemanon/Woodpecker-Webdav/raw/branch/master/push.sh > /tmp/push.sh ## I'd use a proper docker container, but dockerhub is owned by the CIA and I refuse to deal with that (also I don't care to maintain it or set it up). #TODO: merge this script as apart of the file so we don't make unnecessary network requests every time we build.
      - chmod +x /tmp/push.sh
      - PLUGIN_USERNAME=$RELEASESMITHNEXTCLOUDUSERNAME PLUGIN_PASSWORD=$RELEASESMITHNEXTCLOUDPASSWORD PLUGIN_DESTINATION=https://cloud.dev.cavemanon.xyz/remote.php/dav/files/ReleaseSmith/Snoot%20Game/Internal%20Builds/release-${CI_COMMIT_TAG}/ PLUGIN_MAKE_FOLDER_AT=https://cloud.dev.cavemanon.xyz/remote.php/dav/files/ReleaseSmith/Snoot%20Game/Internal%20Builds/release-${CI_COMMIT_TAG}/ PLUGIN_FILE_GLOB=dist/* /tmp/push.sh #sovl
      - rm -rf "dist"
    secrets: [ releasesmithnextcloudusername, releasesmithnextcloudpassword ]
    when:
      - event: tag

  release:
    image: woodpeckerci/plugin-gitea-release:latest
    settings:
      base_url: https://git.cavemanon.xyz
      api_key:
        from_secret: releasesmithapikey
      files: "*-dists/*"
      prerelease: true
      title: "${CI_COMMIT_TAG}"
    when:
      - event: tag

matrix:
  RenpyVersion:
    - "8.3.0"
  RenkitVersion:
    - "4.4.0"