Add Forgejo runner configuration for automated builds

This commit is contained in:
cmclark00 2025-03-20 16:12:39 -04:00
parent dcd389c3f2
commit 64fccdb249
2 changed files with 171 additions and 0 deletions

60
.forgejo/README.md Normal file
View file

@ -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 <your-forgejo-instance-url> \
--token <your-registration-token> \
--name <runner-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 `<your-forgejo-instance-url>`, `<your-registration-token>`, and `<runner-name>` 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/).

View file

@ -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.