From 73eaf12ed7591d99316a7b33f94cfddbe0cb4d18 Mon Sep 17 00:00:00 2001
From: Remy Moll <me@moll.re>
Date: Wed, 18 Sep 2024 17:04:21 +0200
Subject: [PATCH] fix remote repo pushing

---
 .../frontend_trigger_deployment.yaml          | 37 +++++++++++++------
 .../.github/workflows/build_app_android.yaml  | 27 ++++++++++----
 frontend/android/fastlane/Fastfile            | 30 +++++----------
 frontend/android/fastlane/README.md           | 20 +++-------
 frontend/android/fastlane/report.xml          | 23 ------------
 5 files changed, 60 insertions(+), 77 deletions(-)
 delete mode 100644 frontend/android/fastlane/report.xml

diff --git a/.gitea/workflows/frontend_trigger_deployment.yaml b/.gitea/workflows/frontend_trigger_deployment.yaml
index 163e477..1f32b0d 100644
--- a/.gitea/workflows/frontend_trigger_deployment.yaml
+++ b/.gitea/workflows/frontend_trigger_deployment.yaml
@@ -10,15 +10,30 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout code
-        uses: actions/checkout@v2
-
-      - name: Push to github remote
-        uses: https://github.com/actions/cpina/github-action-push-to-another-repository@main
-        env:
-          API_TOKEN_GITHUB: ${{ secrets.PUSH_GITHUB_API_TOKEN }}
+        uses: actions/checkout@v3
         with:
-          source-directory: 'frontend'
-          destination-github-username: 'moll-re'
-          destination-repository-name: 'anyway-frontend-builder'
-          user-email: me@moll.re
-          target-branch: main
+          path: 'src'
+
+      - name: Checkout remote repository
+        uses: actions/checkout@v3
+        with:
+          path: 'dest'
+          ref: 'main'
+          github-server-url: 'https://github.com'
+          repository: 'moll-re/anyway-frontend-builder'
+          token: ${{ secrets.PUSH_GITHUB_API_TOKEN }}
+          fetch-depth: 0
+          persist-credentials: true
+
+      - name: Copy files to remote repository
+        run: cp -r src/frontend/. dest/
+
+      - name: Commit and push changes
+        run: |
+          cd dest
+          git config --global user.email "me@moll.re"
+          git config --global user.name "[bot]"
+          git add .
+          git commit -m "Automatic code update for tag"
+          git tag -a ${{ github.ref_name }} -m "mirrored tag"
+          git push origin main --tags
diff --git a/frontend/.github/workflows/build_app_android.yaml b/frontend/.github/workflows/build_app_android.yaml
index 231dba5..05dae9c 100644
--- a/frontend/.github/workflows/build_app_android.yaml
+++ b/frontend/.github/workflows/build_app_android.yaml
@@ -5,12 +5,12 @@ on:
 
 jobs:
   build:
-    runs-on: macos-lastest
+    runs-on: macos-latest
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - name: Set up ruby env
-        uses: ruby/setup-ruby@v1.138.0
+        uses: ruby/setup-ruby@v1
         with:
           ruby-version: 3.2.1
           bundler-cache: true
@@ -20,9 +20,9 @@ jobs:
         with:
           java-version: '17'
           distribution: 'zulu'
-      
+
       - name: Setup android SDK
-        uses: https://github.com/android-actions/setup-android@v3
+        uses: android-actions/setup-android@v3
 
       - name: Infer version number from git tag
         id: version
@@ -30,10 +30,21 @@ jobs:
           REF_NAME: ${{ github.ref_name }}
         run:
           # remove the 'v' prefix from the tag name
