diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ddc7f09..7af858c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,35 +21,9 @@ jobs: - run: | git fetch --prune --unshallow --tags - - name: Get dependencies and build - run: | - sudo apt-get update - sudo apt-get -y install gcc-mingw-w64-x86-64 - sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross - sudo apt-get -y install gcc-aarch64-linux-gnu libc6-dev-arm64-cross - chmod +x ./build.sh - ./build.sh -r b - - - name: Upload binary files (windows_amd64) - uses: actions/upload-artifact@v2 - with: - name: cloudreve_windows_amd64 - path: release/cloudreve*windows_amd64.* - - - name: Upload binary files (linux_amd64) - uses: actions/upload-artifact@v2 - with: - name: cloudreve_linux_amd64 - path: release/cloudreve*linux_amd64.* - - - name: Upload binary files (linux_arm) - uses: actions/upload-artifact@v2 - with: - name: cloudreve_linux_arm - path: release/cloudreve*linux_arm.* - - - name: Upload binary files (linux_arm64) - uses: actions/upload-artifact@v2 + - name: Build and Release + uses: goreleaser/goreleaser-action@v4 with: - name: cloudreve_linux_arm64 - path: release/cloudreve*linux_arm64.* + distribution: goreleaser + version: latest + args: release --clean diff --git a/.gitignore b/.gitignore index b272561..e99f29b 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ version.lock conf/conf.ini /statik/ .vscode/ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..95630b6 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,68 @@ +env: + - CI=false + - GENERATE_SOURCEMAP=false +before: + hooks: + - go mod tidy + - sh -c "cd assets && rm -rf build && yarn install --network-timeout 1000000 && yarn run build && cd ../ && zip -r - assets/build >assets.zip" +builds: + - + env: + - CGO_ENABLED=0 + + ldflags: + - -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion={{.Version}}' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit={{.ShortCommit}}' + + goos: + - linux + - windows + - darwin + + goarch: + - amd64 + - arm + - arm64 + + goarm: + - 5 + - 6 + - 7 + + ignore: + - goos: windows + goarm: 5 + - goos: windows + goarm: 6 + - goos: windows + goarm: 7 + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +release: + draft: true + prerelease: auto + target_commitish: '{{ .Commit }}' + name_template: "{{.Version}}" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6f3891e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: go -go: - - 1.18.x -node_js: "12.16.3" -git: - depth: 1 -before_install: - - mkdir assets/build - - touch assets/build/test.html -script: - - go test -coverprofile=coverage.txt -covermode=atomic ./... -after_success: - - bash <(curl -s https://codecov.io/bash) -before_deploy: - - sudo apt-get update - - sudo apt-get -y install gcc-mingw-w64-x86-64 - - sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross - - sudo apt-get -y install gcc-aarch64-linux-gnu libc6-dev-arm64-cross - - chmod +x ./build.sh - - ./build.sh -r b -deploy: - provider: releases - api_key: $GITHUB_TOKEN - file_glob: true - file: release/* - draft: true - skip_cleanup: true - on: - tags: true diff --git a/assets b/assets index 09a5168..d4dc124 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 09a5168b23349cb1d0201b544ba48ccb583886be +Subproject commit d4dc124e9986d18096d54ec6f2b4b283de1536cc diff --git a/build.sh b/build.sh deleted file mode 100755 index c25c909..0000000 --- a/build.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -REPO=$( - cd $(dirname $0) - pwd -) -COMMIT_SHA=$(git rev-parse --short HEAD) -VERSION=$(git describe --tags) -ASSETS="false" -BINARY="false" -RELEASE="false" - -debugInfo() { - echo "Repo: $REPO" - echo "Build assets: $ASSETS" - echo "Build binary: $BINARY" - echo "Release: $RELEASE" - echo "Version: $VERSION" - echo "Commit: $COMMIT_SHA" -} - -buildAssets() { - cd $REPO - rm -rf assets/build - - export CI=false - export GENERATE_SOURCEMAP=false - - cd $REPO/assets - - yarn install --network-timeout 1000000 - yarn install - yarn run build - cd build - cd $REPO - - # please keep in mind that if this final output binary `assets.zip` name changed, please go and update the `Dockerfile` as well - zip -r - assets/build >assets.zip -} - -buildBinary() { - cd $REPO - - # same as assets, if this final output binary `cloudreve` name changed, please go and update the `Dockerfile` - go build -a -o cloudreve -ldflags " -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'" -} - -_build() { - local osarch=$1 - IFS=/ read -r -a arr <<<"$osarch" - os="${arr[0]}" - arch="${arr[1]}" - gcc="${arr[2]}" - - # Go build to build the binary. - export GOOS=$os - export GOARCH=$arch - export CC=$gcc - export CGO_ENABLED=1 - - if [ -n "$VERSION" ]; then - out="release/cloudreve_${VERSION}_${os}_${arch}" - else - out="release/cloudreve_${COMMIT_SHA}_${os}_${arch}" - fi - - go build -a -o "${out}" -ldflags " -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'" - - if [ "$os" = "windows" ]; then - mv $out release/cloudreve.exe - zip -j -q "${out}.zip" release/cloudreve.exe - rm -f "release/cloudreve.exe" - else - mv $out release/cloudreve - tar -zcvf "${out}.tar.gz" -C release cloudreve - rm -f "release/cloudreve" - fi -} - -release() { - cd $REPO - ## List of architectures and OS to test coss compilation. - SUPPORTED_OSARCH="linux/amd64/gcc linux/arm/arm-linux-gnueabihf-gcc windows/amd64/x86_64-w64-mingw32-gcc linux/arm64/aarch64-linux-gnu-gcc" - - echo "Release builds for OS/Arch/CC: ${SUPPORTED_OSARCH}" - for each_osarch in ${SUPPORTED_OSARCH}; do - _build "${each_osarch}" - done -} - -usage() { - echo "Usage: $0 [-a] [-c] [-b] [-r]" 1>&2 - exit 1 -} - -while getopts "bacrd" o; do - case "${o}" in - b) - ASSETS="true" - BINARY="true" - ;; - a) - ASSETS="true" - ;; - c) - BINARY="true" - ;; - r) - ASSETS="true" - RELEASE="true" - ;; - d) - DEBUG="true" - ;; - *) - usage - ;; - esac -done -shift $((OPTIND - 1)) - -if [ "$DEBUG" = "true" ]; then - debugInfo -fi - -if [ "$ASSETS" = "true" ]; then - buildAssets -fi - -if [ "$BINARY" = "true" ]; then - buildBinary -fi - -if [ "$RELEASE" = "true" ]; then - release -fi