From 64fccdb249c8168160a841711cea4051dc4edde1 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Thu, 20 Mar 2025 16:12:39 -0400 Subject: [PATCH] Add Forgejo runner configuration for automated builds --- .forgejo/README.md | 60 +++++++++++++++++++ .forgejo/workflows/build.yml | 111 +++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 .forgejo/README.md create mode 100644 .forgejo/workflows/build.yml diff --git a/.forgejo/README.md b/.forgejo/README.md new file mode 100644 index 0000000..1d87e76 --- /dev/null +++ b/.forgejo/README.md @@ -0,0 +1,60 @@ +# Forgejo Runner Setup for TetriStats + +This directory contains the workflow configuration for building and releasing the TetriStats Android APK using Forgejo runners. + +## Setting up a Forgejo Runner + +To set up a Forgejo runner for this repository: + +1. Navigate to your Forgejo instance and log in. + +2. Go to your repository settings. + +3. Navigate to "Actions" or "CI/CD" section. + +4. Click on "Runners" and then "Add Runner." + +5. Follow the instructions provided by Forgejo to register a new runner. + +### Example runner registration commands: + +```bash +# Download the Forgejo runner +curl -o forgejo-runner -L https://code.forgejo.org/forgejo/runner/releases/download/v3.3.0/forgejo-runner-3.3.0-linux-amd64 +chmod +x forgejo-runner + +# Register the runner with your Forgejo instance +./forgejo-runner register --no-interactive \ + --instance \ + --token \ + --name \ + --labels ubuntu-latest,linux \ + --executor docker \ + --docker-image node:16 \ + --docker-volumes /var/run/docker.sock:/var/run/docker.sock + +# Start the runner +./forgejo-runner daemon +``` + +Replace ``, ``, and `` with your own values. + +## Runner Configuration + +The workflow is configured to: + +1. Build a signed Android APK +2. Create a release with the APK attached when: + - A new tag is pushed (for official releases) + - A commit is pushed to main/master (for development releases) + +## Troubleshooting + +If you encounter issues with the runner: + +1. Check the runner logs for errors +2. Ensure the runner has sufficient permissions to access your repository +3. Verify that your Forgejo instance supports actions similar to GitHub Actions +4. Make sure your runner environment has all necessary dependencies installed (Java 17, Android SDK, etc.) + +For more information, refer to the [Forgejo Documentation](https://forgejo.org/docs/). \ No newline at end of file diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..828c740 --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,111 @@ +name: Build and Release Android APK + +on: + push: + branches: [ main, master ] + tags: + - 'v*' + workflow_dispatch: + +# Add permissions needed to create releases +permissions: + contents: write + packages: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Get version name from build.gradle + id: version + run: | + VERSION_NAME=$(grep -o 'versionName = "[^"]*' app/build.gradle.kts | cut -d'"' -f2) + echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV + echo "APP_VERSION=$VERSION_NAME" >> $GITHUB_OUTPUT + + # Setup keystore directory + - name: Setup keystore directory + run: mkdir -p app/keystore + + # Generate a keystore for signing + - name: Generate keystore + run: | + keytool -genkey -v -keystore app/keystore/release.keystore -storepass android -alias release -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=TetriStats,O=Accidental Productions,L=Unknown,C=US" + + # Set environment variables for signing + - name: Set signing environment variables + run: | + echo "KEYSTORE_PASSWORD=android" >> $GITHUB_ENV + echo "KEY_ALIAS=release" >> $GITHUB_ENV + echo "KEY_PASSWORD=android" >> $GITHUB_ENV + + # Build a signed release APK + - name: Build Release APK + run: ./gradlew assembleRelease + + - name: Debug directory structure + run: find app/build/outputs -type f -name "*.apk" | sort + + - name: Rename APK for tag release + if: startsWith(github.ref, 'refs/tags/') + run: | + mkdir -p renamed_apk + cp app/build/outputs/apk/release/app-universal-release.apk renamed_apk/TetriStats-${{ env.VERSION_NAME }}.apk + + - name: Rename APK for push release + if: ${{ !startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' }} + run: | + mkdir -p renamed_apk + cp app/build/outputs/apk/release/app-universal-release.apk renamed_apk/TetriStats-${{ env.VERSION_NAME }}-${{ github.run_number }}.apk + + - name: Upload APK as artifact + uses: actions/upload-artifact@v4 + with: + name: TetriStats-APK + path: app/build/outputs/apk/release/*.apk + + # For Forgejo, create release with artifact + - name: Create Release on Tags + if: startsWith(github.ref, 'refs/tags/') + uses: ncipollo/release-action@v1 + with: + tag: ${{ github.ref_name }} + name: Release ${{ env.VERSION_NAME }} + draft: false + prerelease: false + artifacts: renamed_apk/TetriStats-${{ env.VERSION_NAME }}.apk + body: | + TetriStats Android App Release v${{ env.VERSION_NAME }} + + Automatically generated release from Forgejo. + + Download the APK from the assets below. + + - name: Create Release on Push + if: ${{ !startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' }} + uses: ncipollo/release-action@v1 + with: + tag: v${{ env.VERSION_NAME }}-${{ github.run_number }} + name: Release v${{ env.VERSION_NAME }}-${{ github.run_number }} + draft: false + prerelease: false + artifacts: renamed_apk/TetriStats-${{ env.VERSION_NAME }}-${{ github.run_number }}.apk + body: | + TetriStats Android App Release v${{ env.VERSION_NAME }}-${{ github.run_number }} + + Automatically generated release from Forgejo. + + Download the APK from the assets below. \ No newline at end of file