Skip to content

Commit

Permalink
Updating to shared build.sh and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Dec 25, 2023
1 parent dc8e866 commit a4a58e2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/announce.yml
Expand Up @@ -6,7 +6,7 @@ env:
APP: xo
VER: ${{ github.ref_name }}
REPO: ${{ github.repository }}
HOMEBREW_USER: Kenneth Shaw
HOMEBREW_NAME: Kenneth Shaw
HOMEBREW_EMAIL: kenshaw@gmail.com
HOMEBREW_REPO: https://kenshaw:${{ secrets.HOMEBREW_TOKEN }}@github.com/xo/homebrew-xo.git
AUR_NAME: Kenneth Shaw
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
export SHA256SUM=$(sha256sum $WORKDIR/archive.tar.gz|awk '{print $1}')
export CHANGELOG=$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/$REPO/releases/tags/$VER|jq .body|sed -e 's/\\r//g')
git clone $HOMEBREW_REPO $REPO_PATH
git -C $REPO_PATH config user.name "$HOMEBREW_USER"
git -C $REPO_PATH config user.name "$HOMEBREW_NAME"
git -C $REPO_PATH config user.email "$HOMEBREW_EMAIL"
sed -i "s%url \".*$%url \"https://github.com/$REPO/archive/$VER.tar.gz\"%" $REPO_PATH/Formula/$APP.rb
sed -i "s/sha256 \".*$/sha256 \"$SHA256SUM\"/" $REPO_PATH/Formula/$APP.rb
Expand Down
76 changes: 41 additions & 35 deletions .github/workflows/release.yml
Expand Up @@ -38,17 +38,15 @@ jobs:
- name: Build ${{ matrix.arch }}
run: |
./build.sh -v $VER -a ${{ matrix.arch }}
file build/linux/*/*/$APP
- name: Build ${{ matrix.arch }} (static)
if: matrix.arch != 'arm'
run: |
./build.sh -v $VER -a ${{ matrix.arch }} -s
file build/linux/*/*/${APP}_static
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-linux-${{ matrix.arch }}
path: build/linux/**/*.tar.bz2
path: build/linux/**/*
if-no-files-found: error

build_for_macos:
Expand All @@ -59,7 +57,8 @@ jobs:
arch: [amd64, arm64]
steps:
- name: Install build dependencies
run: brew install coreutils
run: |
brew install coreutils gnu-tar
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
Expand All @@ -69,12 +68,11 @@ jobs:
- name: Build ${{ matrix.arch }}
run: |
./build.sh -v $VER -a ${{ matrix.arch }}
file build/darwin/*/*/$APP
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-darwin-${{ matrix.arch }}
path: build/darwin/**/*.tar.bz2
path: build/darwin/**/*
if-no-files-found: error

