Skip to content

Commit a50c024

Browse files
committed
feat: Add support for multiple distinct artifacts.
Previously we needed a single glob. Now we can have multiple globs. "source" and "versioned" need to agree for each line.
1 parent f35086c commit a50c024

3 files changed

Lines changed: 63 additions & 27 deletions

File tree

.github/workflows/deploy-artifact.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ jobs:
4141
run: ${{ inputs.run }}
4242
- name: Generate sha256 checksum
4343
id: sha256
44-
run: |
45-
{
46-
echo 'artifacts<<EOF'
47-
for file in ${{ inputs.artifact-source }}; do
48-
sha256sum "$file" >"$file.sha256"
49-
echo "$file"
50-
echo "$file.sha256"
51-
done
52-
echo 'EOF'
53-
} >>"$GITHUB_OUTPUT"
44+
run: ci-tools/tools/artifact_sha256.py ${{ inputs.artifact-source }}
5445

5546
- name: Upload artifact
5647
uses: actions/upload-artifact@v4
@@ -62,7 +53,7 @@ jobs:
6253
id: release-version
6354
if: contains(github.ref, 'refs/tags/v')
6455
run: VERSION="$(echo "$GITHUB_REF" | cut -d / -f 3)";
65-
ci-tools/tools/rename_artifact.py
56+
ci-tools/tools/artifact_rename.py
6657
"${{ inputs.artifact-source }}"
6758
"${{ inputs.artifact-versioned }}"
6859
${{ inputs.artifact-source }}
@@ -76,7 +67,7 @@ jobs:
7667
- name: Rename artifact for nightly upload
7768
id: nightly-version
7869
run: VERSION="nightly";
79-
ci-tools/tools/rename_artifact.py
70+
ci-tools/tools/artifact_rename.py
8071
"${{ inputs.artifact-source }}"
8172
"${{ inputs.artifact-versioned }}"
8273
${{ inputs.artifact-source }}
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,38 @@ def main():
4646
print(f"Usage: {sys.argv[0]} <original> <renamed> [files...]")
4747
sys.exit(1)
4848

49-
original = sys.argv[1]
50-
renamed = sys.argv[2]
49+
original = sys.argv[1].split(" ")
50+
renamed = sys.argv[2].split(" ")
5151
files = sys.argv[3:]
5252

53-
print(f"Copying {original} to {renamed}")
54-
55-
original_re, renamed_re = _glob_to_regex(original, renamed)
53+
if len(original) != len(renamed):
54+
print(f"Error: {len(original)} original and {len(renamed)} renamed")
55+
sys.exit(1)
5656

57-
print(f"Copying {original_re} to {renamed_re}")
5857
print(f"Found {len(files)} files: {files}")
58+
5959
outputs: list[str] = []
60-
for f in files:
61-
new_name = re.sub(original_re, renamed_re, f)
62-
print(f"Copying {f} to {new_name}")
63-
try:
64-
with open(f, "rb") as src, open(new_name, "wb") as dst:
65-
dst.write(src.read())
66-
outputs.append(new_name)
67-
except Exception as e:
68-
print(f"Error Copying {f} to {new_name}: {e}")
60+
for o, r in zip(original, renamed):
61+
print(f"Copying glob {o} to {r}")
62+
63+
o_re, r_re = _glob_to_regex(o, r)
64+
65+
print(f"Copying regex {o_re} to {r_re}")
66+
o_files = [f for f in files if re.match(o_re, f)]
67+
if not o_files:
68+
print(f"Error: no files match {o_re}")
69+
sys.exit(1)
70+
for f in o_files:
71+
if not re.match(o_re, f):
72+
continue
73+
new_name = re.sub(o_re, r_re, f)
74+
print(f"Copying file {f} to {new_name}")
75+
try:
76+
with open(f, "rb") as src, open(new_name, "wb") as dst:
77+
dst.write(src.read())
78+
outputs.append(new_name)
79+
except Exception as e:
80+
print(f"Error Copying {f} to {new_name}: {e}")
6981

7082
print(f"Renamed {len(outputs)} files: {outputs}")
7183
_write_github_outputs(outputs)

tools/artifact_sha256.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
# Copyright © 2025 The TokTok team
4+
import os
5+
import subprocess # nosec
6+
import sys
7+
8+
9+
def main():
10+
if len(sys.argv) < 2:
11+
print(f"Usage: {sys.argv[0]} <files...>")
12+
sys.exit(1)
13+
14+
files = sys.argv[1:]
15+
16+
outputs: list[str] = []
17+
for file in files:
18+
sha256 = subprocess.check_output(["sha256sum", file]) # nosec
19+
with open(f"{file}.sha256", "wb") as f:
20+
f.write(sha256)
21+
outputs.append(file)
22+
outputs.append(f"{file}.sha256")
23+
24+
if "GITHUB_ACTIONS" in os.environ:
25+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
26+
f.write("artifacts<<EOF\n")
27+
for output in outputs:
28+
f.write(f"{output}\n")
29+
f.write("EOF\n")
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)