Search code examples
github-actions

Save step variable in github action not working


I have followed existing online documentations to come up with this code that save the variable file_size in the step bellow, however it's always blank, even when there are files avaliable, what am I doing wrong?

- name: Get modified files
  id: files
  uses: umani/[email protected]
  with:
    repo-token: ${{ github.token }}
    pattern: '^src.*\.(py)$'
    result-encoding: 'string'
- name: Check files size
  id: file_check
  run: |
    echo ::set-output name=file_size::$(printf "%s" "${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}" | wc -m)
    echo 'MESSAGE<<EOF' >> $GITHUB_ENV
    echo  "No valid file found, skipped"  >> $GITHUB_ENV
    echo 'EOF' >> $GITHUB_ENV
- name: Lint with pylint
  if: steps.vars.file_check.file_size > 1

This is the run result:

enter image description here

The bash command is correct as I tried it online:

enter image description here

So that just mean the variable isn't saved in github action, how come?


Solution

  • You need to pass the value to $GITHUB_ENV

    like so:

    echo "file_size="$(printf "%s" "${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}" | wc -m) >> $GITHUB_ENV
    

    Otherwise the value will not persist.