diff --git a/.github/workflows/package_compiler.yml b/.github/workflows/package_compiler.yml new file mode 100644 index 00000000000..54dce3b6383 --- /dev/null +++ b/.github/workflows/package_compiler.yml @@ -0,0 +1,41 @@ +name: Package Compiler +on: + push: + branches: + - master + - release-* + pull_request: + types: [opened, synchronize, reopened] +# needed to allow julia-actions/cache to delete old caches that it has created +permissions: + actions: write + contents: read +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - version: '1' # The latest point-release (Linux) + os: ubuntu-latest + arch: x64 + steps: + - uses: actions/checkout@v6 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v3 + - uses: julia-actions/julia-buildpkg@v1 + - shell: julia --color=yes --project=test/PackageCompiler/MyApp {0} + run: | + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + - shell: julia --color=yes --project=test/PackageCompiler {0} + run: | + using Pkg + Pkg.instantiate() + - run: julia --color=yes --project=test/PackageCompiler test/PackageCompiler/build_app.jl diff --git a/test/PackageCompiler/.gitignore b/test/PackageCompiler/.gitignore new file mode 100644 index 00000000000..378eac25d31 --- /dev/null +++ b/test/PackageCompiler/.gitignore @@ -0,0 +1 @@ +build diff --git a/test/PackageCompiler/MyApp/Project.toml b/test/PackageCompiler/MyApp/Project.toml new file mode 100644 index 00000000000..34317b14298 --- /dev/null +++ b/test/PackageCompiler/MyApp/Project.toml @@ -0,0 +1,12 @@ +name = "MyApp" +uuid = "4076af6c-e467-56ae-b986-b466b2749573" + +[deps] +HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" +Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" + +[compat] +HiGHS = "1" +Ipopt = "1" +JuMP = "1" diff --git a/test/PackageCompiler/MyApp/src/MyApp.jl b/test/PackageCompiler/MyApp/src/MyApp.jl new file mode 100644 index 00000000000..09a49067682 --- /dev/null +++ b/test/PackageCompiler/MyApp/src/MyApp.jl @@ -0,0 +1,53 @@ +# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +############################################################################# +# JuMP +# An algebraic modeling language for Julia +# See https://github.com/jump-dev/JuMP.jl +############################################################################# + +module MyApp + +using JuMP +import HiGHS +import Ipopt + +function run_highs_example() + capacity = 10.0 + profit = [5.0, 3.0, 2.0, 7.0, 4.0] + weight = [2.0, 8.0, 4.0, 2.0, 5.0] + model = Model(HiGHS.Optimizer) + @variable(model, x[1:length(weight)], Bin) + @constraint(model, weight' * x <= capacity) + @objective(model, Max, profit' * x) + optimize!(model) + assert_is_solved_and_feasible(model) + print(solution_summary(model)) + return +end + +function run_ipopt_example() + model = Model(Ipopt.Optimizer) + @variable(model, x) + @variable(model, y) + @objective(model, Min, (1 - x)^2 + 100 * (y - x^2)^2) + optimize!(model) + assert_is_solved_and_feasible(model) + print(solution_summary(model)) + return +end + +function julia_main()::Cint + solver = only(match(r"--solver=(.+)", only(ARGS))) + if solver == "ipopt" + run_ipopt_example() + else + @assert solver == "highs" + run_highs_example() + end + return 0 +end + +end diff --git a/test/PackageCompiler/Project.toml b/test/PackageCompiler/Project.toml new file mode 100644 index 00000000000..6179abce3d5 --- /dev/null +++ b/test/PackageCompiler/Project.toml @@ -0,0 +1,5 @@ +[deps] +PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" + +[compat] +PackageCompiler = "2" diff --git a/test/PackageCompiler/build_app.jl b/test/PackageCompiler/build_app.jl new file mode 100644 index 00000000000..8367e219bf4 --- /dev/null +++ b/test/PackageCompiler/build_app.jl @@ -0,0 +1,33 @@ +# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +############################################################################# +# JuMP +# An algebraic modeling language for Julia +# See https://github.com/jump-dev/JuMP.jl +############################################################################# + +using Test + +import PackageCompiler + +PackageCompiler.create_app( + joinpath(@__DIR__, "MyApp"), + joinpath(@__DIR__, "build"); + force = true, +) + +@testset "test --solver=ipopt" begin + app = joinpath(@__DIR__, "build", "bin", "MyApp") + output = sprint(io -> run(pipeline(`$app --solver=highs`; stdout = io))) + @test occursin("HiGHS", output) + @test occursin("OPTIMAL", output) +end + +@testset "test --solver=ipopt" begin + app = joinpath(@__DIR__, "build", "bin", "MyApp") + output = sprint(io -> run(pipeline(`$app --solver=ipopt`; stdout = io))) + @test occursin("Ipopt", output) + @test occursin("LOCALLY_SOLVED", output) +end