-          echo "VERSION=${REF_NAME//v}" >> $GITHUB_ENV
+          echo "VERSION=${REF_NAME//v}" >> $GITHUB_OUTPUT
+
+      - name: Load secrets from github
+        run: |
+          echo "${{ secrets.ANDROID_SECRET_PROPERTIES }}" > secrets.properties
+          echo "${{ secrets.ANDROID_KEYSTORE }}" > release.keystore
+          echo "${{ secrets.ANDROID_GOOGLE_PLAY_JSON }}" > google-key.json
+        working-directory: android
+
+      - name: Install fastlane
+        run: bundle install
+        working-directory: android
 
       - name: Run fastlane lane
-        run: bundle exec fastlane deploy
+        run: bundle exec fastlane deploy_release
         working-directory: android
         env:
-          VERSION_NAME: ${{outputs.version.VERSION}}
+          VERSION_NAME: ${{ steps.version.VERSION }}
diff --git a/frontend/android/fastlane/Fastfile b/frontend/android/fastlane/Fastfile
index 1ce49f1..7b8f0f2 100644
--- a/frontend/android/fastlane/Fastfile
+++ b/frontend/android/fastlane/Fastfile
@@ -1,28 +1,16 @@
-# This file contains the fastlane.tools configuration
-# You can find the documentation at https://docs.fastlane.tools
-#
-# For a list of all available actions, check out
-#
-#     https://docs.fastlane.tools/actions
-#
-# For a list of all available plugins, check out
-#
-#     https://docs.fastlane.tools/plugins/available-plugins
-#
-
 # Uncomment the line if you want fastlane to automatically update itself
 # update_fastlane
 
 default_platform(:android)
 
 platform :android do
-  desc "Runs all the tests"
-  lane :test do
-    gradle(task: "test")
-  end
+  # desc "Runs all the tests"
+  # lane :test do
+  #   gradle(task: "test")
+  # end
 
-  desc "Submit a new build to the closed testing lane"
-  lane :closed_testing do
+  desc "Deploy a new version as a preview version"
+  lane :deploy_testing do
     gradle(
       task: "bundle",
       # flavor: "staging",
@@ -35,13 +23,13 @@ platform :android do
       )
   end
 
-  desc "Deploy a new release to the Google Play"
-  lane :deploy do
+  desc "Deploy a new version as a full release"
+  lane :deploy_release do
     gradle(
       task: "clean assembleRelease",
       properties: {
         # loaded from environment
-        android.injected.version.name: ENV["VERSION_NAME"],
+        "android.injected.version.name" => ENV["VERSION_NAME"],
       }
       )
     upload_to_play_store(
diff --git a/frontend/android/fastlane/README.md b/frontend/android/fastlane/README.md
index 574d585..897c89f 100644
--- a/frontend/android/fastlane/README.md
+++ b/frontend/android/fastlane/README.md
@@ -15,29 +15,21 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do
 
 ## Android
 
-### android test
+### android deploy_testing
 
 ```sh
-[bundle exec] fastlane android test
+[bundle exec] fastlane android deploy_testing
 ```
 
-Runs all the tests
+Deploy a new version as a preview version
 
-### android closed_testing
+### android deploy_release
 
 ```sh
-[bundle exec] fastlane android closed_testing
+[bundle exec] fastlane android deploy_release
 ```
 
-Submit a new build to the closed testing lane
-
-### android deploy
-
-```sh
-[bundle exec] fastlane android deploy
-```
-
-Deploy a new version to the Google Play
+Deploy a new version as a full release
 
 ----
 
diff --git a/frontend/android/fastlane/report.xml b/frontend/android/fastlane/report.xml
deleted file mode 100644
index 07d4bb8..0000000
--- a/frontend/android/fastlane/report.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<testsuites>
-  <testsuite name="fastlane.lanes">
-    
-    
-    
-      
-      <testcase classname="fastlane.lanes" name="0: default_platform" time="0.000594355">
-        
-      </testcase>
-    
-      
-      <testcase classname="fastlane.lanes" name="1: bundle" time="11.355126485">
-        
-      </testcase>
-    
-      
-      <testcase classname="fastlane.lanes" name="2: upload_to_play_store" time="63.414149183">
-        
-      </testcase>
-    
-  </testsuite>
-</testsuites>