mirror of https://github.com/Xhofe/alist
💚 Optimize github actions build
parent
c24894b5de
commit
7c7306bf96
|
@ -31,13 +31,6 @@ jobs:
|
|||
ref: v2
|
||||
path: alist
|
||||
|
||||
- name: Checkout web repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: Xhofe/alist-web
|
||||
ref: v2
|
||||
path: alist-web
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
docker pull crazymax/xgo:latest
|
||||
|
@ -47,10 +40,49 @@ jobs:
|
|||
- name: Build
|
||||
run: |
|
||||
mv alist/build.sh .
|
||||
bash build.sh
|
||||
bash build.sh web
|
||||
mv dist/* alist/public
|
||||
bash build.sh build
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: artifact
|
||||
path: alist/build
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: |
|
||||
bash build.sh web
|
||||
mv dist/* public
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
|
@ -1,48 +0,0 @@
|
|||
name: docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'v2'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'v2'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: bash build.sh web
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
|
@ -19,14 +19,6 @@ jobs:
|
|||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
# - name: Setup docker
|
||||
# uses: docker-practice/actions-setup-docker@master
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
|
@ -35,35 +27,57 @@ jobs:
|
|||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout web repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: Xhofe/alist-web
|
||||
ref: v2
|
||||
path: alist-web
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
docker pull techknowlogick/xgo:latest
|
||||
go install src.techknowlogick.com/xgo@latest
|
||||
docker pull crazymax/xgo:latest
|
||||
go install github.com/crazy-max/xgo@latest
|
||||
sudo apt install upx
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
mv alist/build.sh .
|
||||
bash build.sh cdn
|
||||
mv dist/* alist/public
|
||||
bash build.sh release
|
||||
|
||||
- name: Upload asserts files
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.MY_TOKEN }}
|
||||
branch: cdn
|
||||
directory: alist-web
|
||||
repository: Xhofe/alist-web
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: alist/build/compress/*
|
||||
files: alist/build/compress/*
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: |
|
||||
bash build.sh cdn
|
||||
mv dist/* public
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x
|
150
build.sh
150
build.sh
|
@ -1,17 +1,24 @@
|
|||
#!/bin/bash
|
||||
if [ "$1" == "web" ]; then
|
||||
git clone https://github.com/Xhofe/alist-web.git
|
||||
cd alist-web || exit
|
||||
|
||||
# 构建前端,在当前目录产生一个dist文件夹
|
||||
BUILD_WEB() {
|
||||
git clone https://github.com/alist-org/alist-web.git
|
||||
cd alist-web
|
||||
yarn
|
||||
yarn build
|
||||
mv dist/* ../public
|
||||
mv dist ..
|
||||
cd ..
|
||||
exit 0
|
||||
fi
|
||||
rm -rf alist-web
|
||||
}
|
||||
|
||||
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io,direct
|
||||
CDN_WEB() {
|
||||
curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz
|
||||
tar -zxvf dist.tar.gz
|
||||
rm -f dist.tar.gz
|
||||
}
|
||||
|
||||
if [ "$1" == "docker" ]; then
|
||||
# 在DOCKER中构建
|
||||
BUILD_DOCKER() {
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
|
@ -25,40 +32,20 @@ if [ "$1" == "docker" ]; then
|
|||
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
"
|
||||
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter alist.go
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
cd alist-web || exit
|
||||
webCommit=$(git log --pretty=format:"%h" -1)
|
||||
echo "web commit id: $webCommit"
|
||||
yarn
|
||||
if [ "$1" == "release" ]; then
|
||||
yarn build --base="https://cdn.jsdelivr.net/gh/Xhofe/alist-web@cdn/v2/$webCommit"
|
||||
mv dist/assets ..
|
||||
mv dist/index.html ../alist/public
|
||||
# 构建local
|
||||
yarn build
|
||||
mv dist/index.html dist/local.html
|
||||
mv dist/* ../alist/public
|
||||
else
|
||||
yarn build
|
||||
mv dist/* ../alist/public
|
||||
fi
|
||||
cd ..
|
||||
|
||||
cd alist
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
|
||||
echo "build version: $gitTag"
|
||||
|
||||
ldflags="\
|
||||
BUILD() {
|
||||
cd alist
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
echo "build version: $gitTag"
|
||||
ldflags="\
|
||||
-w -s \
|
||||
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
|
||||
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
|
||||
|
@ -67,44 +54,47 @@ ldflags="\
|
|||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
xgo -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||
else
|
||||
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||
fi
|
||||
mkdir "build"
|
||||
mv alist-* build
|
||||
cd build || exit
|
||||
upx -9 ./*
|
||||
find . -type f -print0 | xargs -0 md5sum > md5.txt
|
||||
cat md5.txt
|
||||
# compress file (release)
|
||||
if [ "$1" == "release" ]; then
|
||||
mkdir compress
|
||||
mv md5.txt compress
|
||||
for i in `find . -type f -name "$appName-linux-*"`
|
||||
do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in `find . -type f -name "$appName-darwin-*"`
|
||||
do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in `find . -type f -name "$appName-windows-*"`
|
||||
do
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
|
||||
done
|
||||
fi
|
||||
cd ../..
|
||||
if [ "$1" == "release" ]; then
|
||||
xgo -out "$appName" -ldflags="$ldflags" -tags=jsoniter .
|
||||
else
|
||||
xgo -targets=linux/amd64,windows/amd64 -out alist -ldflags="$ldflags" -tags=jsoniter .
|
||||
fi
|
||||
mkdir "build"
|
||||
mv alist-* build
|
||||
cd build
|
||||
upx -9 ./*
|
||||
find . -type f -print0 | xargs -0 md5sum >md5.txt
|
||||
cat md5.txt
|
||||
cd ../..
|
||||
}
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
cd alist-web
|
||||
git checkout cdn
|
||||
mkdir "v2/$webCommit"
|
||||
mv ../assets/ v2/$webCommit
|
||||
git add .
|
||||
git config --local user.email "i@nn.ci"
|
||||
git config --local user.name "Xhofe"
|
||||
git commit --allow-empty -m "upload $webCommit assets files" -a
|
||||
cd ..
|
||||
fi
|
||||
RELEASE() {
|
||||
cd alist/build
|
||||
mkdir compress
|
||||
mv md5.txt compress
|
||||
for i in $(find . -type f -name "$appName-linux-*"); do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-darwin-*"); do
|
||||
tar -czvf compress/"$i".tar.gz "$i"
|
||||
done
|
||||
for i in $(find . -type f -name "$appName-windows-*"); do
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
|
||||
done
|
||||
cd ../..
|
||||
}
|
||||
|
||||
if [ "$1" = "web" ]; then
|
||||
BUILD_WEB
|
||||
elif [ "$1" = "cdn" ]; then
|
||||
CDN_WEB
|
||||
elif [ "$1" = "docker" ]; then
|
||||
BUILD_DOCKER
|
||||
elif [ "$1" = "build" ]; then
|
||||
BUILD
|
||||
elif [ "$1" = "release" ]; then
|
||||
BUILD
|
||||
RELEASE
|
||||
else
|
||||
echo -e "${RED_COLOR} 错误的命令${RES}"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue