Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…chine-luau into temp/test-dump
  • Loading branch information
BusyCityGuy committed Sep 25, 2024
2 parents ae4ae04 + 4e9c9a1 commit bdbe0a4
Show file tree
Hide file tree
Showing 21 changed files with 661 additions and 254 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Lint StateMachine
run: ./scripts/lint.sh src/StateMachine
- name: Lint StateQ
run: ./scripts/lint.sh src/StateQ

- name: Lint tests
run: ./scripts/lint.sh src/TestService
Expand Down Expand Up @@ -83,8 +83,8 @@ jobs:
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Enforce StateMachine code style with StyLua
run: ./scripts/formatCheck.sh src/StateMachine
- name: Enforce StateQ code style with StyLua
run: ./scripts/formatCheck.sh src/StateQ

- name: Enforce tests code style with StyLua
run: ./scripts/formatCheck.sh src/TestService
Expand Down Expand Up @@ -112,10 +112,10 @@ jobs:
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Analyze StateMachine with luau-lsp
- name: Analyze StateQ with luau-lsp
run: |
./scripts/sourcemap.sh default.project.json stateMachineSourcemap.json
./scripts/analyze.sh stateMachineSourcemap.json src/StateMachine
./scripts/sourcemap.sh default.project.json stateQSourcemap.json
./scripts/analyze.sh stateQSourcemap.json src/StateQ
- name: Analyze tests with luau-lsp
run: |
Expand Down
223 changes: 223 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
name: Release

on:
release:
types: [published]

jobs:
get-version:
name: Get version from release tag
runs-on: ubuntu-latest

outputs:
tag-name: ${{ steps.output-version.outputs.tag_name }}
version-with-dots: ${{ steps.output-version.outputs.version_with_dots }}
version-with-dashes: ${{ steps.output-version.outputs.version_with_dashes }}

steps:
- name: Checkout code
uses: actions/[email protected]

- name: Output version and tag name
id: output-version
run: |
# Get the tag name (e.g., v0.1.0)
tag_name="${{ github.event.release.tag_name }}"
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
echo "tag_name=$tag_name"
# Strip the leading 'v' to get the version (e.g., 0.1.0)
version_with_dots="${tag_name#v}"
echo "version_with_dots=$version_with_dots" >> $GITHUB_OUTPUT
echo "version_with_dots=$version_with_dots"
# Replaces . with - for use in filenames (e.g., 0-1-0)
version_with_dashes="${version_with_dots//./-}"
echo "version_with_dashes=$version_with_dashes" >> $GITHUB_OUTPUT
echo "version_with_dashes=$version_with_dashes"
install-tools:
name: Install tools and dependencies
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/[email protected]

- name: Install Rokit
uses: CompeyDev/[email protected]

- name: Setup Lune
run: lune setup

- name: Install dependencies with Wally
run: wally install

- name: Cache installed items
uses: actions/[email protected]
with:
path: |
~/.rokit
~/.lune
Packages
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

preprocess-release:
name: Preprocess release (update versions, copyright years)
runs-on: ubuntu-latest
needs: [install-tools, get-version]
environment: Release Preprocessor
permissions:
contents: write
outputs:
commit-hash: ${{ steps.commit-and-push.outputs.commit_hash }}

steps:
- uses: actions/[email protected]
id: release-preprocessor-bot-token
with:
app-id: ${{ vars.RELEASE_PREPROCESSOR_APP_ID }}
private-key: ${{ secrets.RELEASE_PREPROCESSOR_PRIVATE_KEY }}

- name: Checkout code
uses: actions/[email protected]
with:
token: ${{ steps.release-preprocessor-bot-token.outputs.token }}

- name: Restore installed items
uses: actions/[email protected]
with:
path: |
~/.rokit
~/.lune
Packages
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Add rokit tools to PATH
run: echo "$HOME/.rokit/bin" >> $GITHUB_PATH

- name: Locally update version & copyright year in files
run: lune run preprocessRelease ${{ needs.get-version.outputs.version-with-dots }}

- name: Commit version & copyright year updates
id: commit-and-push
uses: stefanzweifel/[email protected]
with:
commit_message: "Preprocess release for version ${{ needs.get-version.outputs.version-with-dots }}"
branch: main
file_pattern: "README.md wally.toml src/StateQ/init.luau LICENSE.md"

