Read file content in expressions

Hi! We have a ‘.node-version’ containing the node version used in our project and we would like to use it for Github Actions instead of hardcoding it. The current code:

name: Continuous Integration

on: push

jobs:
  main:
    name: Main
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1
        with:
          fetch-depth: 1

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 12.8.0

would become something like:

name: Continuous Integration

on: push

jobs:
  main:
    name: Main
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1
        with:
          fetch-depth: 1

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: ${{ readFile('.node-version') }}

I didn’t find a function like that at https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions.

Also, it seems it is not possible to use expressions in ‘uses’ clauses: https://github.community/t5/GitHub-Actions/Usage-of-expressions-and-contexts-in-uses-clause/m-p/39502#M3835. Do you have any workaournd?

4 Likes

I’d second this, although I’d like to see something more versatile, such as an include directive.  So for instance, I could do this…

job1:
    strategy:
      include: matrix.yml
exclude:
- os: ubuntu-latest
build_type: client

and then have a matrix.yml file that contains this

matrix:
  os: [windows-latest, macOS-latest, ubuntu-latest]
  build_type: [full, client]

This would allow much more versatility in building workflows by allowing developers to essentially composite a large number of declarations together that could then be reused elsewhere.

+1. My usecase is reading a rust-toolchain file and putting its contents into a matrix variable.