feat(build): add release automation tasks and CI/CD workflows
Some checks failed
CI / test (push) Has been cancelled

- Introduced Gradle tasks for release preparation, version bumping, and git tagging.
- Added CI workflow for continuous integration on pushes and pull requests.
- Implemented release workflow for automated builds and Gitea releases upon tag pushes.
- Created scripts for manual release processes on Windows and Linux/macOS.
- Documented the release process and Gitea Actions setup in the new RELEASE.md and setup-gitea-actions.md files.
This commit is contained in:
Mr¤KayJayDee
2025-10-23 23:42:16 +02:00
parent 1a79c54cfb
commit a4fc6a158e
7 changed files with 709 additions and 0 deletions

77
scripts/release.bat Normal file
View File

@@ -0,0 +1,77 @@
@echo off
REM PlayHours Release Script for Windows
REM This script automates the release process
echo Starting PlayHours release process...
REM Check if we're in a git repository
git status >nul 2>&1
if %errorlevel% neq 0 (
echo Error: Not in a git repository
exit /b 1
)
REM Check if there are uncommitted changes
git diff --quiet
if %errorlevel% neq 0 (
echo Warning: You have uncommitted changes. Please commit them first.
echo Do you want to continue anyway? (y/N)
set /p choice=
if /i not "%choice%"=="y" (
echo Release cancelled.
exit /b 1
)
)
REM Get current version
for /f "tokens=2 delims==" %%a in ('findstr "mod_version=" gradle.properties') do set CURRENT_VERSION=%%a
echo Current version: %CURRENT_VERSION%
REM Ask for new version
echo Enter new version (current: %CURRENT_VERSION%):
set /p NEW_VERSION=
if "%NEW_VERSION%"=="" (
echo No version entered. Using current version.
set NEW_VERSION=%CURRENT_VERSION%
)
REM Update version in gradle.properties
powershell -Command "(Get-Content gradle.properties) -replace 'mod_version=%CURRENT_VERSION%', 'mod_version=%NEW_VERSION%' | Set-Content gradle.properties"
REM Build the project
echo Building project...
call gradlew clean build
if %errorlevel% neq 0 (
echo Build failed!
exit /b 1
)
REM Create git tag
echo Creating git tag v%NEW_VERSION%...
git tag -a v%NEW_VERSION% -m "Release v%NEW_VERSION%"
if %errorlevel% neq 0 (
echo Failed to create tag!
exit /b 1
)
REM Push changes and tags
echo Pushing changes and tags...
git push origin main
git push origin v%NEW_VERSION%
if %errorlevel% neq 0 (
echo Failed to push changes!
exit /b 1
)
echo.
echo Release v%NEW_VERSION% completed successfully!
echo.
echo Next steps:
echo 1. Go to your Gitea repository
echo 2. Create a new release with tag v%NEW_VERSION%
echo 3. Upload the JAR file from build\libs\playhours-%NEW_VERSION%.jar
echo 4. Add release notes
echo.
echo JAR file location: build\libs\playhours-%NEW_VERSION%.jar
pause

74
scripts/release.sh Normal file
View File

@@ -0,0 +1,74 @@
#!/bin/bash
# PlayHours Release Script for Linux/macOS
# This script automates the release process
set -e
echo "Starting PlayHours release process..."
# Check if we're in a git repository
if ! git status >/dev/null 2>&1; then
echo "Error: Not in a git repository"
exit 1
fi
# Check if there are uncommitted changes
if ! git diff --quiet; then
echo "Warning: You have uncommitted changes. Please commit them first."
read -p "Do you want to continue anyway? (y/N): " choice
if [[ ! "$choice" =~ ^[Yy]$ ]]; then
echo "Release cancelled."
exit 1
fi
fi
# Get current version
CURRENT_VERSION=$(grep "mod_version=" gradle.properties | cut -d'=' -f2)
echo "Current version: $CURRENT_VERSION"
# Ask for new version
read -p "Enter new version (current: $CURRENT_VERSION): " NEW_VERSION
if [ -z "$NEW_VERSION" ]; then
echo "No version entered. Using current version."
NEW_VERSION=$CURRENT_VERSION
fi
# Update version in gradle.properties
sed -i "s/mod_version=$CURRENT_VERSION/mod_version=$NEW_VERSION/" gradle.properties
# Build the project
echo "Building project..."
./gradlew clean build
if [ $? -ne 0 ]; then
echo "Build failed!"
exit 1
fi
# Create git tag
echo "Creating git tag v$NEW_VERSION..."
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
if [ $? -ne 0 ]; then
echo "Failed to create tag!"
exit 1
fi
# Push changes and tags
echo "Pushing changes and tags..."
git push origin main
git push origin "v$NEW_VERSION"
if [ $? -ne 0 ]; then
echo "Failed to push changes!"
exit 1
fi
echo ""
echo "Release v$NEW_VERSION completed successfully!"
echo ""
echo "Next steps:"
echo "1. Go to your Gitea repository"
echo "2. Create a new release with tag v$NEW_VERSION"
echo "3. Upload the JAR file from build/libs/playhours-$NEW_VERSION.jar"
echo "4. Add release notes"
echo ""
echo "JAR file location: build/libs/playhours-$NEW_VERSION.jar"

