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

Mac support #324

Closed
wants to merge 8 commits into from
Closed
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
1 change: 0 additions & 1 deletion .ci/.gitignore

This file was deleted.

6 changes: 6 additions & 0 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/windows:2004

ARG NODE_URL="https://nodejs.org/dist/v20.9.0/node-v20.9.0-x64.msi"

RUN powershell Invoke-WebRequest -Uri $env:NODE_URL -OutFile node.msi
RUN powershell Start-Process MsiExec.exe -Wait -ArgumentList '/i node.msi /qn'
8 changes: 3 additions & 5 deletions .ci/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
There is a [dockerfile](./dockerfile) available to install Node in so it's easy
to build and test the package without messing with your host system.

1. Download [Node.js installer](https://nodejs.org/en/download/) (msi, 64bit).
2. Update `COPY` in line 3 of [dockerfile](./dockerfile)
3. Build container
1. Build container

```powershell
docker build -t windows-node .
```

4. Run image
2. Run image

```powershell
cd ..
docker run --rm -it -v $(pwd):C:\setup-openmodelica windows-node powershell
docker run --rm -it -v C:\path\to\setup-openmodelica:C:\setup-openmodelica windows-node powershell
```
5 changes: 0 additions & 5 deletions .ci/dockerfile

This file was deleted.

9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ jobs:
test: # make sure the action works on a clean machine without building
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]
os: [macos-latest]
include:
- version: 'stable'
- version: '1.22.0-dev-351'
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: ./
with:
version: 'stable'
version: ${{ matrix.version }}
packages: |
'omc'
'omsimulator'
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

# Ignore mos scripts
*.mos

# Ignore VSCode settings
.vscode/
19 changes: 19 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ switch (osPlat) {
case 'win32':
windowsTests()
break
case 'darwin':
macTests()
break
default:
throw new Error(`Platform ${osPlat} is not supported`)
}
Expand Down Expand Up @@ -162,6 +165,22 @@ function windowsTests(): void {
)
}

function macTests(): void {
test(
'Install 64 bit OpenModelica nightly 1.22.0-dev-351',
async () => {
let version = installer.getOMVersion('1.22.0-dev-44')
expect(version.version).toEqual('1.22.0-dev-44')
version = installer.getOMVersion('1.22.0')
expect(version.version).toEqual('1.22.0-dev-351')
await installer.installOM(['omc'], version, '64')
const resVer = await installer.showVersion('omc')
expect(resVer).toContain('1.22.0')
},
10 * 60000
)
}

