Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 2f5ddb8

Browse files
Initial commit
0 parents  commit 2f5ddb8

File tree

16 files changed

+551
-0
lines changed

16 files changed

+551
-0
lines changed

.github/workflows/cicd.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: CI checks + deployment
2+
3+
on:
4+
pull_request:
5+
branches: production
6+
push:
7+
branches: production
8+
9+
jobs:
10+
install-tools:
11+
name: Install tools
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3.3.0
16+
- uses: Roblox/setup-foreman@v1
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
- name: Cache Foreman tools
20+
uses: actions/cache@v3.2.3
21+
with:
22+
path: ~/.foreman
23+
key: tools-${{ hashFiles('foreman.toml') }}
24+
25+
linting:
26+
name: Lint with Selene
27+
runs-on: ubuntu-latest
28+
needs: [install-tools]
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v3.3.0
32+
- name: Restore cached Foreman tools
33+
uses: actions/cache@v3.2.3
34+
with:
35+
path: ~/.foreman
36+
key: tools-${{ hashFiles('foreman.toml') }}
37+
- name: Lint
38+
run: ./scripts/shell/lint.sh src
39+
40+
formatting:
41+
name: Format with StyLua
42+
runs-on: ubuntu-latest
43+
needs: [install-tools]
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v3.3.0
47+
- name: Restore cached Foreman tools
48+
uses: actions/cache@v3.2.3
49+
with:
50+
path: ~/.foreman
51+
key: tools-${{ hashFiles('foreman.toml') }}
52+
- name: Check format
53+
run: ./scripts/shell/check-format.sh src
54+
55+
luau-tests:
56+
name: Run Luau tests via Open Cloud
57+
runs-on: ubuntu-latest
58+
needs: [install-tools]
59+
concurrency:
60+
group: luau-execution
61+
cancel-in-progress: false
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v3.3.0
65+
- name: Restore cached Foreman tools
66+
uses: actions/cache@v3.2.3
67+
with:
68+
path: ~/.foreman
69+
key: tools-${{ hashFiles('foreman.toml') }}
70+
- name: Run tests
71+
run: ./scripts/shell/test.sh default.project.json $TEST_TASK_FILE
72+
env:
73+
ROBLOX_API_KEY: ${{ secrets.ROBLOX_API_KEY }}
74+
ROBLOX_UNIVERSE_ID: ${{ vars.ROBLOX_TEST_UNIVERSE_ID }}
75+
ROBLOX_PLACE_ID: ${{ vars.ROBLOX_TEST_PLACE_ID }}
76+
TEST_TASK_FILE: tasks/runTests.luau
77+
78+
deployment:
79+
name: Deployment
80+
runs-on: ubuntu-latest
81+
needs: [install-tools, linting, formatting, luau-tests] # Only runs if all checks passed
82+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/production' }} # Only runs on pushes to production
83+
steps:
84+
- name: Checkout code
85+
uses: actions/checkout@v3.3.0
86+
- name: Restore cached Foreman tools
87+
uses: actions/cache@v3.2.3
88+
with:
89+
path: ~/.foreman
90+
key: tools-${{ hashFiles('foreman.toml') }}
91+
- name: Publish
92+
run: $HOME/.foreman/bin/rojo upload default.project.json --api_key ${{ secrets.ROBLOX_API_KEY }} --universe_id ${{ vars.ROBLOX_PRODUCTION_UNIVERSE_ID }} --asset_id ${{ vars.ROBLOX_PRODUCTION_PLACE_ID }}

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project place file
2+
/engine-oc-api-cicd-demo.rbxlx
3+
4+
# Roblox Studio lock files
5+
/*.rbxlx.lock
6+
/*.rbxl.lock
7+
8+
# RBXL distributable
9+
dist.rbxl
10+
11+
# pycachce
12+
**/__pycache__

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Roblox place, sample CI/CD setup
2+
3+
> [!WARNING]
4+
> This is a sample project intended to demonstrate how the new Open Cloud Luau execution API can be used. It has not been battle tested so creators should proceed with caution when adapting it for their own experiences.
5+
6+
This repository is an example of a place CI/CD setup for fully managed Rojo projects.
7+
8+
It includes:
9+
10+
- Linting with [Selene](https://github.com/Kampfkarren/selene)
11+
- Validating code format with [StyLua](https://github.com/JohnnyMorganz/StyLua)
12+
- Running tests by building a RBXL with [Rojo](https://github.com/rojo-rbx/rojo), uploading to Roblox, then executing Luau using the Engine Open Cloud API for Executing Luau
13+
- Deployment using [Rojo](https://github.com/rojo-rbx/rojo)
14+
15+
![A screenshot of the CI/CD steps in sequence](screenshot.png)
16+
17+
A special thanks is given to the creators of Rojo, Selene and StyLua for creating such awesome tools.
18+
19+
## How to setup
20+
21+
1. Create a Test place separate from your production place that can be used for running your tests
22+
2. Generate an [Open Cloud API key](https://create.roblox.com/docs/cloud/open-cloud/api-keys) with the following permissions for both your test place and your production place.
23+
- `universe.places:write`
24+
- `universe.place.luau-execution-session:write`
25+
3. Save this API key as a [GitHub Actions Secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) named `ROBLOX_API_KEY`
26+
4. Create G
27+
5. Create [GitHub Actions Repository Variables](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables) for the following values
28+
- `ROBLOX_PRODUCTION_UNIVERSE_ID`, `ROBLOX_PRODUCTION_PLACE_ID`
29+
- `ROBLOX_TEST_UNIVERSE_ID`, `ROBLOX_TEST_PLACE_ID`
30+
6. (Optional) add [GitHub branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule) to validate the checks have been passed on PRs before they have been merged
31+
32+
## Notes
33+
34+
* The CI/CD steps are implemented in [.github/workflows/cicd.yml](.github/workflows/cicd.yml), which in turn calls the python and shell scripts in [/scripts](/scripts)
35+
* The implementation assumes you have a branch called `production` that all commits to are deployed, and all PRs to have checks run
36+
* This implementation assumes you have a fully managed Rojo workflow. The automated testing would theoretically work on a partially managed Rojo workflow (provided your test did not reference non Rojo managed Instances) but deployment will not.
37+
* The python wrappers for Open Cloud inside [/scripts/python](/scripts/python) were written for this demonstration and are not intended as clients for general use
38+
* The Engine Open Cloud API for Executing Luau is currently limited to one concurrent request per universe. The GitHub actions config in this example accounts for this by creating a [concurrency group](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/control-the-concurrency-of-workflows-and-jobs). This will prevent Luau execution jobs from attempting to run concurrently and failing.
39+
* Note, we aim to lift this limit in the future.

default.project.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "engine-oc-api-cicd-demo",
3+
"tree": {
4+
"$className": "DataModel",
5+
6+
"ReplicatedStorage": {
7+
"Shared": {
8+
"$path": "src/shared"
9+
}
10+
},
11+
12+
"ServerScriptService": {
13+
"Server": {
14+
"$path": "src/server"
15+
}
16+
},
17+
18+
"StarterPlayer": {
19+
"StarterPlayerScripts": {
20+
"Client": {
21+
"$path": "src/client"
22+
}
23+
}
24+
},
25+
26+
"Workspace": {
27+
"$properties": {
28+
"FilteringEnabled": true
29+
},
30+
"Baseplate": {
31+
"$className": "Part",
32+
"$properties": {
33+
"Anchored": true,
34+
"Color": [0.38823, 0.37254, 0.38823],
35+
"Locked": true,
36+
"Position": [0, -9, 0],
37+
"Size": [512, 20, 2143]
38+
}
39+
}
40+
},
41+
"Lighting": {
42+
"$properties": {
43+
"Ambient": [0, 0, 0],
44+
"Brightness": 2,
45+
"GlobalShadows": true,
46+
"Outlines": false,
47+
"Technology": "Voxel"
48+
}
49+
},
50+
"SoundService": {
51+
"$properties": {
52+
"RespectFilteringEnabled": true
53+
}
54+
}
55+
}
56+
}

foreman.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tools]
2+
rojo = { github = "rojo-rbx/rojo", version = "7.4.1" }
3+
selene = { source = "Kampfkarren/selene", version = "0.24.0" }
4+
stylua = { source = "JohnnyMorganz/stylua", version = "0.16.0" }

screenshot.png

84.7 KB
Loading

0 commit comments

Comments
 (0)