I have a workflow which creates a new branch with a name that I save as an env variable. the reason is I need the workflow to run on a new clean branch.
1 Job after that I want to check out the branch. the problem is I cant seem to use env variables on the "ref" in order to check it out.
is there a way to do this ? or does github not support this yet.
example code:
- name: Checkout to branch
uses: actions/checkout@v2
with:
repository: org/repo
token: ${{secrets.GIT_TOKEN}}
ref: $NEW_BRANCH_NAME
[edit] ANSWER:
for anyone that is stuck on the same problem, this is how I ended up doing it: first I created a job that just creates and pushed a new branch:
Create-new-Branch:
runs-on: [ self-hosted ]
outputs:
branch_name: ${{ steps.create-branch.outputs.BRANCH_NAME}}
steps:
- name: Checkout master
uses: actions/checkout@v2
with:
repository: org/repo
token: ${{secrets.GIT_TOKEN}}
ref: master
- name: create and push branch
id: create-branch
run: |
export TEST="new-branch-name-`date '+%F'`"
git checkout -b $TEST origin/master
git push -u origin $TEST
echo "::set-output name=BRANCH_NAME::$TEST"
then in the next job when I wanted to use it I use the job output from the job above as the repo name
Job-Name:
needs: Create-new-Branch
runs-on: [self-hosted]
steps:
- name: Checkout to branch
uses: actions/checkout@v2
with:
repository: org/repo
token: ${{secrets.GIT_TOKEN}}
ref: ${{needs.Create-new-Branch.outputs.branch_name}} # the new branch name