Assign workflow_dispatch inputs of previous runs to new github workflow inputs

38 views Asked by At

I'm dealing with a single workflow that takes workflow_dispatch inputs from the user and runs. After the workflow logs have passed their retention limits (30 days) I need to rerun the same workflow the second time however, the second run should get the same inputs that were used for the first run more than 30 days earlier.

I wish to dynamically set the key-value for workflow_dispatch inputs by reading the key-value from a file generated by a previous run.

name: Redirect Inputs to File

on:
  workflow_dispatch:
    inputs:
      input1:
        description: 'Input 1'
        required: true
        default: 'Default Value 1'
      input2:
        description: 'Input 2'
        required: true
        default: 'Default Value 2'
      previousrunid:
        description: 'Enter previous runid'
        required: true
        default: '4356678'

jobs:
  redirect-inputs:
    runs-on: windows-latest
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Run PowerShell script to dump inputs to file STACK
        shell: pwsh
        run: |
          $Inputs = @"
          ${{ toJson(github.event.inputs) }}
          "@ | ConvertFrom-Json
          
          $InputData = $Inputs | ConvertTo-Json
          Write-Host $InputData
          $InputData | Out-File -FilePath "C:\Temp\inputs.json"
          Get-Content -Path "C:\Temp\inputs.json"

If the user provides the previous previousrunid my workflow reads the inputs from C:\Temp\inputs.json and must assign the key-values to the current run inputs i.e ${{ github.event.inputs.<key> }} if that is possible?

Reference: How do we write GITHUB ACTIONS workflow_dispatch user inputs to a file and read it back

0

There are 0 answers