Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/reqwest-0.12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode authored Apr 26, 2024
2 parents 91e5592 + a093b98 commit e9b3c35
Show file tree
Hide file tree
Showing 12 changed files with 512 additions and 84 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ name: CI

on:
push:
branches:
- master

pull_request:
branches:
- master
- main

jobs:
build:
Expand Down
29 changes: 15 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2022-2023, axodotdev
# Copyright 2022-2024, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
# CI that:
#
# * checks for a Git Tag that looks like a release
# * builds artifacts with cargo-dist (archives, installers, hashes)
# * uploads those artifacts to temporary workflow zip
# * on success, uploads the artifacts to a Github Release
# * on success, uploads the artifacts to a GitHub Release
#
# Note that the Github Release will be created with a generated
# Note that the GitHub Release will be created with a generated
# title/body based on your changelogs.

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

jobs:
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
Expand All @@ -62,7 +61,7 @@ jobs:
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
# sure would be cool if github gave us proper conditionals...
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
# functionality based on whether this is a pull_request, and whether it's from a fork.
Expand Down Expand Up @@ -109,6 +108,8 @@ jobs:
with:
submodules: recursive
- uses: swatinem/rust-cache@v2
with:
key: ${{ join(matrix.targets, '-') }}
- name: Install cargo-dist
run: ${{ matrix.install_dist }}
# Get the dist-manifest
Expand All @@ -135,7 +136,7 @@ jobs:
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
Expand All @@ -162,7 +163,7 @@ jobs:
submodules: recursive
- name: Install cargo-dist
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch local artifacts
uses: actions/download-artifact@v4
Expand All @@ -178,7 +179,7 @@ jobs:
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
Expand Down Expand Up @@ -207,15 +208,15 @@ jobs:
with:
submodules: recursive
- name: Install cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.2/cargo-dist-installer.sh | sh"
# Fetch artifacts from scratch-storage
- name: Fetch artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: target/distrib/
merge-multiple: true
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
- id: host
shell: bash
run: |
Expand All @@ -230,7 +231,7 @@ jobs:
name: artifacts-dist-manifest
path: dist-manifest.json

