Repository: zyedidia/micro
File: tools/cross-compile.sh (Shell)

Code before:
cd ..

mkdir -p binaries
mkdir -p micro-$1

cp LICENSE micro-$1
cp README.md micro-$1
cp LICENSE-THIRD-PARTY micro-$1
cp assets/packaging/micro.1 micro-$1
cp assets/packaging/micro.desktop micro-$1
cp assets/micro-logo-mark.svg micro-$1/micro.svg

HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"

# Mac
echo "OSX 64"
GOOS=darwin GOARCH=amd64 make build
mv micro micro-$1
tar -czf micro-$1-osx.tar.gz micro-$1
mv micro-$1-osx.tar.gz binaries

# Mac ARM64
echo "MacOS ARM64"
GOOS=darwin GOARCH=arm64 make build
mv micro micro-$1
tar -czf micro-$1-macos-arm64.tar.gz micro-$1
mv micro-$1-macos-arm64.tar.gz binaries

# Linux
echo "Linux 64"
GOOS=linux GOARCH=amd64 make build
./tools/package-deb.sh $1
mv micro-$1-amd64.deb binaries

mv micro micro-$1
tar -czf micro-$1-linux64.tar.gz micro-$1
mv micro-$1-linux64.tar.gz binaries

echo "Linux 64 fully static"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build
mv micro micro-$1
tar -czf micro-$1-linux64-static.tar.gz micro-$1
mv micro-$1-linux64-static.tar.gz binaries

echo "Linux 32"
GOOS=linux GOARCH=386 make build
mv micro micro-$1

Review comment (suggestion):
I realized using `$VERSION` within the archive resp. asset name is counterproductive when used for the `nightly` upload, because the `softprops/action-gh-release` will only delete and update assets with the same name present.
Having an updated from e.g. `2.0.14-dev.243` -> `2.0.14-dev.244` -> `2.0.14-dev.245` fills the `nightly` "release" with all of the assets.
The correction of the nightlies currently needs manual adjustment to be cleaned up.

So I suggest to slightly adapt the `tools/cross-compile.sh` again to allow a custom string as archive version, if given otherwise use the parsed version. The `nightly` action then can use `tools/cross-compile.sh nightly` to provide fixed asset names, which will be properly handled by the `softprops/action-gh-release` action.
I wasn't able to find an option cleaning up all the assets present at one release.

Side note:
The SHA sum created for the nightlies is only valid till the next build will be done for the same version.

PR: #3418

Code after:
#!/bin/sh

set -e

HASH="$(git rev-parse --short HEAD)"
VERSION="$(go run tools/build-version.go)"
DATE="$(go run tools/build-date.go)"
ADDITIONAL_GO_LINKER_FLAGS="$(go run tools/info-plist.go $VERSION)"

mkdir -p binaries
mkdir -p micro-$VERSION

cp LICENSE micro-$VERSION
cp README.md micro-$VERSION
cp LICENSE-THIRD-PARTY micro-$VERSION
cp assets/packaging/micro.1 micro-$VERSION
cp assets/packaging/micro.desktop micro-$VERSION
cp assets/micro-logo-mark.svg micro-$VERSION/micro.svg

create_artefact_generic()
{
	mv micro micro-$VERSION/
	tar -czf micro-$VERSION-$1.tgz micro-$VERSION
	sha256sum micro-$VERSION-$1.tgz > micro-$VERSION-$1.tgz.sha
	mv micro-$VERSION-$1.* binaries
	rm micro-$VERSION/micro
}

create_artefact_windows()
{
	mv micro.exe micro-$VERSION/
	zip -r -q -T micro-$VERSION-$1.zip micro-$VERSION
	sha256sum micro-$VERSION-$1.zip > micro-$VERSION-$1.zip.sha
	mv micro-$VERSION-$1.* binaries
	rm micro-$VERSION/micro.exe
}

# Mac
echo "OSX 64"
GOOS=darwin GOARCH=amd64 make build
create_artefact_generic "osx"

# Mac ARM64
echo "MacOS ARM64"
GOOS=darwin GOARCH=arm64 make build
create_artefact_generic "macos-arm64"

# Linux
echo "Linux 64"
GOOS=linux GOARCH=amd64 make build