Skip to content

Commit 37fae64

Browse files
provide shaders via artifact repo prototype
1 parent 7e8c6cc commit 37fae64

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build and upload shaders for graphene raster nodes to artifacts Repository
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
check:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: DeterminateSystems/nix-installer-action@main
15+
- uses: DeterminateSystems/magic-nix-cache-action@main
16+
17+
- name: Build graphene raster nodes shaders
18+
run: nix develop .nix -c cargo build -r -p graphene-raster-nodes-shaders
19+
20+
- name: Upload graphene raster nodes shaders to artifacts repository
21+
run: |
22+
bash .github/workflows/scripts/artifact-upload.bash \
23+
${{ vars.ARTIFACTS_REPO_OWNER }} \
24+
${{ vars.ARTIFACTS_REPO_NAME }} \
25+
${{ vars.ARTIFACTS_REPO_BRANCH }} \
26+
rev/${{ github.sha }}/graphene_raster_nodes_shaders_entrypoint.wgsl \
27+
target/spirv-builder/spirv-unknown-naga-wgsl/release/deps/graphene_raster_nodes_shaders_entrypoint.wgsl \
28+
"${{ github.sha }} graphene_raster_nodes_shaders_entrypoint.wgsl" \
29+
${{ secrets.ARTIFACTS_REPO_TOKEN }}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
cat <<EOF
6+
Usage: $0 <owner> <repo> <branch> <target-path> <artifact-file> <commit-message> <github-token>
7+
8+
Arguments:
9+
owner : GitHub user or organization of the target repo
10+
repo : Target repo name
11+
branch : Branch name (e.g. main)
12+
target-path : Full path (including folders + filename) in the target repo where to upload
13+
artifact-file : Local file path to upload
14+
commit-message : Commit message for creating/updating the file
15+
github-token : GitHub token (PAT or equivalent) with write access to the target repo
16+
17+
This will perform a GitHub API PUT to /repos/{owner}/{repo}/contents/{target-path}.
18+
If a file already exists at that path, it will auto-detect the SHA and update; otherwise it will create.
19+
EOF
20+
exit 1
21+
}
22+
23+
if [ $# -ne 7 ]; then
24+
usage
25+
fi
26+
27+
OWNER="$1"
28+
REPO="$2"
29+
BRANCH="$3"
30+
TARGET_PATH="$4"
31+
ARTIFACT_PATH="$5"
32+
COMMIT_MSG="$6"
33+
TOKEN="$7"
34+
35+
if [ ! -f "$ARTIFACT_PATH" ]; then
36+
echo "Error: artifact file not found: $ARTIFACT_PATH" >&2
37+
exit 1
38+
fi
39+
40+
LOCAL_SHA=$(git hash-object "$ARTIFACT_PATH")
41+
echo "Local blob SHA: $LOCAL_SHA"
42+
43+
GET_URL="https://api.github.com/repos/${OWNER}/${REPO}/contents/${TARGET_PATH}?ref=${BRANCH}"
44+
GET_RESPONSE=$(curl -s -H "Authorization: token ${TOKEN}" "$GET_URL")
45+
46+
REMOTE_SHA=$(echo "$GET_RESPONSE" | jq -r .sha 2>/dev/null || echo "")
47+
48+
if [ "$REMOTE_SHA" != "null" ] && [ -n "$REMOTE_SHA" ]; then
49+
echo "Remote blob SHA: $REMOTE_SHA"
50+
if [ "$LOCAL_SHA" = "$REMOTE_SHA" ]; then
51+
echo "The remote file is identical. Skipping upload."
52+
exit 0
53+
else
54+
echo "Remote file differs. Preparing to upload."
55+
fi
56+
else
57+
echo "No existing remote file or no SHA found. Creating."
58+
fi
59+
60+
CONTENT_TMP_BASE64=$(mktemp)
61+
if base64 --help 2>&1 | grep -q -- "-w"; then
62+
base64 -w 0 "$ARTIFACT_PATH" > "$CONTENT_TMP_BASE64"
63+
else
64+
base64 "$ARTIFACT_PATH" | tr -d '\n' > "$CONTENT_TMP_BASE64"
65+
fi
66+
67+
PAYLOAD_TMP=$(mktemp)
68+
jq -n \
69+
--arg message "$COMMIT_MSG" \
70+
--arg branch "$BRANCH" \
71+
--arg sha "$REMOTE_SHA" \
72+
--rawfile content "$CONTENT_TMP_BASE64" \
73+
'{
74+
message: $message,
75+
content: $content,
76+
branch: $branch
77+
} + (if ($sha != "" and $sha != "null") then { sha: $sha } else {} end)' \
78+
> "$PAYLOAD_TMP"
79+
80+
UPLOAD_RESPONSE=$(curl -s -X PUT \
81+
-H "Authorization: token ${TOKEN}" \
82+
-H "Content-Type: application/json" \
83+
-d @"$PAYLOAD_TMP" \
84+
"https://api.github.com/repos/${OWNER}/${REPO}/contents/${TARGET_PATH}")
85+
86+
echo "Upload Response:"
87+
echo "$UPLOAD_RESPONSE"
88+
89+
rm -f "$CONTENT_TMP_BASE64" "$PAYLOAD_TMP"

0 commit comments

Comments
 (0)