From 1f7411a002eb6a220a76d636e7e0cbd47abaaaab Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 13 May 2026 23:16:55 +0800 Subject: [PATCH] provide officially built macOS packages --- .../actions/build-macos-backend/action.yml | 55 ++++++++++++++++++ .../actions/build-macos-package/action.yml | 58 +++++++++++++++++++ .github/workflows/build-non-main-branch.yml | 33 +++++++++++ .github/workflows/build-release.yml | 35 +++++++++++ .github/workflows/build-snapshot.yml | 33 +++++++++++ build.sh | 8 ++- 6 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 .github/actions/build-macos-backend/action.yml create mode 100644 .github/actions/build-macos-package/action.yml diff --git a/.github/actions/build-macos-backend/action.yml b/.github/actions/build-macos-backend/action.yml new file mode 100644 index 00000000..d4eda93d --- /dev/null +++ b/.github/actions/build-macos-backend/action.yml @@ -0,0 +1,55 @@ +name: Build backend file for macOS + +inputs: + go-version: + required: false + description: "The Go version to use for building the macOS backend. The version should be in the format of 'x.y.z'." + default: "1.26.2" + release-build: + required: false + description: "Whether to build the macOS backend in release mode. If set to '1', the backend will be built in release mode. Otherwise, it will be built in development mode." + build-unix-time: + required: false + description: "The unix time to use for building the macOS backend. The value should be a string representing the unix time in seconds." + build-date: + required: false + description: "The date to use for building the macOS backend. The value should be a string representing the date in the format of 'YYYYMMDD'." + check-3rd-api: + required: false + description: "Whether to run integration tests that call third party APIs. If set to '1', the tests will be run. Otherwise, the tests will be skipped." + skip-tests: + required: false + description: "Whether to skip tests when building the macOS backend. If set to '1', the tests will be skipped. Otherwise, the tests will be run." + architecture: + required: true + description: "The name of the architecture to build the macOS package for." + backend-artifact-name-prefix: + required: true + description: "The prefix for the macOS backend artifact name." + +runs: + using: "composite" + steps: + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: ${{ inputs.go-version }} + + - name: Build backend for macOS-${{ inputs.architecture }} + shell: bash + env: + RELEASE_BUILD: "${{ inputs.release-build }}" + BUILD_PIPELINE: "1" + BUILD_UNIXTIME: "${{ inputs.build-unix-time }}" + BUILD_DATE: "${{ inputs.build-date }}" + CHECK_3RD_API: "${{ inputs.check-3rd-api }}" + SKIP_TESTS: "${{ inputs.skip-tests }}" + run: | + ./build.sh backend + + - name: Upload macOS-${{ inputs.architecture }} backend artifact + uses: actions/upload-artifact@v7 + with: + name: ${{ inputs.backend-artifact-name-prefix }}-macos-${{ inputs.architecture }} + path: ezbookkeeping + if-no-files-found: error diff --git a/.github/actions/build-macos-package/action.yml b/.github/actions/build-macos-package/action.yml new file mode 100644 index 00000000..f2895cdd --- /dev/null +++ b/.github/actions/build-macos-package/action.yml @@ -0,0 +1,58 @@ +name: Build packages for macOS + +inputs: + architecture: + required: true + description: "The name of the architecture to build the macOS package for." + package-file-name-prefix: + required: true + description: "The prefix for the macOS package file name." + backend-artifact-name-prefix: + required: true + description: "The prefix for the macOS backend artifact name." + +runs: + using: "composite" + steps: + - name: Download macOS-${{ inputs.architecture }} backend file + uses: actions/download-artifact@v8 + with: + name: ${{ inputs.backend-artifact-name-prefix }}-macos-${{ inputs.architecture }} + path: ${{ runner.temp }}/backend + + - name: Download linux-amd64 packaged files + uses: actions/download-artifact@v8 + with: + name: ${{ inputs.package-file-name-prefix }}-linux-amd64.tar.gz + path: ${{ runner.temp }}/package + + - name: Extract frontend files from linux-amd64 package + shell: bash + run: | + mkdir -p package + tar -xzf ${{ runner.temp }}/package/${{ inputs.package-file-name-prefix }}-linux-amd64.tar.gz -C package + + - name: Package macOS-${{ inputs.architecture }} package + shell: bash + run: | + mkdir -p ezbookkeeping + mkdir -p ezbookkeeping/data + mkdir -p ezbookkeeping/storage + mkdir -p ezbookkeeping/log + cp ${{ runner.temp }}/backend/ezbookkeeping ezbookkeeping/ + cp -R package/public ezbookkeeping/public + cp -R conf ezbookkeeping/conf + cp -R templates ezbookkeeping/templates + cp LICENSE ezbookkeeping/ + cd ezbookkeeping + chmod +x ezbookkeeping + tar -czf ${{ runner.temp }}/${{ inputs.package-file-name-prefix }}-macos-${{ inputs.architecture }}.tar.gz * + cd .. + rm -rf ezbookkeeping + + - name: Upload macOS-${{ inputs.architecture }} artifact + uses: actions/upload-artifact@v7 + with: + archive: false + path: ${{ runner.temp }}/${{ inputs.package-file-name-prefix }}-macos-${{ inputs.architecture }}.tar.gz + if-no-files-found: error diff --git a/.github/workflows/build-non-main-branch.yml b/.github/workflows/build-non-main-branch.yml index 3d514b80..4989f0c2 100644 --- a/.github/workflows/build-non-main-branch.yml +++ b/.github/workflows/build-non-main-branch.yml @@ -128,6 +128,23 @@ jobs: skip-tests: ${{ vars.SKIP_TESTS }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-macos-backend: + needs: + - setup + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-backend + with: + architecture: arm64 + build-unix-time: ${{ needs.setup.outputs.build-unix-time }} + build-date: ${{ needs.setup.outputs.build-date }} + check-3rd-api: ${{ vars.CHECK_3RD_API }} + skip-tests: ${{ vars.SKIP_TESTS }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-windows-package: needs: - setup @@ -142,3 +159,19 @@ jobs: with: package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + + build-macos-package: + needs: + - setup + - build-macos-backend + - build-linux-docker-and-package-x86 + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-package + with: + architecture: arm64 + package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 0b204808..22422f5d 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -162,6 +162,24 @@ jobs: skip-tests: ${{ vars.SKIP_TESTS }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-macos-backend: + needs: + - setup + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-backend + with: + architecture: arm64 + release-build: 1 + build-unix-time: ${{ needs.setup.outputs.build-unix-time }} + build-date: ${{ needs.setup.outputs.build-date }} + check-3rd-api: ${{ vars.CHECK_3RD_API }} + skip-tests: ${{ vars.SKIP_TESTS }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-windows-package: needs: - setup @@ -177,6 +195,22 @@ jobs: package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-macos-package: + needs: + - setup + - build-macos-backend + - build-linux-docker-and-package-x86 + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-package + with: + architecture: arm64 + package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + publish-release: runs-on: ubuntu-latest needs: @@ -184,6 +218,7 @@ jobs: - build-linux-docker-and-package-x86 - build-linux-docker-and-package-arm - build-windows-package + - build-macos-package - push-linux-docker steps: - name: Download all packaged files diff --git a/.github/workflows/build-snapshot.yml b/.github/workflows/build-snapshot.yml index 562612cd..1d28f75c 100644 --- a/.github/workflows/build-snapshot.yml +++ b/.github/workflows/build-snapshot.yml @@ -159,6 +159,23 @@ jobs: skip-tests: ${{ vars.SKIP_TESTS }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-macos-backend: + needs: + - setup + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-backend + with: + architecture: arm64 + build-unix-time: ${{ needs.setup.outputs.build-unix-time }} + build-date: ${{ needs.setup.outputs.build-date }} + check-3rd-api: ${{ vars.CHECK_3RD_API }} + skip-tests: ${{ vars.SKIP_TESTS }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + build-windows-package: needs: - setup @@ -173,3 +190,19 @@ jobs: with: package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} + + build-macos-package: + needs: + - setup + - build-macos-backend + - build-linux-docker-and-package-x86 + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - uses: ./.github/actions/build-macos-package + with: + architecture: arm64 + package-file-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-package-file-name-prefix }} + backend-artifact-name-prefix: ${{ needs.setup.outputs.ezbookkeeping-backend-artifact-name-prefix }} diff --git a/build.sh b/build.sh index 9d438746..6be7d4cd 100755 --- a/build.sh +++ b/build.sh @@ -160,6 +160,12 @@ build_backend() { fi fi + ld_static_link_flags="" + + if [ "$(uname -s)" = "Linux" ]; then + ld_static_link_flags="-linkmode external -extldflags '-static'" + fi + backend_build_extra_arguments="-X main.Version=$VERSION" backend_build_extra_arguments="$backend_build_extra_arguments -X main.CommitHash=$COMMIT_HASH" @@ -169,7 +175,7 @@ build_backend() { echo "Building backend binary file ($RELEASE_TYPE)..." - CGO_ENABLED=1 go build -a -v -trimpath -ldflags "-w -s -linkmode external -extldflags '-static' $backend_build_extra_arguments" -o ezbookkeeping ezbookkeeping.go + CGO_ENABLED=1 go build -a -v -trimpath -ldflags "-w -s $ld_static_link_flags $backend_build_extra_arguments" -o ezbookkeeping ezbookkeeping.go chmod +x ezbookkeeping }