Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI + test #62

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [master]
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-*"

pull_request:
branches: [master]

concurrency:
group: ci-${{ github.ref }}-1
# Cancel previous builds for pull requests only.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [
macos-13, # x64
macos-14, # ARM
ubuntu-latest, # x64
buildjet-2vcpu-ubuntu-2204-arm, # ARM
# windows-latest, # deactivated for now as there is still a Windows issue
]

runs-on: ${{matrix.os}}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: NPM install
run: npm ci

- name: Build
run: npx rescript

- name: Test
env:
CI: 1
shell: bash
run: |
npm pack
npm i -g ./create-rescript-app-*.tgz
npx create-rescript-app
6 changes: 6 additions & 0 deletions src/CI.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@val @scope("process.env") external ci: string = "CI"

let isRunningInCI = switch ci {
| "1" | "true" | "TRUE" => true
| _ => false
}
1 change: 1 addition & 0 deletions src/CI.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let isRunningInCI: bool
8 changes: 7 additions & 1 deletion src/Main.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ https://rescript-lang.org`,
let rescriptJsonPath = Path.join2(Process.cwd(), "rescript.json")
let bsconfigJsonPath = Path.join2(Process.cwd(), "bsconfig.json")

if Fs.existsSync(rescriptJsonPath) || Fs.existsSync(bsconfigJsonPath) {
if CI.isRunningInCI {
P.note(~title="CI Mode", ~message="Running in CI, will create a test project")
await handleError(~outro="Project creation failed.", async () => {
await NewProject.createNewProject()
P.outro("CI test completed successfully.")
})
} else if Fs.existsSync(rescriptJsonPath) || Fs.existsSync(bsconfigJsonPath) {
ExistingRescriptProject.showUpgradeHint()
P.outro("No changes were made to your project.")
} else if Fs.existsSync(packageJsonPath) {
Expand Down
51 changes: 34 additions & 17 deletions src/NewProject.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,15 @@ let getTemplateOptions = () =>
hint: shortDescription,
})

let createNewProject = async () => {
P.note(~title="New Project", ~message=newProjectMessage)

let projectName = await P.text({
message: "What is the name of your new ReScript project?",
placeholder: "my-rescript-app",
initialValue: ?Process.argv[2],
validate: validateProjectName,
})->P.resultOrRaise

let templateName =
await P.select({message: "Select a template", options: getTemplateOptions()})->P.resultOrRaise

let versions = await RescriptVersions.promptVersions()

let createProject = async (~templateName, ~projectName, ~versions) => {
let templatePath = CraPaths.getTemplatePath(~templateName)
let projectPath = Path.join2(Process.cwd(), projectName)

let s = P.spinner()

s->P.Spinner.start("Creating project...")
if !CI.isRunningInCI {
s->P.Spinner.start("Creating project...")
}

await Fs.Promises.cp(templatePath, projectPath, ~options={recursive: true})
Process.chdir(projectPath)
Expand All @@ -83,5 +71,34 @@ let createNewProject = async () => {
await RescriptVersions.installVersions(versions)
let _ = await Promisified.ChildProcess.execFile("git", ["init"])

s->P.Spinner.stop("Project created.")
if !CI.isRunningInCI {
s->P.Spinner.stop("Project created.")
}
}

let createNewProject = async () => {
P.note(~title="New Project", ~message=newProjectMessage)

if CI.isRunningInCI {
// type versions = {rescriptVersion: string, rescriptCoreVersion: string}
await createProject(
~templateName="rescript-template-basic",
~projectName="test",
~versions={rescriptVersion: "11.1.1", rescriptCoreVersion: "1.5.0"},
)
} else {
let projectName = await P.text({
message: "What is the name of your new ReScript project?",
placeholder: "my-rescript-app",
initialValue: ?Process.argv[2],
validate: validateProjectName,
})->P.resultOrRaise

let templateName =
await P.select({message: "Select a template", options: getTemplateOptions()})->P.resultOrRaise

let versions = await RescriptVersions.promptVersions()

await createProject(~templateName, ~projectName, ~versions)
}
}