1

Note: Both the caller and called reusable repo are public and their permissions are correctly set.

Below is my caller repo actions_param workflow test.yml:

name: TEST  main xml read

on:
  push:
    branches: main
    
jobs:
  inside_actionyml:
    uses: knowyrtech/betech/.github/workflows/extractxmldata.yml@feature365
    with:
      xml_Path: 'D:\myxl\setparam.xml'
      key_name: 'app_name'

As you can see it calls betech's extractxmldata.yml from branch feature365.

This workflow will help get values from xml given the key by invoking xml-functions.ps1.

name: Read XML

on:
  workflow_call:
    inputs:
        xml_Path:
          required: true
          default: ''
          type: string
        key_name:
          required: true
          default: ''
          type: string      
  
jobs: 
  Extract-keys:
    runs-on: 'windows-latest'
    steps:
      - uses: actions/checkout@v3

      - name: Get present dir
        run: |
          Get-Location

      - name: List dir
        run: |
          dir   

      - name: Call power shell for extract XML values
        run: |
          set-location "${{ github.workspace }}\betech\scripts"
          ./xml-functions.ps1 "${{ inputs.xml_Path }}" "${{ inputs.key_name }}"

xml-functions.ps1 is placed under the repo's scripts folder as you may see here.

The called workflow calls the reusable workflow however the reusable workflow does not find the reusable repo and its file xml-functions.ps1 and throws an error as seen in the snapshot below:

error

Run set-location "D:\a\actions_param\actions_param\betech\scripts"
Set-Location: D:\a\_temp\0e075a8f-0439-43fc-9c45-1397748c0d29.ps1:2
Line |
   2 |  set-location "D:\a\actions_param\actions_param\betech\scripts"
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'D:\a\actions_param\actions_param\betech\scripts' because it does not exist.

Error: Process completed with exit code 1.

I tried the same on local Windows runner too and observed that the reusable repo betech does not get checkout [downloaded] at the runner at all and hence it fails to find xml-functions.ps1.

All I m concerned and need help is how to get xml-functions.ps1 looked up and called.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Ashar
  • 2,942
  • 10
  • 58
  • 122
  • IIUC, you expect a reusable workflow checkout step to checkout its own repo instead of the repo it's being run from? – Azeem May 19 '23 at 05:24
  • I understood the `uses:` in the calling repo Will checkout the called repo `xml-functions.ps1` Will I have to explicitly checkout the reusable called repo `betech` in the calling repo? I have not seen this as a requirement and I m new to github so not sure. – Ashar May 19 '23 at 05:42
  • The script you're using is not there as part of the workflow itself so it does not exist there without an explicit checkout. So, yes, you need to do something to have it there e.g. checkout or download it via its direct link (https://raw.githubusercontent.com/knowyrtech/betech/main/scripts/xml-functions.ps1). – Azeem May 19 '23 at 05:45
  • Apart from that, your [reusable workflow](https://github.com/knowyrtech/betech/blob/feature365/.github/workflows/extractxmldata.yml) has some linting issues. Lint it with https://rhysd.github.io/actionlint/. – Azeem May 19 '23 at 05:48
  • @Azeem linting issue has now been fixed. Checking how and where to checkout so to be able to find the `ps1` file – Ashar May 19 '23 at 05:56
  • Good. You may directly add that under `run` section if you don't have to worry about its logistics at all. – Azeem May 19 '23 at 05:59
  • i added the remote repo checkout but it does not seem to have been downloaded in `workspace` directory. https://github.com/knowyrtech/actions_param/edit/main/.github/workflows/test.yml – Ashar May 19 '23 at 06:07
  • Your checkout is nested and is in the first job. But, the workflow that needs it is in the second job. Jobs are run on different runners. So, it won't work. – Azeem May 19 '23 at 06:11
  • @Azeem i added explicit checkout as suggested with the name ` - name: Checkout remote repository suggested by stack user @Azeem` in the called workflow file https://github.com/knowyrtech/betech/edit/feature365/.github/workflows/extractxmldata.yml. Now the `ps1` file seems to be found. I will now work on collecting and displaying return values from the `ps1` function. Thank you for your help and if u can post the answer – Ashar May 19 '23 at 06:23
  • 1
    Good. This [checkout](https://github.com/knowyrtech/actions_param/blob/900116619e1c735b253d2e1b4a07b8202a12c3a5/.github/workflows/test.yml#L17-L22) step is redundant now. You may remove it. – Azeem May 19 '23 at 06:27
  • The current checkout dumps `scripts` folder in `workspace` but I wish to get it under the repo i.e `workspace\\scripts\xml-functions.ps1`. I changed ` path: "${{ github.workspace }}\betech"` while checkout but it fails. I don't want to create `betech` folder explicitly but need it auto-created like how `git clone` does. – Ashar May 19 '23 at 06:43
  • Remove `path` and it'll be nested. See https://github.com/actions/checkout for such examples. – Azeem May 19 '23 at 06:46
  • @Azeem i removed the `path` but i still do not see repo folder created ...see here: https://github.com/knowyrtech/betech/blob/feature365/.github/workflows/extractxmldata.yml – Ashar May 19 '23 at 06:52
  • It should be under your first checked out repo i.e. `$GITHUB_WORKSPACE/actions_param/actions_param/betech`. Check the nested directories with `dir` or `tree` command (if available). – Azeem May 19 '23 at 06:55
  • i removed `path` from test.yml first checkout too but don't see the `betech` repo folder created. Here: https://github.com/knowyrtech/actions_param/actions/runs/5021694199/jobs/9004334220. Basically I need the `.ps1` under `"${{ github.workspace }}\betech\scripts"` – Ashar May 19 '23 at 07:00
  • Looks like the intermediate `betech` is [not being created](https://github.com/knowyrtech/actions_param/actions/runs/5021694199/jobs/9004334220#step:8:6). Try `path: "${{ github.workspace }}/actions_param/betech`. – Azeem May 19 '23 at 07:11
  • 1
    @Azeem this worked ` path: "${{ github.workspace }}/betech"` – Ashar May 19 '23 at 09:15
  • So, finally, you got it to work? If yes, you may self-answer this with all the details. BTW, instead of making it a reusable workflow, you could make a [composite](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action) action for better reusability. All the best! – Azeem May 19 '23 at 10:14

0 Answers0