Skip to content

Commit b84162d

Browse files
committed
Use a $TARGET env var (and some other vars)
We are already using a `$CARGO` environment variable, which is mainly for convenient expansion by the shell, but `cargo` (and commands like `cross` with the same interface) pass it on to build scripts, which may use it (and if or how they do may in principle vary by feature or target). But the sitation with `$TARGET` is analogous--it would also make commands more readable, and it is also passed down to scripts by `cargo`. So this adds `$TARGET`. Doing this serves another purpose, which is to make it easier to reason about the semantics of the commands the shell is running. Using `${{ }}` interpolation should not be a security risk here, since all values are trusted. But injecting characters such as `'` could still happen by accident. Often it may not be justified, outside of reusable workflows or those running on events with elevated security risks, to route them through environment variables to ensure their contents are not interpreted specially by the shell. However, with the addition of `$TARGET`, it seems that most of that has already been done, such that clarity is overall improved rather than worsened by going the rest of the way. So this does that too, adding other environment variables in the narrowest scope that is broad enough to avoid duplication. Now all `${{ }}` interpolations are outside of script code. Note that these changes only apply to the release workflow and may not necessarily be justified in other workflows.
1 parent 15f67d2 commit b84162d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ jobs:
3535

3636
- name: Get the release version from the tag
3737
if: env.VERSION == ''
38-
run: echo 'VERSION=${{ github.ref_name }}' >> "$GITHUB_ENV"
38+
run: echo "VERSION=$VERSION" >> "$GITHUB_ENV"
39+
env:
40+
VERSION: ${{ github.ref_name }}
41+
3942

4043
- name: Validate version against Cargo.toml
4144
run: |
@@ -78,7 +81,9 @@ jobs:
7881
run: mkdir artifacts
7982

8083
- name: Save release upload URL to artifact
81-
run: echo '${{ steps.release.outputs.upload_url }}' > artifacts/release-upload-url
84+
run: echo "$URL" > artifacts/release-upload-url
85+
env:
86+
URL: ${{ steps.release.outputs.upload_url }}
8287

8388
- name: Save version number to artifact
8489
run: echo "$VERSION" > artifacts/release-version
@@ -156,8 +161,10 @@ jobs:
156161

157162
env:
158163
CARGO: cargo # On Linux, this will be changed to `cross` in a later step.
164+
TARGET: ${{ matrix.target }}
159165
TARGET_FLAGS: --target=${{ matrix.target }}
160166
TARGET_DIR: target/${{ matrix.target }}
167+
FEATURE: ${{ matrix.feature }}
161168
RUST_BACKTRACE: '1' # Emit backtraces on panics.
162169
CARGO_TERM_COLOR: always
163170
CLICOLOR: '1'
@@ -204,7 +211,7 @@ jobs:
204211
205212
- name: Build release binary
206213
run: |
207-
"$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features ${{ matrix.feature }}
214+
"$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features "$FEATURE"
208215
209216
- name: Strip release binary (x86-64 Linux, and all macOS)
210217
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.os == 'macos-latest'
@@ -222,12 +229,12 @@ jobs:
222229
223230
- name: Build archive
224231
run: |
225-
staging='gitoxide-${{ matrix.feature }}-${{ env.VERSION }}-${{ matrix.target }}'
232+
staging="gitoxide-$FEATURE-$VERSION-$TARGET"
226233
mkdir -p -- "$staging"
227234
228235
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
229236
230-
if [ '${{ matrix.os }}' = 'windows-latest' ]; then
237+
if [ "$OS" = 'windows-latest' ]; then
231238
file -- "$TARGET_DIR"/release/{ein,gix}.exe
232239
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$staging/"
233240
7z a "$staging.zip" "$staging"
@@ -238,6 +245,8 @@ jobs:
238245
tar czf "$staging.tar.gz" "$staging"
239246
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
240247
fi
248+
env:
249+
OS: ${{ matrix.os }}
241250

242251
- name: Upload release archive
243252
uses: actions/upload-release-asset@v1.0.2

0 commit comments

Comments
 (0)