Skip to content

Commit 50f6b29

Browse files
davidmfinolclaude
andauthored
Write temporary build files to a tmpdir instead of the workspace (#91)
The action created BuildOutput/, manifest.vdf, and depot*.vdf in the workspace root, so a second `uses:` of the action in the same job failed with `mkdir: cannot create directory 'BuildOutput': File exists`. Because the action runs in a container as root, those leftovers were also root-owned and could break a later checkout on self-hosted runners. Everything temporary now goes into a per-run mktemp dir under $RUNNER_TEMP, and an EXIT trap chowns it back to the workspace owner. Adds a regression test to the workflow that runs the action twice and asserts the workspace is left clean and writable. Fixes #79 Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 42f7685 commit 50f6b29

2 files changed

Lines changed: 38 additions & 13 deletions

File tree

.github/workflows/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ jobs:
4343
depot1Path: StandaloneWindows64
4444
depot2Path: StandaloneLinux64
4545
releaseBranch: prerelease
46+
47+
# Regression test for #79: the action must be runnable more than once in the same job,
48+
# and must not leave root-owned files behind in the workspace.
49+
- uses: ./
50+
with:
51+
username: ${{ secrets.STEAM_USERNAME }}
52+
configVdf: ${{ secrets.STEAM_CONFIG_VDF }}
53+
appId: ${{ secrets.TEST_APP_ID }}
54+
buildDescription: v0.0.1
55+
rootPath: build
56+
depot1Path: StandaloneWindows64
57+
depot2Path: StandaloneLinux64
58+
releaseBranch: prerelease
59+
- name: Workspace is clean and writable
60+
run: |
61+
test -z "$(find . -path ./.git -prune -o ! -writable -print)"
62+
test ! -e BuildOutput

steam_deploy.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ steamdir=${STEAM_HOME:-$HOME/Steam}
66
# this is relative to the action
77
contentroot=$(pwd)/$rootPath
88

9-
# these are temporary file we create, so in a tmpdir
10-
mkdir BuildOutput
11-
manifest_path=$(pwd)/manifest.vdf
9+
# these are temporary files we create, so in a tmpdir outside of the workspace: this way the
10+
# action can run more than once per job, and it leaves nothing root-owned behind for the next
11+
# checkout to trip over
12+
workdir=$(mktemp -d "${RUNNER_TEMP:-/tmp}/steam-deploy.XXXXXX")
13+
buildoutput=$workdir/BuildOutput
14+
manifest_path=$workdir/manifest.vdf
15+
mkdir -p "$buildoutput"
16+
17+
# hand everything we created back to whoever owns the workspace (the runner user), so that
18+
# self-hosted runners can clean it up without sudo
19+
trap 'chown -R --reference="${GITHUB_WORKSPACE:-$(pwd)}" "$workdir" 2>/dev/null || true' EXIT
1220

1321
echo ""
1422
echo "#################################"
@@ -50,9 +58,9 @@ until [ $i -gt 9 ]; do
5058
echo ""
5159
echo "Adding depot${currentDepot}.vdf ..."
5260
echo ""
53-
export DEPOTS="$DEPOTS \"$currentDepot\" \"depot${currentDepot}.vdf\"\n "
61+
export DEPOTS="$DEPOTS \"$currentDepot\" \"$workdir/depot${currentDepot}.vdf\"\n "
5462

55-
cat << EOF > "depot${currentDepot}.vdf"
63+
cat << EOF > "$workdir/depot${currentDepot}.vdf"
5664
"DepotBuildConfig"
5765
{
5866
"DepotID" "$currentDepot"
@@ -69,7 +77,7 @@ until [ $i -gt 9 ]; do
6977
}
7078
EOF
7179

72-
cat depot${currentDepot}.vdf
80+
cat "$workdir/depot${currentDepot}.vdf"
7381
echo ""
7482
fi;
7583

@@ -82,12 +90,12 @@ echo "# Generating App Manifest #"
8290
echo "#################################"
8391
echo ""
8492

85-
cat << EOF > "manifest.vdf"
93+
cat << EOF > "$manifest_path"
8694
"appbuild"
8795
{
8896
"appid" "$appId"
8997
"desc" "$buildDescription"
90-
"buildoutput" "BuildOutput"
98+
"buildoutput" "$buildoutput"
9199
"contentroot" "$contentroot"
92100
"setlive" "$releaseBranch"
93101
@@ -97,7 +105,7 @@ cat << EOF > "manifest.vdf"
97105
}
98106
EOF
99107

100-
cat manifest.vdf
108+
cat "$manifest_path"
101109
echo ""
102110

103111
if [ -n "$steam_totp" ]; then
@@ -164,7 +172,7 @@ echo "# Uploading build #"
164172
echo "#################################"
165173
echo ""
166174

167-
steamcmd +login "$steam_username" +run_app_build "$manifest_path" +quit | tee build_output.log || (
175+
steamcmd +login "$steam_username" +run_app_build "$manifest_path" +quit | tee "$workdir/build_output.log" || (
168176
echo ""
169177
echo "#################################"
170178
echo "# Errors #"
@@ -201,9 +209,9 @@ steamcmd +login "$steam_username" +run_app_build "$manifest_path" +quit | tee bu
201209
echo "# Output #"
202210
echo "#################################"
203211
echo ""
204-
ls -Ralph BuildOutput
212+
ls -Ralph "$buildoutput"
205213

206-
for f in BuildOutput/*.log; do
214+
for f in "$buildoutput"/*.log; do
207215
echo "######## $f"
208216
cat "$f"
209217
echo
@@ -212,7 +220,7 @@ steamcmd +login "$steam_username" +run_app_build "$manifest_path" +quit | tee bu
212220
exit 1
213221
)
214222

215-
buildId=$(grep -oP '\(BuildID \K\d+(?=\))' build_output.log || echo "")
223+
buildId=$(grep -oP '\(BuildID \K\d+(?=\))' "$workdir/build_output.log" || echo "")
216224

217225
echo "manifest=${manifest_path}" >> $GITHUB_OUTPUT
218226
echo "buildId=${buildId}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)