From eb8890b7db2d2e542e6ce4f6ff43f1c1e51fdb12 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Sun, 16 Nov 2025 14:21:33 +0000 Subject: [PATCH] Make github action test different Docker image versions --- .github/workflows/test.yml | 32 +++++++++++++++++++++++++++++--- docker_test.go | 24 ++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d7e87e..4dbe4ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,8 +4,8 @@ on: [push, pull_request] jobs: - build: - name: test + test-non-docker: + name: test non-docker runs-on: ubuntu-latest strategy: matrix: @@ -28,4 +28,30 @@ jobs: uses: actions/checkout@v4 - name: Test package - run: go test -v ./... + run: go test -run ^(?!Docker).*$ -v ./... + + test-docker: + name: test docker + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ['1.23.x'] + typst-docker-image: + - 'ghcr.io/typst/typst:v0.12.0' + - 'ghcr.io/typst/typst:v0.13.0' + - 'ghcr.io/typst/typst:v0.13.1' + - 'ghcr.io/typst/typst:0.14.0' + + steps: + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Check out code + uses: actions/checkout@v4 + + - name: Test package + run: go test -run ^Docker.*$ -v ./... + env: + TYPST_DOCKER_IMAGE: ${{ matrix.typst-docker-image }} diff --git a/docker_test.go b/docker_test.go index b7b77b4..46a6b49 100644 --- a/docker_test.go +++ b/docker_test.go @@ -8,6 +8,7 @@ package typst_test import ( "bytes" "image" + "os" "path/filepath" "strconv" "testing" @@ -15,8 +16,16 @@ import ( "github.com/Dadido3/go-typst" ) +// Returns the TYPST_DOCKER_IMAGE environment variable. +// If that's not set, it will return an empty string, which makes the tests default to typst.DockerDefaultImage. +func typstDockerImage() string { + return os.Getenv("TYPST_DOCKER_IMAGE") +} + func TestDocker_VersionString(t *testing.T) { - caller := typst.Docker{} + caller := typst.Docker{ + Image: typstDockerImage(), + } _, err := caller.VersionString() if err != nil { @@ -25,7 +34,9 @@ func TestDocker_VersionString(t *testing.T) { } func TestDocker_Fonts(t *testing.T) { - caller := typst.Docker{} + caller := typst.Docker{ + Image: typstDockerImage(), + } result, err := caller.Fonts(nil) if err != nil { @@ -37,7 +48,9 @@ func TestDocker_Fonts(t *testing.T) { } func TestDocker_FontsWithOptions(t *testing.T) { - caller := typst.Docker{} + caller := typst.Docker{ + Image: typstDockerImage(), + } result, err := caller.Fonts(&typst.OptionsFonts{IgnoreSystemFonts: true}) if err != nil { @@ -53,7 +66,9 @@ func TestDocker_Compile(t *testing.T) { const inches = 1 const ppi = 144 - typstCaller := typst.Docker{} + typstCaller := typst.Docker{ + Image: typstDockerImage(), + } r := bytes.NewBufferString(`#set page(width: ` + strconv.FormatInt(inches, 10) + `in, height: ` + strconv.FormatInt(inches, 10) + `in, margin: (x: 1mm, y: 1mm)) = Test @@ -88,6 +103,7 @@ func TestDocker_Compile(t *testing.T) { // Test basic compile functionality with a given working directory. func TestDocker_CompileWithWorkingDir(t *testing.T) { typstCaller := typst.Docker{ + Image: typstDockerImage(), WorkingDirectory: filepath.Join(".", "test-files"), Volumes: []string{".:/markup"}, }