build_for_macos_universal:
Expand All @@ -83,65 +81,73 @@ jobs:
- build_for_macos
runs-on: macos-latest
steps:
- name: Install build dependencies
run: |
brew install coreutils gnu-tar
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Build universal
run: |
export WORKDIR=$PWD/build/darwin/universal/$VER
mkdir -p $WORKDIR
tar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR $APP
tar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR LICENSE
gtar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR $APP
gtar -jxvf dist-darwin-amd64/*/*/*.tar.bz2 -C $WORKDIR LICENSE
mv $WORKDIR/$APP $WORKDIR/$APP-amd64
tar -jxvf dist-darwin-arm64/*/*/*.tar.bz2 -C $WORKDIR $APP
gtar -jxvf dist-darwin-arm64/*/*/*.tar.bz2 -C $WORKDIR $APP
mv $WORKDIR/$APP $WORKDIR/$APP-arm64
file $WORKDIR/$APP-{amd64,arm64}
lipo -create -output $WORKDIR/$APP $WORKDIR/$APP-amd64 $WORKDIR/$APP-arm64
chmod +x $WORKDIR/$APP
file $WORKDIR/$APP
rm $WORKDIR/$APP-{amd64,arm64}
tar -C $WORKDIR -cjf $WORKDIR/$APP-${VER#v}-darwin-universal.tar.bz2 $APP LICENSE
ls -alh $WORKDIR/*.tar.bz2
sudo /usr/sbin/purge
gtar -C $WORKDIR -cjf $WORKDIR/$APP-${VER#v}-darwin-universal.tar.bz2 $APP LICENSE
ls -alh $WORKDIR/*
sha256sum $WORKDIR/*
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-darwin-universal
path: build/darwin/**/*.tar.bz2
path: build/darwin/**/*
if-no-files-found: error

# build_for_windows:
# name: Build for Windows
# runs-on: windows-latest
# steps:
# - name: Install build dependencies
# run: choco install zip
# - name: Checkout
# uses: actions/checkout@v3
# - name: Setup Go
# uses: actions/setup-go@v4
# with:
# go-version: ${{ env.GO_VERSION }}
# - name: Build amd64
# shell: bash
# run: ./build.sh -v $VER
# - name: Archive artifacts
# uses: actions/upload-artifact@v3
# with:
# name: dist-windows
# path: build/windows/**/*.zip
# if-no-files-found: error
build_for_windows:
name: Build for Windows
runs-on: windows-latest
steps:
- name: Install build dependencies
run: choco install zip
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build amd64
shell: bash
run: |
./build.sh -v $VER
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-windows
path: build/windows/**/*
if-no-files-found: error

release:
name: Draft Release
needs:
- build_for_linux
- build_for_macos
- build_for_macos_universal
# - build_for_windows
- build_for_windows
runs-on: ubuntu-latest
steps:
- name: Download artifacts
Expand All @@ -154,5 +160,5 @@ jobs:
draft: true
generate_release_notes: true
files: |
dist-*/*/*/*.bz2
dist-*/*/*/*.tar.bz2
dist-*/*/*/*.zip
45 changes: 30 additions & 15 deletions build.sh
Expand Up @@ -56,6 +56,7 @@ VER="${VER#v}"
BUILD=$SRC/build
DIR=$BUILD/$PLATFORM/$ARCH/$VER

TAR=tar
EXT=tar.bz2
BIN=$DIR/$NAME

Expand All @@ -64,6 +65,9 @@ case $PLATFORM in
EXT=zip
BIN=$BIN.exe
;;
darwin)
TAR=gtar
;;
esac
OUT=$DIR/$NAME-$VER-$PLATFORM-$ARCH.$EXT

Expand Down Expand Up @@ -140,12 +144,6 @@ fi
TAGS="${TAGS[@]}"
LDFLAGS="${LDFLAGS[@]}"

log() {
cat - | while read -r message; do
echo "$1$message"
done
}

echo "APP: $NAME/${VER} ($PLATFORM/$ARCH)"
if [ "$STATIC" = "1" ]; then
echo "STATIC: yes"
Expand Down Expand Up @@ -184,12 +182,28 @@ fi
-tags="$TAGS" \
-trimpath \
$OUTPUT
) 2>&1 | log ' '
)

if [[ "$INSTALL" == "1" || "$BUILDONLY" == "1" ]]; then
exit
fi

(set -x;
file $BIN
)
if [[ "$PLATFORM" != "windows" ]]; then
(set -x;
chmod +x $BIN
)
fi

# purge disk cache
if [[ "$PLATFORM" == "darwin" && "$CI" == "true" ]]; then
(set -x;
sudo /usr/sbin/purge
)
fi

built_ver() {
if [[ "$PLATFORM" == "linux" && "$ARCH" != "$GOARCH" ]]; then
EXTRA=
Expand Down Expand Up @@ -220,19 +234,20 @@ fi
# pack
cp $SRC/LICENSE $DIR
case $EXT in
tar.bz2)
tar -C $DIR -cjf $OUT $(basename $BIN) LICENSE
;;
zip)
zip $OUT -j $BIN LICENSE
;;
tar.bz2) $TAR -C $DIR -cjf $OUT $(basename $BIN) LICENSE ;;
zip) zip $OUT -j $BIN LICENSE ;;
esac

# report
echo "PACKED: $OUT ($(du -sh $OUT|awk '{print $1}'))"

case $EXT in
tar.bz2) tar -jvtf $OUT ;;
zip) unzip -l $OUT ;;
tar.bz2) (set -x; $TAR -jvtf $OUT) ;;
zip) (set -x; unzip -l $OUT) ;;
esac

(set -x;
sha256sum $DIR/*
)

popd &> /dev/null

0 comments on commit a4a58e2

Please sign in to comment.