rmcl 0.3.1

A fully featured Minecraft TUI launcher
name: publish winget

on:
  workflow_call:
    inputs:
      plan:
        required: true
        type: string

permissions:
  contents: write

jobs:
  publish:
    runs-on: windows-latest

    steps:
      - name: prepare WinGet manifest
        id: manifest
        shell: pwsh
        env:
          PLAN: ${{ inputs.plan }}
        run: |
          $plan = $env:PLAN | ConvertFrom-Json
          $tag = $plan.announcement_tag
          $version = $plan.releases[0].app_version
          $identifier = 'Objz.Rmcl'
          $packagePath = "manifests/o/Objz/Rmcl/$version"
          $assetPath = "winget-manifest-$version.zip"
          $installerFile = 'rmcl-x86_64-pc-windows-msvc.msi'
          $checksumFile = "$installerFile.sha256"
          $installerUrl = "https://github.com/objz/rmcl/releases/download/$tag/$installerFile"
          $checksumUrl = "https://github.com/objz/rmcl/releases/download/$tag/$checksumFile"

          New-Item -ItemType Directory -Path $packagePath -Force | Out-Null
          Invoke-WebRequest -Uri $checksumUrl -OutFile "$packagePath/$checksumFile"
          $checksum = (((Get-Content "$packagePath/$checksumFile" -Raw) -split '\s+')[0]).ToUpperInvariant()

          $versionManifest = @(
            '# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.9.0.schema.json'
            "PackageIdentifier: $identifier"
            "PackageVersion: $version"
            'DefaultLocale: en-US'
            'ManifestType: version'
            'ManifestVersion: 1.9.0'
          ) -join "`n"
          $versionManifest | Set-Content -Path "$packagePath/$identifier.yaml" -Encoding utf8

          $installerManifest = @(
            '# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.9.0.schema.json'
            "PackageIdentifier: $identifier"
            "PackageVersion: $version"
            'InstallerType: wix'
            'Scope: machine'
            'InstallerSwitches:'
            '  Silent: /quiet /norestart'
            '  SilentWithProgress: /passive /norestart'
            'UpgradeBehavior: install'
            'Commands:'
            '- rmcl'
            'Installers:'
            '- Architecture: x64'
            "  InstallerUrl: $installerUrl"
            "  InstallerSha256: $checksum"
            'ManifestType: installer'
            'ManifestVersion: 1.9.0'
          ) -join "`n"
          $installerManifest | Set-Content -Path "$packagePath/$identifier.installer.yaml" -Encoding utf8

          $localeManifest = @(
            '# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.9.0.schema.json'
            "PackageIdentifier: $identifier"
            "PackageVersion: $version"
            'PackageLocale: en-US'
            'Publisher: objz'
            'PublisherUrl: https://github.com/objz'
            'PublisherSupportUrl: https://github.com/objz/rmcl/issues'
            'Author: objz'
            'PackageName: rmcl'
            'PackageUrl: https://github.com/objz/rmcl'
            'License: GPL-3.0-only'
            'LicenseUrl: https://github.com/objz/rmcl/blob/master/LICENSE'
            'Copyright: Copyright (c) objz'
            'ShortDescription: Minecraft launcher TUI'
            'Description: A fully featured Minecraft launcher TUI with Microsoft account authentication, instance management, mod loaders, imports, content management, and launch support.'
            'Moniker: rmcl'
            'Tags:'
            '- minecraft'
            '- launcher'
            '- cli'
            '- tui'
            'ManifestType: defaultLocale'
            'ManifestVersion: 1.9.0'
          ) -join "`n"
          $localeManifest | Set-Content -Path "$packagePath/$identifier.locale.en-US.yaml" -Encoding utf8

          Remove-Item "$packagePath/$checksumFile"
          Compress-Archive -Path manifests -DestinationPath $assetPath -Force

          "path=$packagePath" >> $env:GITHUB_OUTPUT
          "asset=$assetPath" >> $env:GITHUB_OUTPUT

      - name: upload WinGet manifest to GitHub Release
        shell: pwsh
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
          PLAN: ${{ inputs.plan }}
        run: |
          $plan = $env:PLAN | ConvertFrom-Json
          gh release upload "$($plan.announcement_tag)" "${{ steps.manifest.outputs.asset }}" --clobber

      - name: submit WinGet manifest
        shell: pwsh
        run: |
          Invoke-WebRequest -Uri https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
          .\wingetcreate.exe submit "${{ steps.manifest.outputs.path }}" --token "${{ secrets.WINGET_TOKEN }}"