Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support context/matrix variables and Composite Actions inputs in steps of type 'uses' #1479

Closed
umarcor opened this issue Nov 12, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@umarcor
Copy link

umarcor commented Nov 12, 2021

Describe the enhancement

It is currently not possible to use variables from the matrix (in a regular workflow), or inputs (in a Composite Action) to define the Actions to be used in steps of type uses. The workflow won't start because of a parser/syntax issue: the uses' attribute must be a path, a Docker image, or owner/repo@ref`.

Code Snippet

See https://github.com/hdl/containers/blob/GHA-MWEs/.github/workflows/MWE-1479.yml and https://github.com/hdl/containers/blob/GHA-MWEs/utils/mwe-input-var-in-uses/action.yml:

  matrix-var-in-uses-name:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        action:
          - actions/checkout
    steps:
      - uses: ${{ matrix.action }}@v2


  matrix-var-in-uses-version:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        version:
          - v1
          - v2
    steps:
      - uses: actions/checkout@${{ matrix.version }}


  matrix-var-in-uses-docker:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        img:
          - debian:bullseye-slim
          - debian:buster-slim
    steps:
     - uses: docker://${{ matrix.img }}


  matrix-var-in-uses-docker-tag:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        img:
          - bullseye-slim
          - buster-slim
    steps:
     - uses: docker://debian:${{ matrix.img }}


  matrix-var-in-uses-action:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: ./utils/mwe-input-var-in-uses
name: '[HDLC] MWE Input variable in uses'
description: 'Minimal Working Example to reproduce a bug when using an input in a uses step of a Composite Action.'

inputs:
  version:
    description: 'Version of actions/checkout to use.'
    default: 'v2'
    required: false
  image:
    description: 'Name of the container image.'
    default: 'asciidoctor/docker-asciidoctor'
    required: true

runs:
  using: 'composite'
  steps:
    - uses: actions/checkout@${{ inputs.version }}
    - uses: docker://${{ inputs.image }}
      with:
        args: doc/make.sh

Additional information

The inability to use Composite Action inputs in steps of type uses: docker:// is particularly uncomfortable, because it forces using the docker CLI explicitly. Therefore, environment variables and binds need to be manually and explicitly described. See, for instance, the following workaround to the Composite Action above: https://github.com/VUnit/vunit_action/blob/master/action.yml.

Being able to use the context would be a suitable solution to using a local action without explicitly checking out the repository, as discussed in #646 (comment). Precisely, uses: ${{ github.repository }}/.github/myaction@${{ github.ref_name }} would be equivalent to:

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

/cc @thboop, per #646 (comment)
/cc @aramfe

@ChristopherHX
Copy link
Contributor

You could try my action as a workaround, which writes and calls an interpolated action.yml file, as long as you don't want to call reusable workflows. Beware multline inputs are dangerous and pre run steps are skipped.
https://github.com/ChristopherHX/conditional

- uses: ChristopherHX/conditional@b4a9649204f81002ec9a4ef7d4bf7d6b2ab7fa55
  with:
    step: |
      uses: docker://${{ inputs.image }}
      with:
        args: doc/make.sh
- uses: ChristopherHX/conditional@b4a9649204f81002ec9a4ef7d4bf7d6b2ab7fa55
  with:
    step: |
      uses: actions/checkout@${{ matrix.version }}
- uses: ChristopherHX/conditional@b4a9649204f81002ec9a4ef7d4bf7d6b2ab7fa55
  with:
    step: |
      uses: ${{ matrix.action }}@v2

@antdking
Copy link

This would be an amazing feature to have (as well as cascading working-directory support).

I understand the reasoning for no variables, but it'd be great if you can allow github.action_path, or maybe a parameter called relative-to-caller: true, which causes uses: to look up relative to the current github.action_path.

For relative actions in an actions monorepo, I'm currently using a hack that exposes the action's parent directory.

FundingOptions/actions@6f3e0e7

This amazingly works, but could very easily break if sparse checkouts are implemented for actions, so treat this as "very undocumented behaviour."


@ChristopherHX, I love that workaround, and I wish I'd thought of it when I did my pre-processor (clean-actions) ages ago, it would have simplified so much 🤣

@garciasdos
Copy link

Hoping this feature arrives soon too 🤞🏼

@ethomson
Copy link
Contributor

Hi @umarcor, this seems like a possibly useful addition. However, suggestions for GitHub Actions functionality belong in the GitHub feedback forum, where the product managers and engineers will be able to review them. This repository is really only focused on the runner application, which is a very small component of GitHub Actions. If you could open this issue there, that would be very helpful for us! 😄

In the meantime, I'm closing this issue here. Thanks again!

@umarcor
Copy link
Author

umarcor commented Dec 18, 2021

@ethomson maybe you can create a GitHub feedback label in this repo?

@umarcor
Copy link
Author

umarcor commented Dec 18, 2021

Ref: community/community#9049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants