Skip to content
Open
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
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ jobs:
- run: task acceptance
env:
TEST_PATTERN: "TestMSIXStructure"
msi-acceptance-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
Comment thread
djgilcrease marked this conversation as resolved.
with:
go-version: stable
- uses: go-task/setup-task@01a4adf9db2d14c1de7a560f09170b6e0df736aa # v2.1.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: task setup
- run: task acceptance
env:
TEST_PATTERN: "TestMSIStructure"
windows-build-pkgs:
needs: [unit-tests]
runs-on: windows-latest
Expand Down Expand Up @@ -170,3 +184,18 @@ jobs:
Write-Error "Expected 'nfpm-msix-test-ok' but got '$output'"
exit 1
}
msi-windows-install:
needs: [unit-tests]
runs-on: windows-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
Comment thread
djgilcrease marked this conversation as resolved.
with:
go-version: stable
- uses: go-task/setup-task@01a4adf9db2d14c1de7a560f09170b6e0df736aa # v2.1.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build MSI package
run: task acceptance:windows:package:msi
- name: Install and verify MSI package
run: task acceptance:windows:install:msi
14 changes: 14 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ tasks:
cmds:
- pwsh -ExecutionPolicy Bypass -File testdata/acceptance/install-msix.ps1

acceptance:windows:package:msi:
desc: Build MSI package for Windows install testing
platforms: [windows]
cmds:
- mkdir -p ./dist
- go build -o ./dist/testapp.exe ./testdata/acceptance/testapp/
- go run ./cmd/nfpm/... pkg -f ./testdata/acceptance/msi.install.yaml -p msi -t ./dist/foo.msi

Comment thread
djgilcrease marked this conversation as resolved.
acceptance:windows:install:msi:
desc: Install and verify MSI package on Windows
platforms: [windows]
cmds:
- pwsh -ExecutionPolicy Bypass -File testdata/acceptance/install-msi.ps1

acceptance:pull:
desc: Pull acceptance test images
vars:
Expand Down
52 changes: 52 additions & 0 deletions acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
_ "github.com/goreleaser/nfpm/v2/arch"
_ "github.com/goreleaser/nfpm/v2/deb"
_ "github.com/goreleaser/nfpm/v2/ipk"
_ "github.com/goreleaser/nfpm/v2/msi"
_ "github.com/goreleaser/nfpm/v2/msix"
_ "github.com/goreleaser/nfpm/v2/rpm"
"github.com/stretchr/testify/require"
gomsi "go.digitalxero.dev/go-msi"
)

// nolint: gochecknoglobals
Expand Down Expand Up @@ -473,3 +475,53 @@ func TestMSIXStructure(t *testing.T) {
})
}
}

func TestMSIStructure(t *testing.T) {
t.Parallel()
for _, arch := range []string{"amd64", "arm64"} {
arch := arch
t.Run(arch, func(t *testing.T) {
t.Parallel()

configFile := "./testdata/acceptance/msi.basic.yaml"
envFunc := func(s string) string {
switch s {
case "BUILD_ARCH":
return arch
case "SEMVER":
return "v1.0.0-0.1.b1+git.abcdefgh"
default:
return os.Getenv(s)
}
}

config, err := nfpm.ParseFileWithEnvMapping(configFile, envFunc)
require.NoError(t, err)

info, err := config.Get("msi")
require.NoError(t, err)
require.NoError(t, nfpm.Validate(info))

pkg, err := nfpm.Get("msi")
require.NoError(t, err)

var buf bytes.Buffer
require.NoError(t, pkg.Package(nfpm.WithDefaults(info), &buf))

// An MSI is an OLE Compound File (CFB) container.
cfbMagic := []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}
require.True(t, bytes.HasPrefix(buf.Bytes(), cfbMagic), "output must be a CFB container")

// The package must pass ICE validation with no error-severity findings.
v, err := gomsi.NewValidator().WithAllICEs().Build()
require.NoError(t, err)
findings, err := v.Validate(bytes.NewReader(buf.Bytes()))
require.NoError(t, err)
for _, f := range findings {
if f.Severity() == gomsi.SeverityError {
t.Errorf("ICE error finding %s: %s", f.ICE(), f.Message())
}
}
})
}
}
8 changes: 6 additions & 2 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,14 @@ func sortedParents(dst string) []string {
paths := []string{}
base := strings.Trim(dst, "/")
for {
base = filepath.Dir(base)
if base == "." {
parent := filepath.Dir(base)
// Stop at the filesystem root ("." for relative paths) and at volume
// roots such as Windows "C:/", where filepath.Dir stops making progress
// and would otherwise loop forever (e.g. for drive-letter destinations).
if parent == "." || parent == base {
break
}
base = parent
paths = append(paths, ToNixPath(base))
}

Expand Down
28 changes: 28 additions & 0 deletions files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,34 @@ func TestImplicitDirectories(t *testing.T) {
require.Equal(t, expected, withoutFileInfo(results))
}

// TestDriveLetterDestinationTerminates guards against the parent-directory walk
// looping forever on a Windows drive-letter destination (filepath.Dir gets
// stuck at the volume root), which previously caused an out-of-memory crash.
func TestDriveLetterDestinationTerminates(t *testing.T) {
results, err := files.PrepareForPackager(
files.Contents{
{
Source: "./testdata/globtest/a.txt",
Destination: "C:/Program Files/App/a.txt",
},
},
0,
"",
false,
mtime,
)
require.NoError(t, err)

var file *files.Content
for _, c := range results {
if c.Type == files.TypeFile {
file = c
}
}
require.NotNil(t, file)
require.Equal(t, "testdata/globtest/a.txt", file.Source)
}

func TestRelevantFiles(t *testing.T) {
contents := files.Contents{
{
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ require (
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/ulikunitz/xz v0.5.15
go.digitalxero.dev/go-msi v0.2.0
go.digitalxero.dev/go-msix v0.3.1
go.yaml.in/yaml/v3 v3.0.4
software.sslmate.com/src/go-pkcs12 v0.7.1
)

require (
Expand All @@ -32,6 +34,7 @@ require (
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/abemedia/go-cfb v0.2.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/cavaliergopher/cpio v1.0.1 // indirect
Expand Down Expand Up @@ -94,5 +97,4 @@ require (
golang.org/x/text v0.37.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
software.sslmate.com/src/go-pkcs12 v0.7.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ek
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
github.com/ProtonMail/gopenpgp/v2 v2.7.1 h1:Awsg7MPc2gD3I7IFac2qE3Gdls0lZW8SzrFZ3k1oz0s=
github.com/ProtonMail/gopenpgp/v2 v2.7.1/go.mod h1:/BU5gfAVwqyd8EfC3Eu7zmuhwYQpKs+cGD8M//iiaxs=
github.com/abemedia/go-cfb v0.2.0 h1:amLvu7/DX65XtcmMuc0an/t09W36gMOrnYwLxGGmwX8=
github.com/abemedia/go-cfb v0.2.0/go.mod h1:ytSRuNKf2VMDQDs8TSZ/VmkVfS4giAdc4xl5XOnpKKA=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down Expand Up @@ -205,6 +207,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJu
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.com/digitalxero/go-conventional-commit v1.0.7 h1:8/dO6WWG+98PMhlZowt/YjuiKhqhGlOCwlIV8SqqGh8=
gitlab.com/digitalxero/go-conventional-commit v1.0.7/go.mod h1:05Xc2BFsSyC5tKhK0y+P3bs0AwUtNuTp+mTpbCU/DZ0=
go.digitalxero.dev/go-msi v0.2.0 h1:ch1gOlRkwv+AvqmbEmXI0zcZSFGOSbP13qbRn41k720=
go.digitalxero.dev/go-msi v0.2.0/go.mod h1:KmoYF1YR3JjpaZmRmiZunTpQ4fKJsnYGgFmTN6gqlgE=
go.digitalxero.dev/go-msix v0.3.1 h1:V5E8PuFkA3Fr3VFYX6pTUutriogYC9sgxIWhzf9sSKw=
go.digitalxero.dev/go-msix v0.3.1/go.mod h1:QbUpFs0AUd1zk7e9fy17suiqEAF90TR3jZY+LCI2K+c=
go.mozilla.org/pkcs7 v0.9.0 h1:yM4/HS9dYv7ri2biPtxt8ikvB37a980dg69/pKmS+eI=
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/goreleaser/nfpm/v2/arch" // archlinux packager
_ "github.com/goreleaser/nfpm/v2/deb" // deb packager
_ "github.com/goreleaser/nfpm/v2/ipk" // ipk packager
_ "github.com/goreleaser/nfpm/v2/msi" // msi packager
_ "github.com/goreleaser/nfpm/v2/msix" // msix packager
_ "github.com/goreleaser/nfpm/v2/rpm" // rpm packager
"github.com/spf13/cobra"
Expand Down
Loading
Loading