Skip to content

Commit 0b2808c

Browse files
authored
Merge branch 'main' into dependabot/cargo/serde-1.0.198
2 parents b954b8a + a093b98 commit 0b2808c

File tree

12 files changed

+512
-84
lines changed

12 files changed

+512
-84
lines changed

.github/workflows/ci.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches:
6-
- master
7-
85
pull_request:
96
branches:
10-
- master
7+
- main
118

129
jobs:
1310
build:

.github/workflows/release.yml

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Copyright 2022-2023, axodotdev
1+
# Copyright 2022-2024, axodotdev
22
# SPDX-License-Identifier: MIT or Apache-2.0
33
#
44
# CI that:
55
#
66
# * checks for a Git Tag that looks like a release
77
# * builds artifacts with cargo-dist (archives, installers, hashes)
88
# * uploads those artifacts to temporary workflow zip
9-
# * on success, uploads the artifacts to a Github Release
9+
# * on success, uploads the artifacts to a GitHub Release
1010
#
11-
# Note that the Github Release will be created with a generated
11+
# Note that the GitHub Release will be created with a generated
1212
# title/body based on your changelogs.
1313

1414
name: Release
@@ -31,7 +31,7 @@ permissions:
3131
# packages versioned/released in lockstep).
3232
#
3333
# If you push multiple tags at once, separate instances of this workflow will
34-
# spin up, creating an independent announcement for each one. However Github
34+
# spin up, creating an independent announcement for each one. However, GitHub
3535
# will hard limit this to 3 tags per commit, as it will assume more tags is a
3636
# mistake.
3737
#
@@ -41,7 +41,6 @@ on:
4141
push:
4242
tags:
4343
- '**[0-9]+.[0-9]+.[0-9]+*'
44-
pull_request:
4544

4645
jobs:
4746
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
@@ -62,7 +61,7 @@ jobs:
6261
# we specify bash to get pipefail; it guards against the `curl` command
6362
# failing. otherwise `sh` won't catch that `curl` returned non-0
6463
shell: bash
65-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
64+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
6665
# sure would be cool if github gave us proper conditionals...
6766
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
6867
# functionality based on whether this is a pull_request, and whether it's from a fork.
@@ -109,6 +108,8 @@ jobs:
109108
with:
110109
submodules: recursive
111110
- uses: swatinem/rust-cache@v2
111+
with:
112+
key: ${{ join(matrix.targets, '-') }}
112113
- name: Install cargo-dist
113114
run: ${{ matrix.install_dist }}
114115
# Get the dist-manifest
@@ -135,7 +136,7 @@ jobs:
135136
run: |
136137
# Parse out what we just built and upload it to scratch storage
137138
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
139+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
139140
echo "EOF" >> "$GITHUB_OUTPUT"
140141
141142
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -162,7 +163,7 @@ jobs:
162163
submodules: recursive
163164
- name: Install cargo-dist
164165
shell: bash
165-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
166+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
166167
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
167168
- name: Fetch local artifacts
168169
uses: actions/download-artifact@v4
@@ -178,7 +179,7 @@ jobs:
178179
179180
# Parse out what we just built and upload it to scratch storage
180181
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
181-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
182+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
182183
echo "EOF" >> "$GITHUB_OUTPUT"
183184
184185
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
@@ -207,15 +208,15 @@ jobs:
207208
with:
208209
submodules: recursive
209210
- name: Install cargo-dist
210-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
211+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
211212
# Fetch artifacts from scratch-storage
212213
- name: Fetch artifacts
213214
uses: actions/download-artifact@v4
214215
with:
215216
pattern: artifacts-*
216217
path: target/distrib/
217218
merge-multiple: true
218-
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219+
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
219220
- id: host
220221
shell: bash
221222
run: |
@@ -230,7 +231,7 @@ jobs:
230231
name: artifacts-dist-manifest
231232
path: dist-manifest.json
232233

