Skip to content

Commit

Permalink
add test for non macos and fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui committed May 5, 2024
1 parent 2777509 commit 8a06e16
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
30 changes: 21 additions & 9 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ jobs:
test:
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: set up go
uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: lint
Expand All @@ -21,18 +19,32 @@ jobs:
sw_vers
make test
make test-large-file
test_on_non_macos:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: test
shell: bash
run: |
make test-on-non-macos
release:
runs-on: macos-latest
name: goreleaser
needs: [test]
needs: [test, test_on_non_macos]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: set up go
uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Run GoReleaser
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test:
test-large-file:
./test-large-file.sh

test-on-non-macos:
./test-on-non-macos.sh

cover:
go test -coverpkg=./... -coverprofile=cover.out ./...
go tool cover -html=cover.out -o cover.html
Expand Down
2 changes: 1 addition & 1 deletion pkg/lipo/thin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (l *Lipo) thin(perm os.FileMode, fatArch lmacho.FatArch) error {
}

// close before rename
if err := r.Close(); err != nil {
if err := out.Close(); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions test-large-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

set -eu

ARM64_FILE="./arm64"
AMD64_FILE="./amd64"
ARM64_FILE="./bin/arm64"
AMD64_FILE="./bin/amd64"
ARM64_LARGE_FILE=$ARM64_FILE.large
AMD64_LARGE_FILE=$AMD64_FILE.large

if [ ! -f $ARM64_FILE ]; then
echo creating ARM64_FILE
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o arm64 example/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o $ARM64_FILE example/main.go
fi

if [ ! -f $AMD64_FILE ]; then
echo creating AMD64_FILE
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o amd64 example/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $AMD64_FILE example/main.go
fi

if [ ! -f large-data ]; then
Expand Down
33 changes: 33 additions & 0 deletions test-on-non-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
# https://github.com/actions/runner-images/issues/7253

set -eu

FAT_BIN=./bin/fat
ARM64_BIN=./bin/arm64
AMD64_BIN=./bin/amd64
EXTRACT_BIN=./bin/extract
THIB_BIN=./bin/thin
LIPO_BIN=./bin/lipo

echo "====building lipo binary"
make
echo "====building base binaries"
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/amd64 example/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/arm64 example/main.go

echo "====creating fat"
$LIPO_BIN -output $FAT_BIN -create $ARM64_BIN $AMD64_BIN
$LIPO_BIN $FAT_BIN -verify_arch x86_64 arm64

echo "====extracting arm64"
$LIPO_BIN -extract arm64 -output $EXTRACT_BIN $FAT_BIN
$LIPO_BIN $EXTRACT_BIN -verify_arch arm64

echo "====thin"
$LIPO_BIN -thin arm64 -output $THIB_BIN $FAT_BIN
$LIPO_BIN $THIB_BIN -verify_arch arm64

echo "===replace TODO"

echo all test pass!

0 comments on commit 8a06e16

Please sign in to comment.