---
name: Generate Updates for Packages and Their Dependencies.
on:
  workflow_dispatch:
    inputs:
      version_cmd_input:
        description: "Packages to check for dependency tree updates."
        required: true
  workflow_call:
    inputs:
      version_cmd_input:
        type: string
        required: true
env:
  GH_TOKEN: ${{ secrets.CREW_PR_TOKEN }}  # setting GH_TOKEN for the entire workflow
permissions:                    # Global permissions configuration starts here
  actions: write
  contents: write
  packages: write
  pull-requests: write          # 'write' access to pull requests
jobs:
  dependencies:
    if: ${{ github.repository_owner == 'chromebrew' }}
    runs-on: ubuntu-24.04
    outputs:
      packages: ${{ steps.get-dependencies.outputs.packages }}
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '4.0.0'
      - name: Install bin/crew gem dependencies
        run: ruby bin/crew version
      - name: Get dependencies of core and buildessential packages
        id: get-dependencies
        run: echo "packages=$(ruby bin/crew deps ${{ inputs.version_cmd_input }} | sort | uniq | xargs | sed 's/Creating device.json.//')" >> "$GITHUB_OUTPUT"
  update-check:
    needs: dependencies
    if: ${{ github.repository_owner == 'chromebrew' }}
    uses: ./.github/workflows/Updater-on-Demand.yml
    secrets: inherit
    with:
      version_cmd_input: ${{ needs.dependencies.outputs.packages }}
