o.aboamer
o.aboamer

Reputation: 93

How to refactor deprecated set-env in github action

I have a github action that runs set-env, now as it is deprecated as mentioned here, how can refactor the following code?

 run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_HEAD_REF} | tr -cd '[:alnum:]\n' | cut -c -30 | tr '[:upper:]' '[:lower:]')"

Upvotes: 1

Views: 659

Answers (1)

Marcin Kłopotek
Marcin Kłopotek

Reputation: 5961

According to the documentation:

 run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr -cd '[:alnum:]\n' | cut -c -30 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

Additionally, instead of messing up with tr and cut you can get the branch name in a more convenient way using the GITHUB_REF built-in variable. It will simplify the script to

 run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV

Upvotes: 2

Related Questions