How to read branch name from json and use for "ref" in actions/checkout@v2

My branch is defined in my.json
{
“test-repo”:{
“url”:“https://github.com/test/test-repo.git”,
“release”:“1.0.0_rc7”
}
}
I want use release from this json file to checkout specific branch like

  • name: Check out test repo
    env:
    TEST_BRANCH: ${{ jq ‘.[“test-repo”].release’ my.json }}
    uses: actions/checkout@v2
    with:
    repository: test/test-repo
    ref: TEST_BRANCH path: test-repo token: {{ secrets.ACCESS_TOKEN }}

But this fails with jq error. Any other way to read from json and use in actions workflow?

@koteswara-kelam,
Please try like as below, I have tested and it can work fine as expected:

- name: read json and set env
  run: echo "::set-env name=TEST_BRANCH::$(jq -r '."test-repo".release' my.json)"

- name: Checkout code
  uses: actions/checkout@v2
  with:
    repository: test/test-repo
    ref: ${{ env.TEST_BRANCH }}
    token: {{ secrets.ACCESS_TOKEN }}
1 Like

Thanks @brightran it worked well.