# Weekly Release Tagging and Beta Deployment Workflow
# ===================================================

# Purpose:
# - Automate weekly version tagging for consistent software versioning
# - Trigger automated beta releases across multiple platforms
# - Maintain a predictable release cycle

# Workflow Overview:
# - Runs automatically every Sunday at 4:00 AM UTC
# - Supports manual triggering via workflow_dispatch
# - Utilizes Gradle Reckon plugin for intelligent versioning
# - Triggers multi-platform build and publish workflow

# Key Features:
# - Automatic semantic versioning
# - Cross-platform release automation
# - Configurable target branch for releases
# - Full repository history checkout for accurate versioning

# Versioning Strategy:
# - Uses Reckon Gradle plugin for semantic versioning
# - Generates production-ready (final) version tags
# - Provides consistent and predictable version incrementation

# Release Process:
# 1. Checkout repository with full commit history
# 2. Setup Java 17 development environment
# 3. Create and push new version tag
# 4. Trigger multi-platform build and publish workflow

# Prerequisites:
# - Gradle project configured with Reckon plugin
# - Java 17 development environment
# - Configured multi-platform build workflow
# - GitHub Actions permissions for workflow dispatch

# Workflow Inputs:
# - target_branch: Branch to use for releases (default: 'dev')
#   Allows flexible release targeting across different branches

# Security Considerations:
# - Uses GitHub's native GITHUB_TOKEN for authentication
# - Controlled workflow dispatch with specific inputs
# - Limited to authorized repository members

# Potential Use Cases:
# - Regular software release cycles
# - Automated beta testing distributions
# - Consistent multi-platform deployment

# Workflow Triggers:
# - Scheduled weekly run (Sunday 4:00 AM UTC)
# - Manual workflow dispatch
# - Callable from other workflows

# ##############################################################################
#                 DON'T EDIT THIS FILE UNLESS NECESSARY                        #
# ##############################################################################

name: Tag Weekly Release

on:
  # Allow manual triggering of the workflow
  workflow_dispatch:
  # Schedule the workflow to run weekly
  schedule:
    # Runs at 04:00 UTC every Sunday
    # Cron syntax: minute hour day-of-month month day-of-week
    - cron: '0 4 * * 0'

concurrency:
  group: "weekly-release"
  cancel-in-progress: false

jobs:
  tag:
    name: Tag Weekly Release
    runs-on: ubuntu-latest
    steps:
      # Checkout the repository with full history for proper versioning
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # Setup Java environment for Gradle operations
      - name: Set up JDK 21
        uses: actions/setup-java@v4.2.2
        with:
          distribution: 'temurin'
          java-version: '21'

      # Create and push a new version tag using Reckon
      # This uses the 'final' stage for production-ready releases
      - name: Tag Weekly Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: ./gradlew :reckonTagPush -Preckon.stage=final

      # Trigger the build and publish workflow for beta release
      # This starts the process of building and deploying the app to various platforms
      - name: Trigger Workflow
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.actions.createWorkflowDispatch({
              owner: context.repo.owner,
              repo: context.repo.repo,
              workflow_id: 'multi-platform-build-and-publish.yml',
              ref: 'development', 
              inputs: {
                "release_type": "beta",
              },
            })

