From a4a58e2e0cb05cf1c3e2d534941f077f67c177ad Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Mon, 25 Dec 2023 06:23:29 -0700 Subject: [PATCH] Updating to shared build.sh and workflows --- .github/workflows/announce.yml | 4 +- .github/workflows/release.yml | 76 ++++++++++++++++++---------------- build.sh | 45 +++++++++++++------- 3 files changed, 73 insertions(+), 52 deletions(-) diff --git a/.github/workflows/announce.yml b/.github/workflows/announce.yml index f3d4d347..f2a57708 100644 --- a/.github/workflows/announce.yml +++ b/.github/workflows/announce.yml @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ba086d7..0800ac73 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 @@ -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: @@ -83,6 +81,9 @@ 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 @@ -90,50 +91,55 @@ jobs: 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 @@ -141,7 +147,7 @@ jobs: - build_for_linux - build_for_macos - build_for_macos_universal -# - build_for_windows + - build_for_windows runs-on: ubuntu-latest steps: - name: Download artifacts @@ -154,5 +160,5 @@ jobs: draft: true generate_release_notes: true files: | - dist-*/*/*/*.bz2 + dist-*/*/*/*.tar.bz2 dist-*/*/*/*.zip diff --git a/build.sh b/build.sh index ca12d392..4d2c3e41 100755 --- a/build.sh +++ b/build.sh @@ -56,6 +56,7 @@ VER="${VER#v}" BUILD=$SRC/build DIR=$BUILD/$PLATFORM/$ARCH/$VER +TAR=tar EXT=tar.bz2 BIN=$DIR/$NAME @@ -64,6 +65,9 @@ case $PLATFORM in EXT=zip BIN=$BIN.exe ;; + darwin) + TAR=gtar + ;; esac OUT=$DIR/$NAME-$VER-$PLATFORM-$ARCH.$EXT @@ -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" @@ -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= @@ -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