Skip to content

Commit 62a06f9

Browse files
fix(ci): use env variables to ensure escaping
Environment variables are properly escaped in GitHub, thus reducing the risk of code injection. Pull-Request: #3790.
1 parent 4bd4653 commit 62a06f9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
31+
env:
32+
CRATE: ${{ matrix.crate }}
3133
steps:
3234
- name: Install Protoc
3335
run: sudo apt-get install -y protobuf-compiler
@@ -44,39 +46,39 @@ jobs:
4446
save-if: false
4547

4648
- name: Run all tests
47-
run: cargo test --package ${{ matrix.crate }} --all-features
49+
run: cargo test --package "$CRATE" --all-features
4850

4951
- name: Check if we compile without any features activated
50-
run: cargo build --package ${{ matrix.crate }} --no-default-features
52+
run: cargo build --package "$CRATE" --no-default-features
5153

5254
- run: cargo clean
5355

5456
- name: Check if crate has been released
5557
id: check-released
5658
run: |
57-
RESPONSE_CODE=$(curl https://crates.io/api/v1/crates/${{ matrix.crate }} --silent --write-out "%{http_code}" --output /dev/null)
59+
RESPONSE_CODE=$(curl https://crates.io/api/v1/crates/"$CRATE" --silent --write-out "%{http_code}" --output /dev/null)
5860
echo "code=${RESPONSE_CODE}"
5961
echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT
6062
6163
- uses: ./.github/actions/cargo-semver-checks
6264
if: steps.check-released.outputs.code == 200 # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped.
6365
with:
64-
crate: ${{ matrix.crate }}
66+
crate: env.CRATE
6567

6668
- name: Enforce no dependency on meta crate
6769
run: |
6870
cargo metadata --format-version=1 --no-deps | \
69-
jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .dependencies | all(.name != "libp2p")'
71+
jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .dependencies | all(.name != "libp2p")'
7072
7173
- uses: taiki-e/cache-cargo-install-action@7dd0cff2732612ac642812bcec4ada5a279239ed # v1
7274
with:
7375
tool: tomlq
7476

7577
- name: Enforce version in `workspace.dependencies` matches latest version
76-
if: matrix.crate != 'libp2p'
78+
if: env.CRATE != 'libp2p'
7779
run: |
78-
PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .version')
79-
SPECIFIED_VERSION=$(tomlq 'workspace.dependencies.${{ matrix.crate }}.version' --file ./Cargo.toml)
80+
PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version')
81+
SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml)
8082
8183
echo "Package version: $PACKAGE_VERSION";
8284
echo "Specified version: $SPECIFIED_VERSION";

0 commit comments

Comments
 (0)