Usage of expressions and contexts in `uses` clause

I’ve got a use case where I want to test my action in an example workflow.
This works out great for me with hardcoded values in the uses clause. But it would be much more elegant to be able to use context variables like github.repository in the uses clause to be fork agnostic.

Something like this:

...
        uses: "${{ github.repository }}@master"
...

In my case I test a fork of a Github Repo. This means the root of my fork has another repository name than I do.
So it’ll be great if this repository could be resolved dynamically by using the github context.

This is currently not possible and ends with:

### ERRORED 11:55:40Z

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/gpr.yaml (Line: 14, Col: 13): Unrecognized named-value: 'github'. Located at position 1 within expression: github.repository

You can use path as argument for uses, so this should do the trick

- uses: ./
4 Likes

Thank you very much. This did the trick. Kudos to you :smiley:

For a bit more color.  Because we have the settings where a repo or org owner can specify if they want third party actions or not we need to be able to resolve the full list of referenced actions before we start the workflow.  If we enabled expressions in the uses section that would not be possible until runtime and we would potentially get hours into a job before it failed due to this policy.

2 Likes

Thank you for this explanation

Do you have a working example for this? When I tried this it was not doing anything: https://github.com/eps1lon/actions-label-merge-conflict/blob/2f617ca50dfb880adbf628a61e3d4f427561a1df/.github/workflows/ci.yml#L24

This works fine for me if you have an action.yml in your root directory

- uses: actions/checkout@v2
- uses: ./

@wipe2238 The link to the docs seems to be outdated.

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-an-action-in-the-same-repository-as-the-workflow