View File

@@ -0,0 +1,173 @@
# Setting up Gitea Actions for PlayHours
This guide will help you configure Gitea Actions for automated releases on your self-hosted Gitea instance.
## Prerequisites
- Self-hosted Gitea instance with Actions enabled
- Repository with proper permissions
- Git repository with the PlayHours project
## Step 1: Enable Actions in Gitea
1. **Check Gitea version**: Ensure you're running Gitea 1.19+ (Actions support)
2. **Enable Actions globally** (if you're the admin):
- Go to Site Administration → Actions
- Enable "Enable Actions"
3. **Enable Actions for your repository**:
- Go to your repository settings
- Under "Features", enable "Actions"
## Step 2: Configure Repository Secrets
1. **Go to repository settings****Secrets**
2. **Add the following secrets** (if needed):
### Required Secrets
- `GITEA_TOKEN`: Your Gitea API token (for Gitea API access)
- `GITEA_API_URL`: Your Gitea instance URL (optional, defaults to current instance)
### Creating API Tokens
#### For Gitea Token:
1. Go to your Gitea profile → Settings → Applications
2. Generate new token with `repo` scope
3. Copy the token and add it as `GITEA_TOKEN` secret
#### For Custom Gitea Instance (optional):
1. Go to repository settings → Secrets
2. Add `GITEA_API_URL` with your instance URL (e.g., `https://your-gitea.com`)
## Step 3: Verify Workflow Files
Ensure these files exist in your repository:
- `.gitea/workflows/ci.yml`
- `.gitea/workflows/release.yml`
## Step 4: Test the Setup
### Test CI Workflow
1. **Make a small change** to your code
2. **Commit and push** to main branch
3. **Check Actions tab** - you should see a CI workflow running
### Test Release Workflow
1. **Create a test tag**:
```bash
git tag -a v1.0.0-test -m "Test release"
git push origin v1.0.0-test
```
2. **Check Actions tab** - you should see a release workflow running
3. **Check Releases** - a new release should be created
## Step 5: Configure Runner (if needed)
If you don't have runners available, you may need to set up self-hosted runners:
### Using Docker Runner
1. **Install act** (local Actions runner):
```bash
# On Linux/macOS
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
# On Windows (with Chocolatey)
choco install act-cli
```
2. **Test locally**:
```bash
act -l # List available workflows
act push # Run push workflow
```
### Using Self-Hosted Runner
1. **Download runner** from your Gitea instance
2. **Configure and register** the runner
3. **Start the runner service**
## Troubleshooting
### Common Issues
1. **Actions not showing up**:
- Check if Actions are enabled in repository settings
- Verify Gitea version supports Actions
2. **Workflow fails to run**:
- Check runner availability
- Verify workflow syntax
- Check secrets configuration
3. **Build fails**:
- Verify Java 17 is available
- Check Gradle wrapper permissions
- Review build logs for specific errors
4. **Release creation fails**:
- Verify API tokens have correct permissions
- Check if release already exists
- Review Gitea API rate limits
### Debug Steps
1. **Check Actions logs**:
- Go to Actions tab in your repository
- Click on failed workflow
- Review step-by-step logs
2. **Test locally**:
```bash
# Test build
./gradlew clean build
# Test with act
act push -v
```
3. **Verify secrets**:
- Check secret names match exactly
- Verify token permissions
- Test API access manually
## Advanced Configuration
### Custom Runner Labels
If using self-hosted runners, you can specify runner labels in workflows:
```yaml
jobs:
build:
runs-on: [self-hosted, linux, java17]
```
### Environment Variables
Add environment-specific variables:
```yaml
env:
JAVA_VERSION: '17'
GRADLE_OPTS: '-Xmx2g'
```
### Custom Gitea Instance Configuration
If your Gitea instance is not at the default URL:
```yaml
env:
GITEA_API_URL: ${{ secrets.GITEA_API_URL }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
```
## Security Considerations
1. **Token Permissions**: Use minimal required permissions for API tokens
2. **Secret Management**: Never commit secrets to repository
3. **Runner Security**: Secure self-hosted runners properly
4. **Access Control**: Limit who can trigger releases
## Monitoring and Maintenance
1. **Regular Updates**: Keep Gitea and Actions up to date
2. **Log Monitoring**: Check Actions logs for issues
3. **Token Rotation**: Regularly rotate API tokens
4. **Runner Health**: Monitor runner performance and availability