Skip to content

Commit 8b76447

Browse files
authored
Merge pull request #23 from highcard-dev/codex/minecraft-vanilla-runtime-format
Update Minecraft Vanilla scrolls for new runtime
2 parents 4f87c97 + a08cb72 commit 8b76447

211 files changed

Lines changed: 8802 additions & 5942 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,47 @@ jobs:
66
build-deploy:
77
runs-on: self-hosted
88
env:
9+
SCROLL_REGISTRY_PR_NAMESPACE: druid-team-experimental
910
SCROLL_REGISTRY_ENDPOINT: ${{ secrets.SCROLL_REGISTRY_ENDPOINT }}
1011
SCROLL_REGISTRY_API_KEY: ${{ secrets.SCROLL_REGISTRY_API_KEY }}
1112
SCROLL_REGISTRY_API_SECRET: ${{ secrets.SCROLL_REGISTRY_API_SECRET }}
1213
SCROLL_REGISTRY_BUCKET: ${{ secrets.SCROLL_REGISTRY_BUCKET_STAGING }}
14+
DRUID_CLI_VERSION: pr-76
1315
steps:
1416
- uses: actions/checkout@v3
1517
- uses: actions/setup-go@v3
1618
with:
1719
go-version: ">=1.19.3"
1820
- run: apt update && apt install -y make
19-
- run: make build-tree
21+
- name: Build scroll tree
22+
env:
23+
SCROLL_REGISTRY_HOST: ${{ secrets.SCROLL_REGISTRY_HOST }}
24+
run: |
25+
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
26+
registry_host="${SCROLL_REGISTRY_HOST#http://}"
27+
registry_host="${registry_host#https://}"
28+
registry_host="${registry_host%%/*}"
29+
export DRUID_COLDSTARTER_IMAGE="${registry_host}/${SCROLL_REGISTRY_PR_NAMESPACE}/druid:stable-pr${{ github.event.pull_request.number }}"
30+
fi
31+
make build-tree
2032
- name: Get registry binary
21-
uses: robinraju/release-downloader@v1.7
22-
with:
23-
repository: "highcard-dev/druid-cli"
24-
latest: true
25-
fileName: "druid"
26-
token: ${{ secrets.GO_REPO_TOKEN }}
27-
- run: chmod +x ./druid
33+
if: github.event.pull_request.head.repo.full_name == github.repository
34+
env:
35+
GH_TOKEN: ${{ secrets.GO_REPO_TOKEN }}
36+
run: |
37+
gh release download "$DRUID_CLI_VERSION" --repo highcard-dev/druid-cli --pattern druid --clobber
2838
- name: Install druid
29-
run: mv ./druid /usr/local/bin/druid
30-
- run: ./scripts/validate_all_scrolls.sh
39+
if: github.event.pull_request.head.repo.full_name == github.repository
40+
run: |
41+
chmod +x druid
42+
mv druid /usr/local/bin/druid
43+
- name: Validate all scrolls
44+
run: ./scripts/validate_all_scrolls.sh
45+
- name: Login to registry
46+
if: github.event.pull_request.head.repo.full_name == github.repository
47+
run: druid login --host ${{ secrets.SCROLL_REGISTRY_HOST }} --user '${{ secrets.SCROLL_REGISTRY_USER }}' --password ${{ secrets.SCROLL_REGISTRY_PASSWORD }}
48+
- name: Push experimental PR tags
49+
if: github.event.pull_request.head.repo.full_name == github.repository
50+
env:
51+
SCROLL_REGISTRY_HOST: ${{ secrets.SCROLL_REGISTRY_HOST }}
52+
run: ./scripts/push.sh "${{ github.event.pull_request.number }}"

.github/workflows/release.yml

Lines changed: 115 additions & 115 deletions
Large diffs are not rendered by default.

generate-scrolls.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111
"text/template"
12+
"unicode"
1213

1314
cp "github.com/otiai10/copy"
1415

