Checkout a commit created during the same workflow #25985
-
I have a workflow that runs a script to update a template and pushes that template back to Github (Job 1), then tries to check it out and use it with another action (Job 2). Because actions/checkout@v2 only uses the reference that calls it, this means that in the second job, I end up checking out an older version of the template (because the updated template technically occurred in the future).
I’m going to experiment, but wanted to post 1) in case someone else has the same issue and 2) in case I don’t figure it out, since I’m not super comfortable with git. Is this what checking out the HEAD is for? I really only need one commit, the issue is that the commit occurs after the workflow starts. I also understand that Github doesn’t want to be able to trigger workflows from Github Actions to prevent recursion, but I’m not trying to do that. The user triggers the workflow, but checkout needs to be able to access a later commit than the one that triggered the workflow. No future knowledge is required because the current commit at the time of the second job is the one I want to work on. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
This is the result of adding the HEAD checkout:
So checkout initially grabbed the “wrong” ref (“Attempting to correct”), then the HEAD checkout pointed to the correct subsequent ref (“Template Updated”). Unfortunately I’m not sure if it did what I wanted because the template didn’t have a functional change. But it looks like it worked? Is this the answer? |
Beta Was this translation helpful? Give feedback.
-
If there are no other team members or workflow which push new changes at the time gap after job1 pushed the changes and before job2 checkout operation, you could use checkout HEAD to get the commit pushed in job1. |
Beta Was this translation helpful? Give feedback.
-
yanjingzhu:
This is essentially the basis of my question. I’m reassured to hear that checkout HEAD is a solution. However, I’m still trying to reach the best solution. As you said, that would preferably be to checkout the correct reference (the one pushed by job 1). My next step would be to grab that reference somehow and then store it, then somehow reference it when using actions/checkout, but I don’t see a way to checkout a specific reference. Two ways I’ll probably try next:
As always, I’m open to more elegant, less hacky, solutions |
Beta Was this translation helpful? Give feedback.
-
You could store the SHA ref in a file, upload the file as an artifact, and grab it in the next job. According to the documentation you can check out a specific commit using the |
Beta Was this translation helpful? Give feedback.
-
The commit id could be got using git command:
You could set an output variable in job “prepare” with the commit id. Then you could get its value through job needs output.
|
Beta Was this translation helpful? Give feedback.
-
I marked the post with a complete example as the solution, but the answer to my question required both halves:
Thank you both for the help. I also found the job needs output page, but was trying to use it with Edit: For completeness, I forgot to mention that I used |
Beta Was this translation helpful? Give feedback.
-
Thanks for the nod in the issue/commit comments! 🙂 |
Beta Was this translation helpful? Give feedback.
-
Another solution to ref is to use |
Beta Was this translation helpful? Give feedback.
The commit id could be got using git command:
You could set an output variable in job “prepare” with the commit id. Then you could get its value through job needs output.
As what @airtower-luna suggested, In job “trystable” , you could specify the commit id as ref input value in checkout step .
Please see my example :