# Create a Github Release while uploading all files to it
# Create a GitHub Release while uploading all files to it
announce:
needs:
- plan
Expand All @@ -246,7 +247,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: "Download Github Artifacts"
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
Expand All @@ -256,7 +257,7 @@ jobs:
run: |
# Remove the granular manifests
rm -f artifacts/*-dist-manifest.json
- name: Create Github Release
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.plan.outputs.tag }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "asphalt"
version = "0.4.2"
version = "0.5.0"
edition = "2021"
license = "MIT"
authors = ["Jack T <[email protected]>"]
Expand Down Expand Up @@ -32,20 +32,23 @@ lto = "thin"
# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.12.0"
cargo-dist-version = "0.13.2"
# CI backends to support
ci = ["github"]
# The installers to generate for each app
installers = []
# Target platforms to build apps for (Rust target-triple syntax)
targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
]
# Publish jobs to run in CI
pr-run-mode = "skip"
# The archive format to use for windows builds (defaults .zip)
windows-archive = ".zip"
# The archive format to use for non-windows builds (defaults .tar.xz)
unix-archive = ".zip"
# Checksums to generate for each App
checksum = "false"
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ Asphalt is configured with a project file called `asphalt.toml`. It is required
```toml
asset_dir = "test/"
write_dir = "output/"

[codegen]
typescript = true
luau = true
style = "flat"
output_name = "assets"

[creator]
type = "user"
id = 9670971

[existing."test/online_asset.ogg"]
id = 583095803
[existing]
"test/some_sound_on_roblox.ogg" = { id = 123456789 }
"test/some_image_on_roblox.png" = { id = 987654321 }
```

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

#### Creator

- `type`: "user" or "group"
- `id`: number

#### Codegen

- `typescript`: boolean (optional)
- Generate a Typescript definition file.
- `luau`: boolean (optional)
- Use the `luau` file extension.
- `style`: "flat" | "nested" (optional)
- 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`.
- `output_name`: string (optional)
- The name for the generated files. Defaults to `assets`.

#### ExistingAsset

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

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.

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.
43 changes: 0 additions & 43 deletions src/codegen.rs → src/codegen/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,3 @@ pub fn generate_ts(
output_dir, interface, output_dir
))
}

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

use crate::{FileEntry, LockFile};

fn test_lockfile() -> LockFile {
let mut entries = BTreeMap::new();
entries.insert(
"assets/foo.png".to_string(),
FileEntry {
asset_id: 1,
hash: "a".to_string(),
},
);
entries.insert(
"assets/bar/baz.png".to_string(),
FileEntry {
asset_id: 2,
hash: "b".to_string(),
},
);

LockFile { entries }
}

#[test]
fn generate_lua() {
let lockfile = test_lockfile();

let lua = super::generate_lua(&lockfile, "assets").unwrap();
assert_eq!(lua, "return {\n\t[\"/bar/baz.png\"] = \"rbxassetid://2\",\n\t[\"/foo.png\"] = \"rbxassetid://1\"\n}");
}

#[test]
fn generate_ts() {
let lockfile = test_lockfile();

let ts = super::generate_ts(&lockfile, "assets", "assets").unwrap();
assert_eq!(ts, "declare const assets: {\n\t\"/bar/baz.png\": string,\n\t\"/foo.png\": string\n}\nexport = assets");
}
}
89 changes: 89 additions & 0 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use crate::{config::StyleType, LockFile};

mod flat;
mod nested;

pub fn generate_lua(
lockfile: &LockFile,
strip_dir: &str,
style: &StyleType,
) -> anyhow::Result<String> {
match style {
StyleType::Flat => flat::generate_lua(lockfile, strip_dir),
StyleType::Nested => nested::generate_lua(lockfile, strip_dir),
}
}

pub fn generate_ts(
lockfile: &LockFile,
strip_dir: &str,
output_dir: &str,
style: &StyleType,
) -> anyhow::Result<String> {
match style {
StyleType::Flat => flat::generate_ts(lockfile, strip_dir, output_dir),
StyleType::Nested => nested::generate_ts(lockfile, strip_dir, output_dir),
}
}

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

use crate::{FileEntry, LockFile};

fn test_lockfile() -> LockFile {
let mut entries = BTreeMap::new();
entries.insert(
"assets/foo.png".to_string(),
FileEntry {
asset_id: 1,
hash: "a".to_string(),
},
);
entries.insert(
"assets/bar/baz.png".to_string(),
FileEntry {
asset_id: 2,
hash: "b".to_string(),
},
);
LockFile { entries }
}

#[test]
fn generate_lua() {
let lockfile = test_lockfile();

let lua = super::flat::generate_lua(&lockfile, "assets").unwrap();
assert_eq!(lua, "return {\n\t[\"/bar/baz.png\"] = \"rbxassetid://2\",\n\t[\"/foo.png\"] = \"rbxassetid://1\"\n}");
}

#[test]
fn generate_ts() {
let lockfile = test_lockfile();

let ts = super::flat::generate_ts(&lockfile, "assets", "assets").unwrap();
assert_eq!(ts, "declare const assets: {\n\t\"/bar/baz.png\": string,\n\t\"/foo.png\": string\n}\nexport = assets");
}

#[test]
fn generate_lua_nested() {
let lockfile = test_lockfile();

let lua = super::nested::generate_lua(&lockfile, "assets").unwrap();
assert_eq!(
lua,
"return {\n bar = {\n [\"baz.png\"] = \"rbxassetid://2\",\n },\n [\"foo.png\"] = \"rbxassetid://1\",\n}");
}

#[test]
fn generate_ts_nested() {
let lockfile = test_lockfile();

let ts = super::nested::generate_ts(&lockfile, "assets", "assets").unwrap();
assert_eq!(
ts,
"declare const assets: {\n bar: {\n \"baz.png\": \"rbxassetid://2\",\n },\n \"foo.png\": \"rbxassetid://1\",\n}\nexport = assets");
}
}
Loading

0 comments on commit e9b3c35

Please sign in to comment.