From ee6a32642e8d2409de145aafb5d92a64a17698fe Mon Sep 17 00:00:00 2001 From: Oscar Reimer Date: Thu, 28 Nov 2024 10:06:00 +0100 Subject: [PATCH] Drop debug flags from release binaries and compress them --- .github/workflows/release.yml | 173 +++++++++++++++-------------- .goreleaser.yml | 24 +++- scripts/fetch_supported_formats.sh | 1 - scripts/install.sh | 2 +- 4 files changed, 113 insertions(+), 87 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae089174..1b34314d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,8 +2,8 @@ name: Release on: push: - tags: - - 'v*' +# tags: +# - 'v*' permissions: contents: write @@ -111,6 +111,11 @@ jobs: - run: git fetch --force --tags + - name: Install UPX + uses: crazy-max/ghaction-upx@v3 + with: + install-only: true + - uses: actions/setup-go@v5 with: go-version: '>=1.20' @@ -137,85 +142,85 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} - - name: Download JAR archives - uses: actions/download-artifact@v4 - - - name: Add archives with JARs to release - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') - with: - tag_name: ${{ github.ref_name }} - files: | - soot-wrapper-rev-hash.txt/soot-wrapper-rev-hash.txt - soot-wrapper-11.zip/soot-wrapper-11.zip - soot-wrapper-17.zip/soot-wrapper-17.zip - soot-wrapper-21.zip/soot-wrapper-21.zip - - major-release: - runs-on: ubuntu-latest - needs: goreleaser - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Update major release tag - id: major-tag - run: | - # returns v1, v2, etc, everything to the left of the leftmost dot. - MAJOR_VERSION="${GITHUB_REF_NAME%%.*}" - MAJOR_TAG="release-${MAJOR_VERSION}" - echo "MAJOR_VERSION=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT" - echo "MAJOR_TAG=${MAJOR_TAG}" >> "$GITHUB_OUTPUT" - git tag -f "${MAJOR_TAG}" - git push -f origin "${MAJOR_TAG}" - - name: Fetch assets from actual release - env: - MAJOR_TAG: ${{ steps.major-tag.outputs.MAJOR_TAG }} - GH_TOKEN: ${{ github.token }} - run: | - gh release download --pattern="cli_*.tar.gz" "${GITHUB_REF_NAME}" - - name: Create or update release - uses: softprops/action-gh-release@v2 - with: - body: Latest release for the ${{ steps.major-tag.outputs.MAJOR_VERSION }} branch of the CLI - name: Latest ${{ steps.major-tag.outputs.MAJOR_VERSION }} CLI - tag_name: ${{ steps.major-tag.outputs.MAJOR_TAG }} - fail_on_unmatched_files: true - make_latest: false - files: "cli_*.tar.gz" - - - aur: - runs-on: ubuntu-latest - needs: goreleaser - container: - image: archlinux/archlinux:base-devel - steps: - - name: Prepare Arch Linux container - run: | - pacman -Syu --noconfirm git go openssh pacman-contrib - useradd -m aur - - # Setup SSH access to aur.archlinux.org - - uses: webfactory/ssh-agent@v0.9.0 - with: - ssh-private-key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} - - # Now actually clone AUR repo, and update to new version - - name: Build package and update AUR - run: | - export NEW_VERSION="${GITHUB_REF_NAME#v}" - sudo -u aur sh -c "mkdir -p /home/aur/.ssh && chmod 700 /home/aur/.ssh && touch /home/aur/.ssh/known_hosts && chmod 600 /home/aur/.ssh/known_hosts" - sudo -u aur sh -c "echo 'aur.archlinux.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuBKrPzbawxA/k2g6NcyV5jmqwJ2s+zpgZGZ7tpLIcN' >> /home/aur/.ssh/known_hosts" - mkdir -p /root/.ssh && chmod 700 /root/.ssh && cp /home/aur/.ssh/known_hosts /root/.ssh/known_hosts && chown root: /root/.ssh/known_hosts - # clone repo - git clone aur@aur.archlinux.org:debricked.git debricked - chown -R aur debricked/ - cd debricked/ - sudo -u aur NEW_VERSION="${NEW_VERSION}" make update_version - sudo -u aur make package - sudo -u aur git diff - sudo -u aur git config user.email noreply@debricked.com - sudo -u aur git config user.name "Debricked build bot" - git config --global --add safe.directory "$PWD" - make push +# - name: Download JAR archives +# uses: actions/download-artifact@v4 +# +# - name: Add archives with JARs to release +# uses: softprops/action-gh-release@v2 +# if: startsWith(github.ref, 'refs/tags/') +# with: +# tag_name: ${{ github.ref_name }} +# files: | +# soot-wrapper-rev-hash.txt/soot-wrapper-rev-hash.txt +# soot-wrapper-11.zip/soot-wrapper-11.zip +# soot-wrapper-17.zip/soot-wrapper-17.zip +# soot-wrapper-21.zip/soot-wrapper-21.zip +# +# major-release: +# runs-on: ubuntu-latest +# needs: goreleaser +# steps: +# - uses: actions/checkout@v4 +# with: +# fetch-depth: 0 +# - name: Update major release tag +# id: major-tag +# run: | +# # returns v1, v2, etc, everything to the left of the leftmost dot. +# MAJOR_VERSION="${GITHUB_REF_NAME%%.*}" +# MAJOR_TAG="release-${MAJOR_VERSION}" +# echo "MAJOR_VERSION=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT" +# echo "MAJOR_TAG=${MAJOR_TAG}" >> "$GITHUB_OUTPUT" +# git tag -f "${MAJOR_TAG}" +# git push -f origin "${MAJOR_TAG}" +# - name: Fetch assets from actual release +# env: +# MAJOR_TAG: ${{ steps.major-tag.outputs.MAJOR_TAG }} +# GH_TOKEN: ${{ github.token }} +# run: | +# gh release download --pattern="cli_*.tar.gz" "${GITHUB_REF_NAME}" +# - name: Create or update release +# uses: softprops/action-gh-release@v2 +# with: +# body: Latest release for the ${{ steps.major-tag.outputs.MAJOR_VERSION }} branch of the CLI +# name: Latest ${{ steps.major-tag.outputs.MAJOR_VERSION }} CLI +# tag_name: ${{ steps.major-tag.outputs.MAJOR_TAG }} +# fail_on_unmatched_files: true +# make_latest: false +# files: "cli_*.tar.gz" +# +# +# aur: +# runs-on: ubuntu-latest +# needs: goreleaser +# container: +# image: archlinux/archlinux:base-devel +# steps: +# - name: Prepare Arch Linux container +# run: | +# pacman -Syu --noconfirm git go openssh pacman-contrib +# useradd -m aur +# +# # Setup SSH access to aur.archlinux.org +# - uses: webfactory/ssh-agent@v0.9.0 +# with: +# ssh-private-key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} +# +# # Now actually clone AUR repo, and update to new version +# - name: Build package and update AUR +# run: | +# export NEW_VERSION="${GITHUB_REF_NAME#v}" +# sudo -u aur sh -c "mkdir -p /home/aur/.ssh && chmod 700 /home/aur/.ssh && touch /home/aur/.ssh/known_hosts && chmod 600 /home/aur/.ssh/known_hosts" +# sudo -u aur sh -c "echo 'aur.archlinux.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuBKrPzbawxA/k2g6NcyV5jmqwJ2s+zpgZGZ7tpLIcN' >> /home/aur/.ssh/known_hosts" +# mkdir -p /root/.ssh && chmod 700 /root/.ssh && cp /home/aur/.ssh/known_hosts /root/.ssh/known_hosts && chown root: /root/.ssh/known_hosts +# # clone repo +# git clone aur@aur.archlinux.org:debricked.git debricked +# chown -R aur debricked/ +# cd debricked/ +# sudo -u aur NEW_VERSION="${NEW_VERSION}" make update_version +# sudo -u aur make package +# sudo -u aur git diff +# sudo -u aur git config user.email noreply@debricked.com +# sudo -u aur git config user.name "Debricked build bot" +# git config --global --add safe.directory "$PWD" +# make push diff --git a/.goreleaser.yml b/.goreleaser.yml index f75393bd..79711482 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,7 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json # Documentation at https://goreleaser.com +version: 2 + before: hooks: - go mod tidy @@ -13,7 +16,7 @@ builds: - windows - darwin ldflags: - - -X main.version={{.Version}} + - -s -w -X main.version={{.Version}} archives: - name_template: >- @@ -44,3 +47,22 @@ nfpms: - deb - rpm - apk + +upx: + - # Whether to enable it or not. + # + # Templates: allowed. + enabled: true + + # Filter by GOOS. + goos: [ linux, windows ] + + # Compress argument. + # Valid options are from '1' (faster) to '9' (better), and 'best'. + compress: '6' + + # Whether to try LZMA (slower). + lzma: false + + # Whether to try all methods and filters (slow). + brute: false diff --git a/scripts/fetch_supported_formats.sh b/scripts/fetch_supported_formats.sh index e2e070e1..5c8cbdb4 100755 --- a/scripts/fetch_supported_formats.sh +++ b/scripts/fetch_supported_formats.sh @@ -3,4 +3,3 @@ cd "${0%/*}/../" mkdir -p internal/file/embedded curl -fsSLo internal/file/embedded/supported_formats.json https://debricked.com/api/1.0/open/files/supported-formats -ls -l internal/file/embedded/ diff --git a/scripts/install.sh b/scripts/install.sh index bec535d2..9d878845 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -5,7 +5,7 @@ then echo -e "Failed to find git, thus also the version. Version will be set to v0.0.0" fi version=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match) -ldFlags="-X main.version=${version}" +ldFlags="-s -w -X main.version=${version}" go install -ldflags "${ldFlags}" ./cmd/debricked go generate -v -x ./cmd/debricked go build -ldflags "${ldFlags}" ./cmd/debricked