Greg
Greg

Reputation: 152

Rename a file based on release

I'm trying to rename a file when a new release is tagged, but it is failing.

    - name: rename file
      run: mv ./Code/.pio/build/attiny841/firmware.hex ./Code/.pio/build/attiny841/megadesk-${{ $GITHUB_REF_NAME }}.hex

However when it runs I get an error

Invalid workflow file: .github/workflows/version_pio_build.yml#L44
The workflow is not valid. .github/workflows/version_pio_build.yml (Line: 44, Col: 12): Unexpected symbol: '$GITHUB_REF_NAME'. Located at position 1 within expression: $GITHUB_REF_NAME

If I change this to

    - name: rename file
      run: mv ./Code/.pio/build/attiny841/firmware.hex ./Code/.pio/build/attiny841/megadesk-${{ env.GITHUB_REF_NAME }}.hex

Then the resulting execution is mv ./Code/.pio/build/attiny841/firmware.hex ./Code/.pio/build/attiny841/megadesk-.hex

Note this is triggered on a tag push.

    - name: env list
      run: env

This has a list of variables including

...
RUNNER_TOOL_CACHE=/opt/hostedtoolcache
ImageVersion=20220220.1
DOTNET_NOLOGO=1
GITHUB_REF_NAME=v25
GRAALVM_11_ROOT=/usr/local/graalvm/graalvm-ce-java11-22.0.0.2
GITHUB_JOB=build
AZURE_EXTENSION_DIR=/opt/az/azcliextensions
...

Upvotes: 0

Views: 1355

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 23190

Your problem here is that you used the wrong syntax.

Neither ${{ $GITHUB_REF_NAME }} nor ${{ env.GITHUB_REF_NAME }} will work, but just $GITHUB_REF_NAME will.

Therefore, your command line should be:

run: mv ./Code/.pio/build/attiny841/firmware.hex ./Code/.pio/build/attiny841/megadesk-$GITHUB_REF_NAME.hex

If you want to take a look, here is a demo:

Workflow file: https://github.com/GuillaumeFalourd/poc-github-actions/blob/main/.github/workflows/49-rename-on-release.yml

Workflow run: https://github.com/GuillaumeFalourd/poc-github-actions/runs/5359686796?check_suite_focus=true

Upvotes: 1

Related Questions