233-
# Create a Github Release while uploading all files to it
234+
# Create a GitHub Release while uploading all files to it
234235
announce:
235236
needs:
236237
- plan
@@ -246,7 +247,7 @@ jobs:
246247
- uses: actions/checkout@v4
247248
with:
248249
submodules: recursive
249-
- name: "Download Github Artifacts"
250+
- name: "Download GitHub Artifacts"
250251
uses: actions/download-artifact@v4
251252
with:
252253
pattern: artifacts-*
@@ -256,7 +257,7 @@ jobs:
256257
run: |
257258
# Remove the granular manifests
258259
rm -f artifacts/*-dist-manifest.json
259-
- name: Create Github Release
260+
- name: Create GitHub Release
260261
uses: ncipollo/release-action@v1
261262
with:
262263
tag: ${{ needs.plan.outputs.tag }}

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "asphalt"
3-
version = "0.4.2"
3+
version = "0.5.0"
44
edition = "2021"
55
license = "MIT"
66
authors = ["Jack T <[email protected]>"]
@@ -32,20 +32,23 @@ lto = "thin"
3232
# Config for 'cargo dist'
3333
[workspace.metadata.dist]
3434
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
35-
cargo-dist-version = "0.12.0"
35+
cargo-dist-version = "0.13.2"
3636
# CI backends to support
3737
ci = ["github"]
3838
# The installers to generate for each app
3939
installers = []
4040
# Target platforms to build apps for (Rust target-triple syntax)
4141
targets = [
42-
"aarch64-apple-darwin",
43-
"x86_64-apple-darwin",
44-
"x86_64-unknown-linux-gnu",
45-
"x86_64-pc-windows-msvc",
42+
"aarch64-apple-darwin",
43+
"x86_64-apple-darwin",
44+
"x86_64-unknown-linux-gnu",
45+
"x86_64-pc-windows-msvc",
4646
]
4747
# Publish jobs to run in CI
4848
pr-run-mode = "skip"
49+
# The archive format to use for windows builds (defaults .zip)
4950
windows-archive = ".zip"
51+
# The archive format to use for non-windows builds (defaults .tar.xz)
5052
unix-archive = ".zip"
53+
# Checksums to generate for each App
5154
checksum = "false"

README.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ Asphalt is configured with a project file called `asphalt.toml`. It is required
3535
```toml
3636
asset_dir = "test/"
3737
write_dir = "output/"
38+
39+
[codegen]
3840
typescript = true
3941
luau = true
42+
style = "flat"
43+
output_name = "assets"
4044

4145
[creator]
4246
type = "user"
4347
id = 9670971
4448

45-
[existing."test/online_asset.ogg"]
46-
id = 583095803
49+
[existing]
50+
"test/some_sound_on_roblox.ogg" = { id = 123456789 }
51+
"test/some_image_on_roblox.png" = { id = 987654321 }
4752
```
4853

4954
</details>
@@ -56,19 +61,26 @@ id = 583095803
5661
- The directory to output the generated code to. This should probably be somewhere in your game's source folder.
5762
- `creator`: Creator
5863
- The Roblox creator to upload the assets under.
59-
- `typescript`: boolean (optional)
60-
- Generate a Typescript definition file.
61-
- `luau`: boolean (optional)
62-
- Use the `luau` file extension.
63-
- `output_name`: string (optional)
64-
- The name for the generated files. Defaults to `assets`.
64+
- `codegen`: Codegen
65+
- Code generation options.
6566
- `existing`: map<string, ExistingAsset> (optional)
6667

6768
#### Creator
6869

6970
- `type`: "user" or "group"
7071
- `id`: number
7172

73+
#### Codegen
74+
75+
- `typescript`: boolean (optional)
76+
- Generate a Typescript definition file.
77+
- `luau`: boolean (optional)
78+
- Use the `luau` file extension.
79+
- `style`: "flat" | "nested" (optional)
80+
- The code-generation style to use. Defaults to `flat`. If you would like to have an experience similar to [Tarmac](https://github.com/rojo-rbx/tarmac), use `nested`.
81+
- `output_name`: string (optional)
82+
- The name for the generated files. Defaults to `assets`.
83+
7284
#### ExistingAsset
7385

7486
- `id`: number
@@ -80,3 +92,5 @@ Just run `asphalt` and make sure you have a config file as specified above. When
8092
## API Key
8193

8294
You will need an API key to run Asphalt. You can specify this using the `--api-key` argument, or the `ASPHALT_API_KEY` environment variable.
95+
96+
You can get one from the [Creator Dashboard](https://create.roblox.com/dashboard/credentials). Make sure you select the correct group and Asset-related permissions.

src/codegen.rs src/codegen/flat.rs

-43
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,3 @@ pub fn generate_ts(
4747
output_dir, interface, output_dir
4848
))
4949
}
50-
51-
#[cfg(test)]
52-
mod tests {
53-
use std::collections::BTreeMap;
54-
55-
use crate::{FileEntry, LockFile};
56-
57-
fn test_lockfile() -> LockFile {
58-
let mut entries = BTreeMap::new();
59-
entries.insert(
60-
"assets/foo.png".to_string(),
61-
FileEntry {
62-
asset_id: 1,
63-
hash: "a".to_string(),
64-
},
65-
);
66-
entries.insert(
67-
"assets/bar/baz.png".to_string(),
68-
FileEntry {
69-
asset_id: 2,
70-
hash: "b".to_string(),
71-
},
72-
);
73-
74-
LockFile { entries }
75-
}
76-
77-
#[test]
78-
fn generate_lua() {
79-
let lockfile = test_lockfile();
80-
81-
let lua = super::generate_lua(&lockfile, "assets").unwrap();
82-
assert_eq!(lua, "return {\n\t[\"/bar/baz.png\"] = \"rbxassetid://2\",\n\t[\"/foo.png\"] = \"rbxassetid://1\"\n}");
83-
}
84-
85-
#[test]
86-
fn generate_ts() {
87-
let lockfile = test_lockfile();
88-
89-
let ts = super::generate_ts(&lockfile, "assets", "assets").unwrap();
90-
assert_eq!(ts, "declare const assets: {\n\t\"/bar/baz.png\": string,\n\t\"/foo.png\": string\n}\nexport = assets");
91-
}
92-
}

src/codegen/mod.rs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use crate::{config::StyleType, LockFile};
2+
3+
mod flat;
4+
mod nested;
5+
6+
pub fn generate_lua(
7+
lockfile: &LockFile,
8+
strip_dir: &str,
9+
style: &StyleType,
10+
) -> anyhow::Result<String> {
11+
match style {
12+
StyleType::Flat => flat::generate_lua(lockfile, strip_dir),
13+
StyleType::Nested => nested::generate_lua(lockfile, strip_dir),
14+
}
15+
}
16+
17+
pub fn generate_ts(
18+
lockfile: &LockFile,
19+
strip_dir: &str,
20+
output_dir: &str,
21+
style: &StyleType,
22+
) -> anyhow::Result<String> {
23+
match style {
24+
StyleType::Flat => flat::generate_ts(lockfile, strip_dir, output_dir),
25+
StyleType::Nested => nested::generate_ts(lockfile, strip_dir, output_dir),
26+
}
27+
}
28+
29+
#[cfg(test)]
30+
mod tests {
31+
use std::collections::BTreeMap;
32+
33+
use crate::{FileEntry, LockFile};
34+
35+
fn test_lockfile() -> LockFile {
36+
let mut entries = BTreeMap::new();
37+
entries.insert(
38+
"assets/foo.png".to_string(),
39+
FileEntry {
40+
asset_id: 1,
41+
hash: "a".to_string(),
42+
},
43+
);
44+
entries.insert(
45+
"assets/bar/baz.png".to_string(),
46+
FileEntry {
47+
asset_id: 2,
48+
hash: "b".to_string(),
49+
},
50+
);
51+
LockFile { entries }
52+
}
53+
54+
#[test]
55+
fn generate_lua() {
56+
let lockfile = test_lockfile();
57+
58+
let lua = super::flat::generate_lua(&lockfile, "assets").unwrap();
59+
assert_eq!(lua, "return {\n\t[\"/bar/baz.png\"] = \"rbxassetid://2\",\n\t[\"/foo.png\"] = \"rbxassetid://1\"\n}");
60+
}
61+
62+
#[test]
63+
fn generate_ts() {
64+
let lockfile = test_lockfile();
65+
66+
let ts = super::flat::generate_ts(&lockfile, "assets", "assets").unwrap();
67+
assert_eq!(ts, "declare const assets: {\n\t\"/bar/baz.png\": string,\n\t\"/foo.png\": string\n}\nexport = assets");
68+
}
69+
70+
#[test]
71+
fn generate_lua_nested() {
72+
let lockfile = test_lockfile();
73+
74+
let lua = super::nested::generate_lua(&lockfile, "assets").unwrap();
75+
assert_eq!(
76+
lua,
77+
"return {\n bar = {\n [\"baz.png\"] = \"rbxassetid://2\",\n },\n [\"foo.png\"] = \"rbxassetid://1\",\n}");
78+
}
79+
80+
#[test]
81+
fn generate_ts_nested() {
82+
let lockfile = test_lockfile();
83+
84+
let ts = super::nested::generate_ts(&lockfile, "assets", "assets").unwrap();
85+
assert_eq!(
86+
ts,
87+
"declare const assets: {\n bar: {\n \"baz.png\": \"rbxassetid://2\",\n },\n \"foo.png\": \"rbxassetid://1\",\n}\nexport = assets");
88+
}
89+
}

0 commit comments

Comments
 (0)