Skip to content

Commit 5940b2e

Browse files
Update checkout
1 parent 854ba41 commit 5940b2e

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

.github/workflows/build-and-run-tests-from-branch.yml

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
commit_sha:
77
required: false
88
type: string
9-
description: "Commit SHA (optional)"
9+
description: "Commit SHA (optional -- otherwise the last commit from the branch will be taken)"
1010

1111
workflow_call:
1212
inputs:
@@ -30,22 +30,15 @@ jobs:
3030
steps:
3131
- name: Print environment variables
3232
run: printenv
33-
34-
- name: Set up commit SHA
35-
# "You can make an environment variable available to any subsequent steps in a workflow job by
36-
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
33+
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
37+
- name: Check out ${{ github.event.inputs.commit_sha }} commit
38+
if: github.event.inputs.commit_sha != ''
3739
run: |
38-
if [ ${{ github.event.inputs.commit_sha }} != "" ]
39-
then
40-
echo COMMIT_SHA="${{ github.event.inputs.commit_sha }}" >> $GITHUB_ENV
41-
else
42-
echo COMMIT_SHA="${{ github.sha }}" >> $GITHUB_ENV
43-
fi
44-
# read more about contexts: https://docs.github.com/en/actions/learn-github-actions/contexts#about-contexts
45-
- uses: actions/checkout@v3
46-
with:
47-
ref: ${{ env.COMMIT_SHA }}
48-
40+
git fetch
41+
git checkout ${{ github.event.inputs.commit_sha }}
4942
- id: set-matrix
5043
name: Read and print config from framework-tests-matrix.json
5144
run: |
@@ -69,21 +62,14 @@ jobs:
6962
- name: Print environment variables
7063
run: printenv
7164

72-
- name: Set up commit SHA
73-
# "You can make an environment variable available to any subsequent steps in a workflow job by
74-
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
75-
run: |
76-
if [ ${{ github.event.inputs.commit_sha }} != "" ]
77-
then
78-
echo COMMIT_SHA="${{ github.event.inputs.commit_sha }}" >> $GITHUB_ENV
79-
else
80-
echo COMMIT_SHA="${{ github.sha }}" >> $GITHUB_ENV
81-
fi
82-
# read more about contexts: https://docs.github.com/en/actions/learn-github-actions/contexts#about-contexts
83-
- uses: actions/checkout@v3
84-
with:
85-
ref: ${{ env.COMMIT_SHA }}
65+
- name: Checkout repository
66+
uses: actions/checkout@v3
8667

68+
- name: Check out ${{ github.event.inputs.commit_sha }} commit
69+
if: github.event.inputs.commit_sha != ''
70+
run: |
71+
git fetch
72+
git checkout ${{ github.event.inputs.commit_sha }}
8773
- name: Run monitoring
8874
run: |
8975
echo Find your Prometheus metrics using label {instance=\"${GITHUB_RUN_ID}-${HOSTNAME}\"}
@@ -130,16 +116,14 @@ jobs:
130116
- name: Print environment variables
131117
run: printenv
132118

133-
- name: Set up commit SHA
134-
# "You can make an environment variable available to any subsequent steps in a workflow job by
135-
# defining or updating the environment variable and writing this to the GITHUB_ENV environment file."
119+
- name: Checkout repository
120+
uses: actions/checkout@v3
121+
122+
- name: Check out ${{ github.event.inputs.commit_sha }} commit
123+
if: github.event.inputs.commit_sha != ''
136124
run: |
137-
if [ ${{ github.event.inputs.commit_sha }} != "" ]
138-
then
139-
echo COMMIT_SHA="${{ github.event.inputs.commit_sha }}" >> $GITHUB_ENV
140-
else
141-
echo COMMIT_SHA="${{ github.sha }}" >> $GITHUB_ENV
142-
fi
125+
git fetch
126+
git checkout ${{ github.event.inputs.commit_sha }}
143127
- uses: actions/checkout@v3
144128
with:
145129
ref: ${{ env.COMMIT_SHA }}

0 commit comments

Comments
 (0)