Reference a Context Variable in an Expression

Hi,

My company is moving stuff we have in Jenkins into Actions. When we want to put out a new version of our binaries or libraries, we update the relevant version numbers in a commit and then raise a version change PR.

The Jenkins scripted pipelines have a little bit of code in them to look at the latest commit message and check if it’s a version change commit, and we deploy on that basis. I’m trying to reproduce this in Actions, and have something like the following:

- shell: bash
        id: commit_message
        run: |
          commit_message=$(git log --format=%B -n 1 ${{ github.sha }})
          echo "::set-output name=commit_message::$commit_message"
      - shell: bash
        id: versioning
        run: |
          api_version=$(grep "^version" < safe-api/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')
          cli_version=$(grep "^version" < safe-cli/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')
          ffi_version=$(grep "^version" < safe-ffi/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g')
          echo "::set-output name=api_version::$api_version"
          echo "::set-output name=cli_version::$cli_version"
          echo "::set-output name=ffi_version::$ffi_version"
      #- shell: bash
        #run: make package-commit_hash-artifacts-for-deploy
        #if: !startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change")
      - shell: bash
        run: make package-version-artifacts-for-deploy
        if: startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change")
      - shell: bash
        run: ./resources/tag.sh "${{ steps.versioning.outputs.api_version }}" "safe-api"
        if: startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change") && contains(${{ steps.commit_message.outputs.commit_message }}, "safe-api")
      - shell: bash
        run: ./resources/tag.sh "${{ steps.versioning.outputs.cli_version }}" "safe-cli"
        if: startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change") && contains(${{ steps.commit_message.outputs.commit_message }}, "safe-cli")
      - shell: bash
        run: ./resources/tag.sh "${{ steps.versioning.outputs.ffi_version }}" "safe-ffi"
        if: startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change") && contains(${{ steps.commit_message.outputs.commit_message }}, "safe-ffi")
      - shell: bash
        run: make deploy-github-release
        if: startsWith(${{ steps.commit_message.outputs.commit_message }}, "Version change")

When I try and run this, I get the following error:

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/ci.yml (Line: 381, Col: 13): Unrecognized named-value: 'steps'

I’m wondering if you could advise what the correct way to do this is? I could do everything in one big Bash script, but I’m not sure that’s the best way to express what I’m trying to do.

Any advice would be appreciated.

Cheers,

Chris 

Did you try:

if: startsWith(steps.commit_message.outputs.commit_message, "Version change")

?

Yeah, that works - thanks!

Can I ask something else please? I’m getting a different error now, related to use of the logical not operator.

- shell: bash
   run: make package-version-artifacts-for-deploy
   if: ! startsWith(steps.commit_message.outputs.commit_message, 'Version change')

What is the correct way to use the logical not? I’ve tried it with and without the space. With the space:

Your workflow file was invalid: The pipeline is not valid. .github/workflows/ci.yml: (Line: 379, Col: 13, Idx: 14003) - (Line: 379, Col: 14, Idx: 14004): While parsing a tag, did not find expected tag URI.

Without the space:

yaml: line 378: did not find expected key

Using “!” as first character is the problem, put whole if inside quotes, just like in path filtering 

Yeah that works, thanks!