Skip to content

Commit 49f34f4

Browse files
committed
.github/workflows: simplify tag checkout steps
In commit df6e49c of PR git-lfs#5243 we added a step to all of the jobs in our CI and release GitHub Actions workflows to work around the problem described in actions/checkout#290 and actions/checkout#882. This step, which only executes if the job is running due to the push of a new tag, performs a "git fetch" command of the tag's reference to ensure that the local copy is identical to the remote one and has not been converted from an annotated tag into a lightweight one. Starting with v2 of the actions/checkout action, annotated tags are by default replaced with lightweight ones, which then causes any subsequent "git describe" commands to return an incorrect value. Since we depend on the output of "git describe" in several places in our workflows to generate the appropriate version name for our release artifacts, we need to ensure we have the full annotated tag for the current reference rather than a lightweight one. Recently, in commit 9c3fab1 of PR git-lfs#5930, we strengthened the security of our GitHub Action workflows by setting the "persist-credentials" option of the actions/checkout action to "false", so that any cached Git credentials are removed at the end of that step. While this causes no problems when our CI workflow runs after a branch is pushed, as is the case for new PRs, when we push a new tag the "git fetch" step now fails as it depends on the cached Git credentials from the actions/checkout step. We could use the GITHUB_TOKEN Action secret to temporarily set an appropriate HTTP Authorization header to make the "git fetch" command succeed. However, a more straightforward solution exists whereby we specify explicitly the reference we want to check out using the "ref" option of the actions/checkout action. This causes the action to fetch the reference such that if the reference is an annotated tag, it remains one and is not converted into a lightweight one. For reference, see: actions/checkout#882 (comment) actions/runner-images#1717 (comment) h/t classabbyamp and xenoterracide for documenting this workaround
1 parent a8bf080 commit 49f34f4

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
with:
1717
fetch-depth: 0
1818
persist-credentials: false
19-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
20-
if: ${{ github.ref_type == 'tag' }}
21-
# We update the current tag as the checkout step turns annotated tags
22-
# into lightweight ones by accident, breaking "git describe".
23-
# See https://github.com/actions/checkout/issues/882 for details.
19+
ref: ${{ github.ref }}
20+
# We specify the current ref because otherwise the checkout turns
21+
# annotated tags into lightweight ones, breaking "git describe".
22+
# See https://github.com/actions/checkout/issues/290 and
23+
# https://github.com/actions/checkout/issues/882 for details.
2424
- uses: ruby/setup-ruby@v1
2525
- run: gem install asciidoctor
2626
- uses: actions/setup-go@v5
@@ -53,8 +53,7 @@ jobs:
5353
with:
5454
fetch-depth: 0
5555
persist-credentials: false
56-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
57-
if: ${{ github.ref_type == 'tag' }}
56+
ref: ${{ github.ref }}
5857
- uses: actions/setup-go@v5
5958
with:
6059
go-version: ${{ matrix.go }}
@@ -67,9 +66,7 @@ jobs:
6766
with:
6867
fetch-depth: 0
6968
persist-credentials: false
70-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
71-
if: ${{ github.ref_type == 'tag' }}
72-
shell: bash
69+
ref: ${{ github.ref }}
7370
- uses: ruby/setup-ruby@v1
7471
- run: gem install asciidoctor
7572
- run: Rename-Item -Path C:\msys64 -NewName msys64-tmp -Force
@@ -136,11 +133,10 @@ jobs:
136133
with:
137134
fetch-depth: 0
138135
persist-credentials: false
136+
ref: ${{ github.ref }}
139137
- uses: actions/setup-go@v5
140138
with:
141139
go-version: '1.23.x'
142-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
143-
if: ${{ github.ref_type == 'tag' }}
144140
- run: git clone -b master https://github.com/git/git.git "$HOME/git"
145141
- run: |
146142
echo "GIT_INSTALL_DIR=$HOME/git" >> "$GITHUB_ENV"
@@ -161,11 +157,10 @@ jobs:
161157
with:
162158
fetch-depth: 0
163159
persist-credentials: false
160+
ref: ${{ github.ref }}
164161
- uses: actions/setup-go@v5
165162
with:
166163
go-version: '1.23.x'
167-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
168-
if: ${{ github.ref_type == 'tag' }}
169164
- run: git clone -b v2.0.0 https://github.com/git/git.git "$HOME/git"
170165
- run: |
171166
echo "GIT_INSTALL_DIR=$HOME/git" >> "$GITHUB_ENV"
@@ -183,8 +178,7 @@ jobs:
183178
with:
184179
fetch-depth: 0
185180
persist-credentials: false
186-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
187-
if: ${{ github.ref_type == 'tag' }}
181+
ref: ${{ github.ref }}
188182
- uses: ruby/setup-ruby@v1
189183
- run: git clone https://github.com/git-lfs/build-dockers.git "$HOME/build-dockers"
190184
- run: (cd "$HOME/build-dockers" && ./build_dockers.bsh)
@@ -201,8 +195,7 @@ jobs:
201195
with:
202196
fetch-depth: 0
203197
persist-credentials: false
204-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
205-
if: ${{ github.ref_type == 'tag' }}
198+
ref: ${{ github.ref }}
206199
- uses: ruby/setup-ruby@v1
207200
- run: |
208201
echo '{"experimental": true}' | sudo tee /etc/docker/daemon.json

.github/workflows/release.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
with:
1818
fetch-depth: 0
1919
persist-credentials: false
20-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
21-
shell: bash
22-
# We update the current tag as the checkout step turns annotated tags
23-
# into lightweight ones by accident, breaking "git describe".
24-
# See https://github.com/actions/checkout/issues/882 for details.
20+
ref: ${{ github.ref }}
21+
# We specify the current ref because otherwise the checkout turns
22+
# annotated tags into lightweight ones, breaking "git describe".
23+
# See https://github.com/actions/checkout/issues/290 and
24+
# https://github.com/actions/checkout/issues/882 for details.
2525
- uses: ruby/setup-ruby@v1
2626
- run: gem install asciidoctor
2727
- run: Rename-Item -Path C:\msys64 -NewName msys64-tmp -Force
@@ -110,7 +110,7 @@ jobs:
110110
with:
111111
fetch-depth: 0
112112
persist-credentials: false
113-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
113+
ref: ${{ github.ref }}
114114
- uses: ruby/setup-ruby@v1
115115
- run: gem install asciidoctor
116116
- uses: actions/setup-go@v5
@@ -149,7 +149,7 @@ jobs:
149149
with:
150150
fetch-depth: 0
151151
persist-credentials: false
152-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
152+
ref: ${{ github.ref }}
153153
- uses: ruby/setup-ruby@v1
154154
- run: gem install asciidoctor
155155
- uses: actions/setup-go@v5
@@ -181,7 +181,7 @@ jobs:
181181
with:
182182
fetch-depth: 0
183183
persist-credentials: false
184-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
184+
ref: ${{ github.ref }}
185185
- uses: ruby/setup-ruby@v1
186186
- run: gem install packagecloud-ruby
187187
- run: git clone https://github.com/git-lfs/build-dockers.git "$HOME/build-dockers"
@@ -203,7 +203,7 @@ jobs:
203203
with:
204204
fetch-depth: 0
205205
persist-credentials: false
206-
- run: git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
206+
ref: ${{ github.ref }}
207207
- uses: ruby/setup-ruby@v1
208208
- run: gem install packagecloud-ruby
209209
- run: |

0 commit comments

Comments
 (0)