@@ -19,6 +20,7 @@ type TemplateVars struct {
1920
Artifact string
2021
Version string
2122
VersionEscaped string
23+
ColdstarterImage string
2224
Artifacts map[string]string
2325
ArtifactsUnescaped map[string]string
2426
Vars map[string]string
@@ -69,12 +71,31 @@ func main() {
6971
"split": func(sep, s string) []string {
7072
return strings.Split(s, sep)
7173
},
74+
"upper": strings.ToUpper,
75+
"env": func(value string) string {
76+
var out strings.Builder
77+
for i, r := range value {
78+
if i > 0 && unicode.IsUpper(r) {
79+
out.WriteByte('_')
80+
}
81+
if r == '-' || r == ' ' {
82+
out.WriteByte('_')
83+
continue
84+
}
85+
out.WriteRune(unicode.ToUpper(r))
86+
}
87+
return out.String()
88+
},
7289
}
7390
scollYamltemplate, err := template.New(filepath.Base(scrollYamlTemplate)).Funcs(funcMap).ParseFiles(scrollYamlTemplate)
7491
// Capture any error
7592
if err != nil {
7693
log.Fatalln(err)
7794
}
95+
coldstarterImage := os.Getenv("DRUID_COLDSTARTER_IMAGE")
96+
if coldstarterImage == "" {
97+
coldstarterImage = "artifacts.druid.gg/druid-team/druid:stable"
98+
}
7899

79100
//iterate through artifacts and generate scroll.yaml files
80101
for version, artifact := range artifacts {
@@ -83,6 +104,7 @@ func main() {
83104
templateVars.Artifact = artifact
84105
templateVars.Version = version
85106
templateVars.VersionEscaped = strings.Replace(version, ".", "-", -1)
107+
templateVars.ColdstarterImage = coldstarterImage
86108
templateVars.Artifacts = GetArtifactsAbove(version, artifacts, true)
87109
templateVars.ArtifactsUnescaped = GetArtifactsAbove(version, artifacts, false)
88110
if varsBytes != nil && vars[version] == nil {

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ require (
77
github.com/otiai10/copy v1.12.0
88
)
99

10-
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
10+
require (
11+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
12+
gopkg.in/yaml.v3 v3.0.1 // indirect
13+
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4
55
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
66
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
77
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

scripts/push.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
pr_number="${1:?usage: $0 <pr-number>}"
6+
registry_host="${SCROLL_REGISTRY_HOST:?SCROLL_REGISTRY_HOST is required}"
7+
registry_host="${registry_host#http://}"
8+
registry_host="${registry_host#https://}"
9+
registry_host="${registry_host%%/*}"
10+
11+
namespace="${SCROLL_REGISTRY_PR_NAMESPACE:-druid-team-experimental}"
12+
runtime_namespace="${SCROLL_REGISTRY_RUNTIME_NAMESPACE:-druid-team}"
13+
runtime_image="${DRUID_SCROLL_RUNTIME_IMAGE:-${registry_host}/${runtime_namespace}/druid:stable-nix}"
14+
roots="${SCROLL_PR_ROOTS:-}"
15+
16+
yaml_value() {
17+
awk -F':[[:space:]]*' -v key="$2" '
18+
$1 == key {
19+
value = $2
20+
gsub(/^"/, "", value)
21+
gsub(/"$/, "", value)
22+
print value
23+
exit
24+
}
25+
' "$1"
26+
}
27+
28+
scroll_dirs() {
29+
if [[ -n "$roots" ]]; then
30+
for root in $roots; do
31+
for dir in "$root"/*; do
32+
[[ -f "$dir/scroll.yaml" ]] || continue
33+
printf '%s\n' "$dir"
34+
done
35+
[[ -f "$root/scroll.yaml" ]] && printf '%s\n' "$root"
36+
done
37+
return
38+
fi
39+
find ./scrolls -type f -name scroll.yaml -print | sed 's#/scroll.yaml$##' | sort
40+
}
41+
42+
port_args() {
43+
awk '
44+
/^ports:/ { in_ports=1; next }
45+
/^[^[:space:]-]/ { in_ports=0 }
46+
in_ports && /^[[:space:]]*-[[:space:]]*name:/ {
47+
name=$0
48+
sub(/^[[:space:]]*-[[:space:]]*name:[[:space:]]*/, "", name)
49+
gsub(/"/, "", name)
50+
}
51+
in_ports && /^[[:space:]]*port:/ {
52+
port=$0
53+
sub(/^[[:space:]]*port:[[:space:]]*/, "", port)
54+
if (name != "" && port != "") {
55+
printf " -p %s=%s", name, port
56+
}
57+
}
58+
' "$1/scroll.yaml"
59+
}
60+
61+
category_for_dir() {
62+
local dir="$1"
63+
dir="${dir#./scrolls/}"
64+
echo "${dir%%/*}"
65+
}
66+
67+
push_dir() {
68+
local dir="$1"
69+
local name app_version image artifact ports category
70+
71+
if [[ "$dir" == ./scrolls/.sample || "$dir" == ./scrolls/.sample/* ]]; then
72+
echo "Skipping ${dir}: sample scrolls are validation fixtures"
73+
return
74+
fi
75+
76+
name="$(yaml_value "$dir/scroll.yaml" name)"
77+
app_version="$(yaml_value "$dir/scroll.yaml" app_version)"
78+
if [[ "$app_version" == "latest" ]]; then
79+
echo "Skipping ${dir}: PR previews do not publish latest tags"
80+
return
81+
fi
82+
83+
image="${name##*/}"
84+
artifact="${registry_host}/${namespace}/${image}:${app_version}-pr${pr_number}"
85+
ports="$(port_args "$dir")"
86+
category="$(category_for_dir "$dir")"
87+
88+
echo "Pushing ${artifact} from ${dir}"
89+
# shellcheck disable=SC2086
90+
druid push "$artifact" "$dir" $ports \
91+
-i "$runtime_image" \
92+
--min-disk 3Gi --min-ram 512Mi --min-cpu 0.25 \
93+
--smart --category "$category"
94+
}
95+
96+
while IFS= read -r dir; do
97+
push_dir "$dir"
98+
done < <(scroll_dirs)

0 commit comments

Comments
 (0)