create-release-artifacts:
name: Create release artifacts
runs-on: ubuntu-latest
needs: [install-tools, get-version, preprocess-release]

steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ needs.preprocess-release.outputs.commit-hash }}

- name: Restore installed items
uses: actions/[email protected]
with:
path: |
~/.rokit
~/.lune
Packages
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Add rokit tools to PATH
run: echo "$HOME/.rokit/bin" >> $GITHUB_PATH

- name: Build release artifacts
run: lune run build ${{ needs.get-version.outputs.version-with-dashes }}

- name: Cache artifacts
uses: actions/[email protected]
with:
path: |
build
wally.toml
key: artifacts-${{ needs.get-version.outputs.tag-name }}

publish-wally-artifact:
name: Publish release artifact to Wally
runs-on: ubuntu-latest
needs:
[install-tools, get-version, preprocess-release, create-release-artifacts]

steps:
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ needs.preprocess-release.outputs.commit-hash }}

- name: Restore installed items
uses: actions/[email protected]
with:
path: |
~/.rokit
~/.lune
Packages
DevPackages
key: tools-${{ hashFiles('rokit.toml') }}

- name: Restore build artifacts
uses: actions/[email protected]
with:
path: |
build
wally.toml
key: artifacts-${{ needs.get-version.outputs.tag-name }}

- name: Add rokit tools to PATH
run: echo "$HOME/.rokit/bin" >> $GITHUB_PATH

- name: Log in to Wally
run: wally login --token ${{ secrets.WALLY_ACCESS_TOKEN }}

- name: Publish package to Wally
run: wally publish

upload-github-artifacts:
name: Upload artifacts to the GitHub release
runs-on: ubuntu-latest
needs: [get-version, create-release-artifacts]
permissions:
contents: write

steps:
- name: Restore build artifacts
uses: actions/[email protected]
with:
path: |
build
wally.toml
key: artifacts-${{ needs.get-version.outputs.tag-name }}

- name: Print files
run: ls -R

- name: Upload zip artifact to the GitHub release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: build/zip/StateQ-${{ needs.get-version.outputs.version-with-dashes}}.zip
asset_name: StateQ-${{ needs.get-version.outputs.version-with-dashes}}.zip
asset_content_type: application/zip

- name: Upload rbxm artifact to the GitHub release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: build/rbxm/StateQ-${{ needs.get-version.outputs.version-with-dashes }}.rbxm
asset_name: StateQ-${{ needs.get-version.outputs.version-with-dashes }}.rbxm
asset_content_type: application/octet-stream
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ globaltypes.d.luau
Packages
DevPackages
*sourcemap.json
settings.json
settings.json
build
.DS_Store
19 changes: 14 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ If you're running tests in studio yourself (not recommended) instead of using th

| Method | Instructions |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| CLI | `rojo build test.project.json -o StateMachine-Test.rbxl` |
| CLI | `rojo build test.project.json -o StateQ-Test.rbxl` |
| VSC Extension | Click Rojo on the status bar at the bottom, mouse over `test.project.json` in the pop-up menu, and click the Build icon on the right of the list item. |
</details>

Expand Down Expand Up @@ -174,10 +174,10 @@ You need to set the `FFlagEnableLoadModule` value to `true`. Be sure to restart

### Run tests

