diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 510e4810..84515699 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,53 +9,49 @@ jobs: name: Build runs-on: ubuntu-18.04 steps: - - - name: Set up Golang - uses: actions/setup-go@v1 - with: - go-version: 1.17 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - with: - clean: false - submodules: 'recursive' - - run: | - git fetch --prune --unshallow --tags - - - name: Get dependencies and build - run: | - go install github.com/rakyll/statik - export PATH=$PATH:~/go/bin/ - statik -src=models -f - 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 - with: - name: cloudreve_linux_arm64 - path: release/cloudreve*linux_arm64.* + - name: Set up Go 1.17 + uses: actions/setup-go@v2 + with: + go-version: "1.17" + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + with: + clean: false + submodules: "recursive" + - 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 + with: + name: cloudreve_linux_arm64 + path: release/cloudreve*linux_arm64.* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a325be5..1df53014 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,9 @@ jobs: - name: Build static files run: | cd assets - yarn install - yarn run build + mkdir build + cd build + touch test.html - name: Test run: go test -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/.travis.yml b/.travis.yml index 22d4990b..2acbb53a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,11 @@ go: node_js: "12.16.3" git: depth: 1 -install: - - go get github.com/rakyll/statik before_script: - - statik -src=models -f + - cd assets + - mkdir build + - cd mkdir + - touch test.html script: - go test -coverprofile=coverage.txt -covermode=atomic ./... after_success: @@ -27,4 +28,4 @@ deploy: draft: true skip_cleanup: true on: - tags: true \ No newline at end of file + tags: true diff --git a/Dockerfile b/Dockerfile index 4b51c5e6..e99d32ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,8 +28,6 @@ RUN set -ex \ && apk add gcc libc-dev git \ && export COMMIT_SHA=$(git rev-parse --short HEAD) \ && export VERSION=$(git describe --tags) \ - && (cd && go get github.com/rakyll/statik) \ - && statik -src=assets/build/ -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico -f \ && go install -ldflags "-X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=${VERSION}' \ -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=${COMMIT_SHA}'\ -w -s" diff --git a/README.md b/README.md index 3496f678..358f10b1 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ chmod +x ./cloudreve ## :gear: 构建 -自行构建前需要拥有 `Go >= 1.16`、`yarn`等必要依赖。 +自行构建前需要拥有 `Go >= 1.17`、`yarn`等必要依赖。 #### 克隆代码 diff --git a/build.sh b/build.sh index dd18f3ad..c93170e2 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,16 @@ #!/bin/bash -REPO=$(cd $(dirname $0); pwd) +REPO=$( + cd $(dirname $0) + pwd +) COMMIT_SHA=$(git rev-parse --short HEAD) VERSION=$(git describe --tags) ASSETS="false" BINARY="false" RELEASE="false" -debugInfo () { +debugInfo() { echo "Repo: $REPO" echo "Build assets: $ASSETS" echo "Build binary: $BINARY" @@ -16,105 +19,99 @@ debugInfo () { echo "Commit: $COMMIT_SHA" } -buildAssets () { +buildAssets() { cd $REPO rm -rf assets/build - rm -f statik/statik.go export CI=false cd $REPO/assets + yarn --update-checksums yarn install yarn run build - - if ! [ -x "$(command -v statik)" ]; then - export CGO_ENABLED=0 - go get github.com/rakyll/statik - fi - - cd $REPO - statik -src=assets/build/ -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico,*.ttf -f + cd build + rm -rf *.map } -buildBinary () { +buildBinary() { cd $REPO 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 + 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(){ +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}" + _build "${each_osarch}" done } usage() { - echo "Usage: $0 [-a] [-c] [-b] [-r]" 1>&2; - exit 1; + echo "Usage: $0 [-a] [-c] [-b] [-r]" 1>&2 + exit 1 } while getopts "bacr:d" 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 - ;; + 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)) +shift $((OPTIND - 1)) if [ "$DEBUG" = "true" ]; then debugInfo