function commonTests(): void {
test(
'Install Modelica libraries',
Expand Down
76 changes: 71 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

88 changes: 82 additions & 6 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export function getOMVersions(): string[] {
case 'win32':
osVersionLst = json.windows
break
case 'darwin':
osVersionLst = json.mac
break
default:
// Array stays empty
}
Expand All @@ -53,7 +56,7 @@ export function getOMVersions(): string[] {
* @returns Highest available version matching versionInput.
*/
export function getOMVersion(versionInput: string): VersionType {
if (osPlat !== 'linux' && osPlat !== 'win32') {
if (osPlat !== 'linux' && osPlat !== 'win32' && osPlat !== 'darwin') {
throw new Error(`getOMVersion: OS ${osPlat} not supported.`)
}

Expand All @@ -65,15 +68,41 @@ export function getOMVersion(versionInput: string): VersionType {
versionInput === 'release'
) {
maxVersion = versionInput
} else if (versionInput.includes('dev')) {
maxVersion = versionInput
} else {
// Use the highest available version that matches versionInput
const availableReleases = getOMVersions()
core.debug(`Available versions ${availableReleases}`)
maxVersion = semver.maxSatisfying(availableReleases, versionInput)
if (maxVersion == null) {
throw new Error(
`Could not find a OpenModelica version that matches ${versionInput}`
)
// Check pre-releases
core.debug(`Checking pre releases`)
// Workaround so that 20 is smaller than 100. Add leading zeroes
for (let i=0; i<availableReleases.length; i++) {
if (availableReleases[i].includes('-dev-')) {
const splittedArray = availableReleases[i].split('-dev-')
core.debug(`Splitted array of ${availableReleases[i].toString()}: ${splittedArray.toString()}`)
if (Number(splittedArray[1]) < 100) {
core.debug(`Smaller 100`)
availableReleases[i] = `${splittedArray[0]}-dev-00${splittedArray[1]}`
} else if (Number(splittedArray[1]) < 1000) {
core.debug(`Smaller 1000`)
availableReleases[i] = `${splittedArray[0]}-dev-0${splittedArray[1]}`
}
}
}
core.debug(`Available versions: ${availableReleases.toString()}`)

maxVersion = semver.maxSatisfying(availableReleases, `>${versionInput}-dev`, { includePrerelease: true })
if (maxVersion == null) {
throw new Error(
`Could not find a OpenModelica version that matches ${versionInput}`
)
} else {
// Remove leading zeroes
const splittedArray = maxVersion.split('-dev-')
maxVersion = `${splittedArray[0]}-dev-${Number(splittedArray[1])}`
}
}
}
core.debug(`Searching for ${versionInput}, found max version: ${maxVersion}`)
Expand All @@ -87,6 +116,9 @@ export function getOMVersion(versionInput: string): VersionType {
case 'win32':
osVersionLst = json.windows
break
case 'darwin':
osVersionLst = json.mac
break
default:
// Array stays empty
}
Expand Down Expand Up @@ -174,7 +206,7 @@ async function aptInstallOM(
)

// Install OpenModelica packages
core.info(`Running apt-get install`)
core.info(`Running apt-get inexec--versionstall`)
await exec.exec(`${sudo} apt-get clean`)
await exec.exec(`${sudo} apt-get update`)
for (const pkg of packages) {
Expand Down Expand Up @@ -235,6 +267,47 @@ async function winInstallOM(version: VersionType, bit: string): Promise<void> {
fs.rmSync('tmp', {recursive: true})
}

/**
* Install omc using the Windows installer executable.
*
* @param version Version object to install.
*/
async function macInstallOM(version: VersionType): Promise<void> {

// Download OpenModelica pkg file tmp/
const pkg = await util.downloadCachedSync(
version.address,
'tmp',
version.version === 'nightly'
)

// Check for homebrew
///bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
//(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/arch/.bashrc
//eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

// Run installer
core.info(`Running installer with package ${pkg}`)
await exec.exec(
`installer -verbose -pkg ${pkg} -target CurrentUserHomeDirectory`
)

const out = await exec.getExecOutput('find', ['/Users/runner', '-name', 'omc'])

if (out.exitCode !== 0) {
core.debug(`Error message: ${out.stderr}`)
core.setFailed(Error(`Couldn't find omc. Exit code: ${out.exitCode}`))
}

// Update PATH
const pathToOmc = '/Users/runner/opt/omc/bin'
core.info(`Adding ${pathToOmc} to PATH`)
core.addPath(pathToOmc)

// Clean up
fs.rmSync('tmp', {recursive: true})
}

/**
* Install OpenModelica packages (omc, OMSimulator)
*
Expand All @@ -254,6 +327,9 @@ export async function installOM(
case 'win32':
await winInstallOM(version, architectureInput)
break
case 'darwin':
await macInstallOM(version)
break
default:
throw new Error(`Platform ${osPlat} is not supported`)
}
Expand Down
30 changes: 24 additions & 6 deletions src/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"version": "stable",
"type": "stable",
"arch": "64",
"address": "https://build.openmodelica.org/omc/builds/windows/releases/1.21/0/64bit/OpenModelica-v1.21.0-64bit.exe"
"address": "https://build.openmodelica.org/omc/builds/windows/releases/1.22/0/64bit/OpenModelica-v1.22.0-64bit.exe"
},
{
"version": "release",
"type": "release",
"arch": "64",
"address": "https://build.openmodelica.org/omc/builds/windows/releases/1.21/0/64bit/OpenModelica-v1.21.0-64bit.exe"
"address": "https://build.openmodelica.org/omc/builds/windows/releases/1.22/0/64bit/OpenModelica-v1.22.0-64bit.exe"
},
{
"version": "1.22.0",
Expand Down Expand Up @@ -259,10 +259,28 @@
],
"mac": [
{
"version": "1.22.0",
"type": "release",
"arch": "64",
"address": "https://build.openmodelica.org/omc/builds/windows/releases/1.22/0/64bit/OpenModelica-v1.22.0-64bit.exe"
"version": "nightly",
"type": "nightly",
"arch": "arm64",
"address": "https://build.openmodelica.org/mac/arm64/nightly/OpenModelica-latest.pkg"
},
{
"version": "1.22.0-dev-351",
"type": "nightly",
"arch": "arm64",
"address": "https://build.openmodelica.org/mac/arm64/nightly/OpenModelica-v1.22.0-dev-351-g208d90052b-cmake-Darwin.pkg"
},
{
"version": "1.22.0-dev-44",
"type": "nightly",
"arch": "arm64",
"address": "https://build.openmodelica.org/mac/arm64/nightly/OpenModelica-v1.22.0-dev-44-g01cf43c698-cmake-Darwin.pkg"
},
{
"version": "1.21.0-dev-399",
"type": "nightly",
"arch": "arm64",
"address": "https://build.openmodelica.org/mac/arm64/nightly/OpenModelica-v1.21.0-dev-399-g0273588b39-cmake-Darwin.pkg"
}
]
}