| Method | Instructions |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CLI (recommended) | `lune run test` |
| Roblox Studio | Open the test place file `StateMachine-Test.rbxl` [built in the above step](#build-the-project) in Roblox Studio and run the place (server only). The output widget will show the test results. |
| Method | Instructions |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CLI (recommended) | `lune run test` |
| Roblox Studio | Open the test place file `StateQ-Test.rbxl` [built in the above step](#build-the-project) in Roblox Studio and run the place (server only). The output widget will show the test results. |

### Continuous Integration (CI)

Expand Down Expand Up @@ -211,3 +211,12 @@ Alternatively, you can run individual steps yourself:
There is an additional script available to fix formatting with StyLua, that does not run on GitHub:

> lune run formatFix
## Releasing

1. To make a release, use the GitHub web interface to [create a new release](https://github.com/BusyCityGuy/finite-state-machine-luau/releases/new).
1. Choose a tag with a version number like `v0.0.0`, beginning with `v` and using semantic versioning. No suffix like `-pre` is supported, only numbers as shown.
1. Create a release title, preferably something like "Version 0.0.0" to be consistent with the tag.
1. Describe the changes in the release
1. Publish release
1. A GitHub Actions workflow will automatically run and upload .zip and .rbxm artifacts to the release. It will also automatically publish the release to Wally, and update hardcoded numbers throughout the codebase like versions and copyright years.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 BusyCityGuy
Copyright (c) 2024 BusyCityGuy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Finite State Machine (FSM) in Luau
# StateQ: A Finite State Machine (FSM) in Luau

A feature rich and fully typed implementation of a Finite State Machine in [Luau](https://luau-lang.org/), developed for use in Roblox experiences.
An intuitive fully-typed Finite State Machine in [Luau](https://luau-lang.org/) that supports async transitions by queueing events, developed for use in Roblox experiences.

This project is licensed under the terms of the MIT license. See [LICENSE.md](https://github.com/busycityguy/finite-state-machine-luau/blob/main/LICENSE.md) for details.

Expand Down Expand Up @@ -51,7 +51,7 @@ A simple state machine diagram for a light switch may look like this, where
- States are represented as rectangles, and squares indicate the State can be Final
- Events are represented as capsules

![Screen Shot 2023-12-14 at 18 04 33](https://github.com/BusyCityGuy/finite-state-machine-luau/assets/55513323/3d5b2118-91ea-4427-ac2d-688fb0094d1f)
![ExampleUsage](https://github.com/BusyCityGuy/finite-state-machine-luau/assets/55513323/3d5b2118-91ea-4427-ac2d-688fb0094d1f)

```luau
local LightState = {
Expand All @@ -64,7 +64,7 @@ local Event = {
SwitchOff = "SwitchOff",
}
local light = StateMachine.new(LightState.On, {
local light = StateQ.new(LightState.On, {
[Event.SwitchOn] = {
canBeFinal = true,
from = {
Expand Down Expand Up @@ -107,22 +107,22 @@ light:handle(Event.SwitchOn) -- warns "Illegal event `SwitchOn` called during st

# Installation

If your project is set up to build with Rojo, you can add this repository as a submodule of your project by running the following command:
## Rojo users

`git submodule add https://github.com/BusyCityGuy/finite-state-machine-luau path/to/your/dependencies`
If your project is set up to build with Rojo, the preferred installation method is using [Wally](https://wally.run/). Add this to your `wally.toml` file:
> StateQ = "busycityguy/[email protected]"
<details>
<summary>These alternative installations are not implemented yet</summary>
If you're not using Wally, you can add this repository as a submodule of your project by running the following command:

In the future, an alternative installation method will be to download your desired release file from the [Releases](https://github.com/BusyCityGuy/latest) page.
> git submodule add https://github.com/BusyCityGuy/finite-state-machine-luau path/to/your/dependencies
Provided in the release will be a `.zip` file that can be extracted into your Rojo project, or you can download the `.rbxm` and drag it into Roblox Studio if you're not using Rojo.
If you want to avoid submodules too, you can download the `.zip` file from the [latest release](https://github.com/BusyCityGuy/finite-state-machine-luau/releases/latest) page.

Also in the future, this project will be published on [Wally](https://wally.run/), and could be installed into your project by adding `finite-state-machine = "busycityguy/[email protected]"` to your `wally.toml` file.
## Non-Rojo users

</details>
If you aren't using Rojo, you can download the `.rbxm` file from the [latest release](https://github.com/BusyCityGuy/finite-state-machine-luau/releases/latest) page and drag it into Roblox Studio.

# Help!
# Feedback

If you have other questions, bugs, feature requests, or feedback, please [open an issue](https://github.com/BusyCityGuy/finite-state-machine-luau/issues)!

Expand Down
16 changes: 8 additions & 8 deletions default.project.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "StateMachine",
"tree": {
"$path": "src/StateMachine",
"Dependencies": {
"$path": "Packages"
}
}
}
"name": "StateQ",
"tree": {
"$path": "src/StateQ",
"Dependencies": {
"$path": "Packages"
}
}
}
Loading

0 comments on commit bdbe0a4

Please sign in to comment.