Skip to content

Commit 1bbabf5

Browse files
authored
Add a CI test for PackageCompiler.jl (#4135)
1 parent a43fe85 commit 1bbabf5

6 files changed

Lines changed: 145 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Package Compiler
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
# needed to allow julia-actions/cache to delete old caches that it has created
10+
permissions:
11+
actions: write
12+
contents: read
13+
jobs:
14+
test:
15+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- version: '1' # The latest point-release (Linux)
22+
os: ubuntu-latest
23+
arch: x64
24+
steps:
25+
- uses: actions/checkout@v6
26+
- uses: julia-actions/setup-julia@v2
27+
with:
28+
version: ${{ matrix.version }}
29+
arch: ${{ matrix.arch }}
30+
- uses: julia-actions/cache@v3
31+
- uses: julia-actions/julia-buildpkg@v1
32+
- shell: julia --color=yes --project=test/PackageCompiler/MyApp {0}
33+
run: |
34+
using Pkg
35+
Pkg.develop(PackageSpec(path=pwd()))
36+
Pkg.instantiate()
37+
- shell: julia --color=yes --project=test/PackageCompiler {0}
38+
run: |
39+
using Pkg
40+
Pkg.instantiate()
41+
- run: julia --color=yes --project=test/PackageCompiler test/PackageCompiler/build_app.jl

test/PackageCompiler/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "MyApp"
2+
uuid = "4076af6c-e467-56ae-b986-b466b2749573"
3+
4+
[deps]
5+
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
6+
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
7+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
8+
9+
[compat]
10+
HiGHS = "1"
11+
Ipopt = "1"
12+
JuMP = "1"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
#############################################################################
6+
# JuMP
7+
# An algebraic modeling language for Julia
8+
# See https://github.com/jump-dev/JuMP.jl
9+
#############################################################################
10+
11+
module MyApp
12+
13+
using JuMP
14+
import HiGHS
15+
import Ipopt
16+
17+
function run_highs_example()
18+
capacity = 10.0
19+
profit = [5.0, 3.0, 2.0, 7.0, 4.0]
20+
weight = [2.0, 8.0, 4.0, 2.0, 5.0]
21+
model = Model(HiGHS.Optimizer)
22+
@variable(model, x[1:length(weight)], Bin)
23+
@constraint(model, weight' * x <= capacity)
24+
@objective(model, Max, profit' * x)
25+
optimize!(model)
26+
assert_is_solved_and_feasible(model)
27+
print(solution_summary(model))
28+
return
29+
end
30+
31+
function run_ipopt_example()
32+
model = Model(Ipopt.Optimizer)
33+
@variable(model, x)
34+
@variable(model, y)
35+
@objective(model, Min, (1 - x)^2 + 100 * (y - x^2)^2)
36+
optimize!(model)
37+
assert_is_solved_and_feasible(model)
38+
print(solution_summary(model))
39+
return
40+
end
41+
42+
function julia_main()::Cint
43+
solver = only(match(r"--solver=(.+)", only(ARGS)))
44+
if solver == "ipopt"
45+
run_ipopt_example()
46+
else
47+
@assert solver == "highs"
48+
run_highs_example()
49+
end
50+
return 0
51+
end
52+
53+
end

test/PackageCompiler/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
3+
4+
[compat]
5+
PackageCompiler = "2"

test/PackageCompiler/build_app.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
#############################################################################
6+
# JuMP
7+
# An algebraic modeling language for Julia
8+
# See https://github.com/jump-dev/JuMP.jl
9+
#############################################################################
10+
11+
using Test
12+
13+
import PackageCompiler
14+
15+
PackageCompiler.create_app(
16+
joinpath(@__DIR__, "MyApp"),
17+
joinpath(@__DIR__, "build");
18+
force = true,
19+
)
20+
21+
@testset "test --solver=ipopt" begin
22+
app = joinpath(@__DIR__, "build", "bin", "MyApp")
23+
output = sprint(io -> run(pipeline(`$app --solver=highs`; stdout = io)))
24+
@test occursin("HiGHS", output)
25+
@test occursin("OPTIMAL", output)
26+
end
27+
28+
@testset "test --solver=ipopt" begin
29+
app = joinpath(@__DIR__, "build", "bin", "MyApp")
30+
output = sprint(io -> run(pipeline(`$app --solver=ipopt`; stdout = io)))
31+
@test occursin("Ipopt", output)
32+
@test occursin("LOCALLY_SOLVED", output)
33+
end

0 commit comments

Comments
 (0)