Skip to content

Commit 286e388

Browse files
committed
Minor changes from ripgrep workflow + simplify + clarify quoting
The release.yml workflow adapts from the corresponding workflow in the ripgrep project, but drawing from multiple revisions of it and also including substantial gitoxide-specific changes. ripgrep's licensing permits this even with respect to any material that is original to that project, since one of the licenses ripgrep is offered under is the Unlicense, which allows arbitrary use and adaptation without requiring even attribution. This commit makes these changes related to that relationship: - Note the relationship, linking to the ripgrep workflow. - Bring in the new ripgrep comment explaining the workflow, which, as there, is shorter and just above the `create-release` job, not at the top. This makes a slight change, so as not to refer to a version tag scheme that differs and that we do not enforce. - Renames both *_VERSION variables to just `VERSION`, as they now are in the ripgrep workflow. These variables have conceptually the same meaning, always take the same value, and do not clash because each job in the workflow has exactly one of them. - Bring in the simplification of using `github.ref_name` to get the tag name to use as the version string. There remain other significant changes to that workflow that can and should be applied or adapted into this one, but which are not included in this commit. This commit also makes some other changes for simplification and stylistic clarity: - Change the trigger tag pattern to the glob-like `v*`, which seems to be what the GHA docs say will make it work (though this may have been tried unsuccessfully before). - Don't specify the fetch depth, because `actions-checkout` defaults to a depth of 1 already. - Remove ad-hoc echos that inadvertently performed empty parameter expansion because they used a variable that had just been written in `$GITHUB_ENV`. Writes to `$GITHUB_ENV` only affect the environment of subsequent steps, not of subsequent commands run as part of the same script step. These could have been shown in a different way, or by expanding them straightforwardly but in a subsequent script step (like the existing "Show command used for Cargo" step), but the removed echos did not seem very important and the information they were showing is mostly available by detailed log inspection. - Simplify some commands whose complexity was just to support those ineffective echos. - Use the bash `$(< path)` syntax where applicable. This is a more efficient alternative to `$(cat path)`. It's a bash-ism, but bash is now being used to run all steps on all platforms. - Where both (a) quoting was clearly unnecessary because of the way YAML parses strings and (b) quoting was being used in some places and not analogous other places, so the style was inconsistent, this removes the quoting. (This does not remove quoting in other situations, not even when one but not the other condition holds.) - When quoting inline, this always uses the strongest form, of those that are readily available and easily readable. This applies both to the formation of YAML strings, which now prefer single quotes to double quotes, and to quotation marks that appear inside YAML strings that are executed by the shell. Now double quotes are only used when both (a) quoting for a shell rather than the YAML parser and (b) deliberately causing the shell to perform its own `$...` expansions. This is because double-quoted `${{ }}` interpolation can falsely appear to be a shell expansion, when really all `${{ }}` interpolation is done after YAML parsing but before the shell receives the code that it runs in a script step. - Double-quote `$GITHUB_ENV` (rather than not quoting it), so all shell parameter expansion is double quoted except where expansion that quoting would suppress is wanted (currently, nowhere). - When shell quoting is optional because the item being `${{ }}` interpolated is guaranteed to be parsed by the shell as a single argument, and where we *rely* on that effect, this quotes the argument. This is done more for consistency, in view of how it was already mostly being done, than robustness. It is still not truly robust because, although we never set such values, a `'` character, if present in the output of interpolation, would be (like all output of `${{ }}` interpolation) present literally in the script that the shell receives, and the shell would interpret it as a closing quotation mark. - Adjust spacing for consistency with the existing style.
1 parent 418d71f commit 286e388

File tree

1 file changed

+37
-49
lines changed

1 file changed

+37
-49
lines changed

.github/workflows/release.yml

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
# The way this works is a little weird. But basically, the create-release job
2-
# runs purely to initialize the GitHub release itself. Once done, the upload
3-
# URL of the release is saved as an artifact.
4-
#
5-
# The build-release job runs only once create-release is finished. It gets
6-
# the release upload URL by downloading the corresponding artifact (which was
7-
# uploaded by create-release). It then builds the release executables for each
8-
# supported platform and attaches them as release assets to the previously
9-
# created release.
10-
#
11-
# The key here is that we create the release only once.
1+
# This is largely adapted from past and recent versions of the ripgrep release workflow.
2+
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml
123

134
name: release
145

@@ -19,7 +10,7 @@ on:
1910
# branches:
2011
# - fix-releases
2112
tags:
22-
- "v.*"
13+
- 'v*'
2314

2415
env:
2516
RUST_BACKTRACE: 1
@@ -31,38 +22,39 @@ defaults:
3122
shell: bash
3223

3324
jobs:
25+
# The create-release job runs purely to initialize the GitHub release itself,
26+
# and names the release after the version tag that was pushed. It's separate
27+
# from building the release so that we only create the release once.
3428
create-release:
3529
name: create-release
3630
runs-on: ubuntu-latest
3731
# env:
3832
# # Set to force version number, e.g., when no tag exists.
39-
# ARTIFACT_VERSION: TEST-0.0.0
33+
# VERSION: TEST-0.0.0
4034
steps:
4135
- name: Create artifacts directory
4236
run: mkdir artifacts
4337

4438
- name: Get the release version from the tag
45-
if: env.ARTIFACT_VERSION == ''
46-
run: |
47-
echo "ARTIFACT_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
48-
echo "version is: ${{ env.ARTIFACT_VERSION }}"
39+
if: env.VERSION == ''
40+
run: echo 'VERSION=${{ github.ref_name }}' >> "$GITHUB_ENV"
4941

5042
- name: Create GitHub release
5143
id: release
5244
uses: ncipollo/release-action@v1
5345
with:
54-
tag: ${{ env.ARTIFACT_VERSION }}
55-
name: ${{ env.ARTIFACT_VERSION }}
46+
tag: ${{ env.VERSION }}
47+
name: ${{ env.VERSION }}
5648
allowUpdates: true
5749
omitBody: true
5850
omitPrereleaseDuringUpdate: true
5951
token: ${{ secrets.GITHUB_TOKEN }}
6052

6153
- name: Save release upload URL to artifact
62-
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
54+
run: echo '${{ steps.release.outputs.upload_url }}' > artifacts/release-upload-url
6355

6456
- name: Save version number to artifact
65-
run: echo "${{ env.ARTIFACT_VERSION }}" > artifacts/release-version
57+
run: echo '${{ env.VERSION }}' > artifacts/release-version
6658

6759
- name: Upload artifacts
6860
uses: actions/upload-artifact@v4
@@ -72,21 +64,21 @@ jobs:
7264

7365
build-release:
7466
name: build-release
75-
needs: [ "create-release" ]
67+
needs: [ create-release ]
7668
env:
7769
# For some builds, we use cross to test on 32-bit and big-endian
7870
# systems.
7971
CARGO: cargo
8072
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
81-
TARGET_FLAGS: ""
73+
TARGET_FLAGS: ''
8274
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
8375
TARGET_DIR: ./target
8476
# Emit backtraces on panics.
8577
RUST_BACKTRACE: 1
8678
strategy:
8779
matrix:
8880
build: [ linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc ]
89-
feature: [ "small", "lean", "max", "max-pure" ]
81+
feature: [ small, lean, max, max-pure ]
9082
include:
9183
- build: linux
9284
os: ubuntu-latest
@@ -130,11 +122,10 @@ jobs:
130122
feature: max
131123

132124
runs-on: ${{ matrix.os }}
125+
133126
steps:
134127
- name: Checkout repository
135128
uses: actions/checkout@v4
136-
with:
137-
fetch-depth: 1
138129

139130
- name: Install packages (Ubuntu)
140131
# Because openssl doesn't work on musl by default, we resort to max-pure. And that won't need any dependency, so we can skip this.continue-on-error
@@ -152,15 +143,15 @@ jobs:
152143
- name: Use Cross
153144
run: |
154145
cargo install cross
155-
echo "CARGO=cross" >> $GITHUB_ENV
156-
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
157-
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
146+
echo 'CARGO=cross' >> "$GITHUB_ENV"
147+
echo 'TARGET_FLAGS=--target ${{ matrix.target }}' >> "$GITHUB_ENV"
148+
echo 'TARGET_DIR=./target/${{ matrix.target }}' >> "$GITHUB_ENV"
158149
159150
- name: Show command used for Cargo
160151
run: |
161-
echo "cargo command is: ${{ env.CARGO }}"
162-
echo "target flag is: ${{ env.TARGET_FLAGS }}"
163-
echo "target dir is: ${{ env.TARGET_DIR }}"
152+
echo 'cargo command is: ${{ env.CARGO }}'
153+
echo 'target flag is: ${{ env.TARGET_FLAGS }}'
154+
echo 'target dir is: ${{ env.TARGET_DIR }}'
164155
165156
- name: Get release download URL
166157
uses: actions/download-artifact@v4
@@ -170,19 +161,15 @@ jobs:
170161

171162
- name: Set release upload URL and release version
172163
run: |
173-
release_upload_url="$(cat artifacts/release-upload-url)"
174-
echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
175-
echo "release upload url: $RELEASE_UPLOAD_URL"
176-
release_version="$(cat artifacts/release-version)"
177-
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
178-
echo "release version: $RELEASE_VERSION"
164+
echo "UPLOAD_URL=$(< artifacts/release-upload-url)" >> "$GITHUB_ENV"
165+
echo "VERSION=$(< artifacts/release-version)" >> "$GITHUB_ENV"
179166
180167
- name: Build release binary
181168
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} --no-default-features --features ${{ matrix.feature }}
182169

183170
- name: Strip release binary (linux and macos)
184171
if: matrix.build == 'linux' || matrix.build == 'macos'
185-
run: strip target/${{ matrix.target }}/release/ein target/${{ matrix.target }}/release/gix
172+
run: strip 'target/${{ matrix.target }}/release/ein' 'target/${{ matrix.target }}/release/gix'
186173

187174
- name: Strip release binary (arm)
188175
if: matrix.build == 'linux-arm'
@@ -193,31 +180,32 @@ jobs:
193180
arm-linux-gnueabihf-strip \
194181
/target/arm-unknown-linux-gnueabihf/release/ein \
195182
/target/arm-unknown-linux-gnueabihf/release/gix
183+
196184
- name: Build archive
197185
run: |
198-
staging="gitoxide-${{ matrix.feature }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
199-
mkdir -p "$staging"
186+
staging='gitoxide-${{ matrix.feature }}-${{ env.VERSION }}-${{ matrix.target }}'
187+
mkdir -p -- "$staging"
200188
201189
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
202190
203-
if [ "${{ matrix.os }}" = "windows-latest" ]; then
204-
file target/${{ matrix.target }}/release/ein.exe target/${{ matrix.target }}/release/gix.exe
205-
cp target/${{ matrix.target }}/release/ein.exe target/${{ matrix.target }}/release/gix.exe "$staging/"
191+
if [ '${{ matrix.os }}' = 'windows-latest' ]; then
192+
file 'target/${{ matrix.target }}/release/ein.exe' 'target/${{ matrix.target }}/release/gix.exe'
193+
cp 'target/${{ matrix.target }}/release/ein.exe' 'target/${{ matrix.target }}/release/gix.exe' "$staging/"
206194
7z a "$staging.zip" "$staging"
207-
echo "ASSET=$staging.zip" >> $GITHUB_ENV
195+
echo "ASSET=$staging.zip" >> "$GITHUB_ENV"
208196
else
209-
file target/${{ matrix.target }}/release/ein target/${{ matrix.target }}/release/gix
210-
cp target/${{ matrix.target }}/release/ein target/${{ matrix.target }}/release/gix "$staging/"
197+
file 'target/${{ matrix.target }}/release/ein' 'target/${{ matrix.target }}/release/gix'
198+
cp 'target/${{ matrix.target }}/release/ein' 'target/${{ matrix.target }}/release/gix' "$staging/"
211199
tar czf "$staging.tar.gz" "$staging"
212-
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
200+
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
213201
fi
214202
215203
- name: Upload release archive
216204
uses: actions/upload-release-asset@v1.0.2
217205
env:
218206
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
219207
with:
220-
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
208+
upload_url: ${{ env.UPLOAD_URL }}
221209
asset_path: ${{ env.ASSET }}
222210
asset_name: ${{ env.ASSET }}
223211
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)