Skip to content

Commit 064877f

Browse files
author
Martin Taillefer
committed
Ditch PowerShell
1 parent 514b550 commit 064877f

File tree

1 file changed

+44
-70
lines changed

1 file changed

+44
-70
lines changed

.github/actions/setup/action.yml

Lines changed: 44 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -34,80 +34,54 @@ runs:
3434
using: composite
3535
steps:
3636
- name: Loading Repo Constants
37-
shell: pwsh
37+
shell: bash
3838
run: |
39-
$constantsPath = Join-Path '${{ github.workspace }}' 'constants.toml'
39+
echo "CARGO_TERM_COLOR=always" >> "$GITHUB_ENV"
4040
41-
if (-not (Test-Path $constantsPath)) {
42-
Write-Error "constants.toml not found at $constantsPath"
43-
exit 1
44-
}
45-
46-
Add-Content -Path $env:GITHUB_ENV -Value "CARGO_TERM_COLOR=always"
47-
48-
Get-Content $constantsPath | ForEach-Object {
49-
if ($_ -match '^([A-Z0-9_]+)\s*=\s*"([^"]+)"') {
50-
$key = $matches[1]
51-
$value = $matches[2]
52-
Add-Content -Path $env:GITHUB_ENV -Value "$key=$value"
53-
}
54-
}
41+
constants_path="${{ github.workspace }}/constants.toml"
42+
while IFS= read -r line; do
43+
if [[ "$line" =~ ^([A-Z0-9_]+)[[:space:]]*=[[:space:]]*\"([^\"]+)\" ]]; then
44+
echo "${BASH_REMATCH[1]}=${BASH_REMATCH[2]}" >> "$GITHUB_ENV"
45+
fi
46+
done < "$constants_path"
5547
5648
- name: Processing Tool Versions
5749
if: inputs.rust-toolchain != '' || inputs.cargo-tools != ''
5850
id: expand
59-
shell: pwsh
51+
shell: bash
6052
run: |
61-
# Expand Rust Toolchain Variables
62-
$toolchain = '${{ inputs.rust-toolchain }}'
63-
if ($toolchain) {
64-
$parts = $toolchain.Split(',') | ForEach-Object {
65-
$part = $_.Trim()
66-
# Check if this part is an environment variable (all caps with underscores)
67-
if ($part -match '^[A-Z0-9_]+$') {
68-
$envValue = [System.Environment]::GetEnvironmentVariable($part)
69-
if ($envValue) {
70-
return $envValue
71-
}
72-
}
73-
return $part
74-
}
75-
$expandedToolchain = $parts -join ','
76-
"toolchain=$expandedToolchain" >> $env:GITHUB_OUTPUT
77-
}
78-
79-
# Expand Cargo Tools Variables
80-
$tools = '${{ inputs.cargo-tools }}'
81-
if ($tools) {
82-
$expandedParts = $tools.Split(',') | ForEach-Object {
83-
$tool = $_.Trim()
84-
85-
# Pattern 1: CARGO_<NAME>_VERSION -> cargo-<name>@<value>
86-
if ($tool -match '^CARGO_([A-Z0-9_]+)_VERSION$') {
87-
$toolName = $matches[1].ToLower().Replace('_', '-')
88-
$envValue = [System.Environment]::GetEnvironmentVariable($tool)
89-
if ($envValue) {
90-
return "cargo-$toolName@$envValue"
91-
}
92-
}
93-
94-
# Pattern 2: tool@ENV_VAR_NAME -> tool@value
95-
if ($tool -match '^(.+)@([A-Z0-9_]+)$') {
96-
$toolName = $matches[1]
97-
$envVarName = $matches[2]
98-
$envValue = [System.Environment]::GetEnvironmentVariable($envVarName)
99-
if ($envValue) {
100-
return "$toolName@$envValue"
101-
}
102-
}
103-
104-
# Pattern 3: literal tool@version, pass through
105-
return $tool
106-
}
107-
108-
$expandedTools = $expandedParts -join ', '
109-
"tools=$expandedTools" >> $env:GITHUB_OUTPUT
110-
}
53+
# Expand Rust Toolchain
54+
if [[ -n '${{ inputs.rust-toolchain }}' ]]; then
55+
expanded=""
56+
IFS=',' read -ra parts <<< '${{ inputs.rust-toolchain }}'
57+
for part in "${parts[@]}"; do
58+
part=${part// /}
59+
if [[ "$part" =~ ^[A-Z0-9_]+$ ]] && [[ -n "${!part}" ]]; then
60+
part="${!part}"
61+
fi
62+
expanded+="${expanded:+,}$part"
63+
done
64+
echo "toolchain=$expanded" >> "$GITHUB_OUTPUT"
65+
fi
66+
67+
# Expand Cargo Tools
68+
if [[ -n '${{ inputs.cargo-tools }}' ]]; then
69+
expanded=""
70+
IFS=',' read -ra parts <<< '${{ inputs.cargo-tools }}'
71+
for tool in "${parts[@]}"; do
72+
tool=${tool// /}
73+
if [[ "$tool" =~ ^CARGO_([A-Z0-9_]+)_VERSION$ ]]; then
74+
name=$(echo "${BASH_REMATCH[1]}" | tr 'A-Z_' 'a-z-')
75+
val="${!tool}"
76+
[[ -n "$val" ]] && tool="cargo-$name@$val"
77+
elif [[ "$tool" =~ ^(.+)@([A-Z0-9_]+)$ ]]; then
78+
val="${!BASH_REMATCH[2]}"
79+
[[ -n "$val" ]] && tool="${BASH_REMATCH[1]}@$val"
80+
fi
81+
expanded+="${expanded:+, }$tool"
82+
done
83+
echo "tools=$expanded" >> "$GITHUB_OUTPUT"
84+
fi
11185
11286
- name: Configure Cargo Dependency Cache
11387
if: inputs.enable-cargo-cache == 'true'
@@ -122,10 +96,10 @@ runs:
12296

12397
- name: Configure Sccache
12498
if: inputs.enable-sccache == 'true'
125-
shell: pwsh
99+
shell: bash
126100
run: |
127-
Add-Content -Path $env:GITHUB_ENV -Value "SCCACHE_GHA_ENABLED=true"
128-
Add-Content -Path $env:GITHUB_ENV -Value "RUSTC_WRAPPER=sccache"
101+
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
102+
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
129103
130104
- name: Start Sccache
131105
if: inputs.enable-sccache == 'true'

0 commit comments

Comments
 (0)