Skip to content

Auto Build

Auto Build #10

Workflow file for this run

name: Auto Build
on:
schedule:
# 每天 UTC 12:00(即北京时间 20:00)自动执行
- cron: '0 12 * * *'
workflow_dispatch:
env:
ANDROID_NDK_VERSION: r25c
COMMIT_ID: "${{ github.sha }}"
NO_BUILD_PROMPT: "no new commits, no need to build."
jobs:
commit-num-check:
name: Check Commit Num
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get New Commits
id: get-commits
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT
- name: Warning
run: if [ $(git log --oneline --since '24 hours ago' | wc -l) <= 0 ]; then echo $NO_BUILD_PROMPT; fi
outputs:
commit-count: ${{ steps.get-commits.outputs.NEW_COMMIT_COUNT }}
resources-download:
name: Download Related Resources
runs-on: ubuntu-latest
needs: commit-num-check
if: ${{ needs.commit-num-check.outputs.commit-count > 0 }}
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Upload Documents
uses: actions/upload-artifact@v3
with:
name: documents
path: ./sealdice-builtins/data
gocqhttp-build:
name: Build Gocqhttp
runs-on: ubuntu-latest
needs: commit-num-check
if: ${{ needs.commit-num-check.outputs.commit-count > 0 }}
strategy:
matrix:
# target: linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [ linux, windows, darwin ]
goarch: [ '386', amd64, arm64 ]
exclude:
- goos: linux
goarch: '386'
- goos: windows
goarch: arm64
- goos: darwin
goarch: '386'
fail-fast: true
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Get Commit ID
run: |
cd go-cqhttp
echo "GOCQ_CID=`git rev-parse HEAD`" >> $GITHUB_ENV;
- name: Cache dist get
id: cache-gocq-dist
uses: actions/cache@v3
env:
cache-name: cache-gocq-${{ matrix.goos }}-${{ matrix.goarch }}-dist
with:
path: ./go-cqhttp/output
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.GOCQ_CID }}
- name: Install Go
uses: actions/setup-go@v3
if: ${{ steps.cache-gocq-dist.outputs.cache-hit != 'true' }}
with:
go-version: stable
- name: Build Binary
if: ${{ steps.cache-gocq-dist.outputs.cache-hit != 'true' }}
working-directory: ./go-cqhttp
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLE: 0
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX=".exe"; fi
export BINARY_NAME="go-cqhttp$BINARY_SUFFIX"
export LD_FLAGS="-w -s -X github.com/Mrs4s/go-cqhttp/internal/base.Version=${COMMIT_ID::7}-sealdicefork"
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
- name: Upload Gocqhttp
uses: actions/upload-artifact@v3
with:
name: go-cqhttp_${{ matrix.goos }}_${{ matrix.goarch }}
path: ./go-cqhttp/output
gocqhttp-android-build:
name: Build Gocqhttp (android, arm64)
runs-on: ubuntu-latest
needs: commit-num-check
if: ${{ needs.commit-num-check.outputs.commit-count > 0 }}
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Get Commit ID
run: |
cd go-cqhttp
echo "GOCQ_CID=`git rev-parse HEAD`" >> $GITHUB_ENV;
- name: Cache dist get
id: cache-gocq-dist
uses: actions/cache@v3
env:
cache-name: cache-gocqa-dist
with:
path: ./go-cqhttp/output
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.GOCQ_CID }}
- name: Install Go
if: ${{ steps.cache-gocq-dist.outputs.cache-hit != 'true' }}
uses: actions/setup-go@v3
with:
go-version: stable
- name: Setup Android NDK
id: setup-ndk
if: ${{ steps.cache-gocq-dist.outputs.cache-hit != 'true' }}
uses: nttld/setup-ndk@v1
with:
ndk-version: ${{ env.ANDROID_NDK_VERSION }}
link-to-sdk: true
local-cache: true
- name: Build Binary
if: ${{ steps.cache-gocq-dist.outputs.cache-hit != 'true' }}
working-directory: ./go-cqhttp
env:
GOOS: android
GOARCH: arm64
CGO_ENABLE: 0
CC: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
run: |
export LD_FLAGS="-w -s -X github.com/Mrs4s/go-cqhttp/internal/base.Version=${COMMIT_ID::7}-sealdicefork"
go build -o "output/go-cqhttp" -trimpath -ldflags "$LD_FLAGS" .
- name: Upload Gocqhttp
uses: actions/upload-artifact@v3
with:
name: go-cqhttp_android_arm64
path: ./go-cqhttp/output
ui-build:
name: Build UI
runs-on: ubuntu-latest
needs: commit-num-check
if: ${{ needs.commit-num-check.outputs.commit-count > 0 }}
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Get Commit ID
run: |
cd sealdice-ui
echo "UI_CID=`git rev-parse HEAD`" >> $GITHUB_ENV;
- name: Cache ui dist get
id: cache-ui-dist
uses: actions/cache@v3
env:
cache-name: cache-ui-dist
with:
path: ./sealdice-ui/dist
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.UI_CID }}
- if: ${{ steps.cache-ui-dist.outputs.cache-hit == 'true' }}
name: Show cache
continue-on-error: true
run: ls ./sealdice-ui/dist
- name: Install Node
uses: actions/setup-node@v3
if: ${{ steps.cache-ui-dist.outputs.cache-hit != 'true' }}
with:
node-version: latest
- name: Install Dependencies
if: ${{ steps.cache-ui-dist.outputs.cache-hit != 'true' }}
working-directory: ./sealdice-ui
run: npm install
- name: Build WebUI
if: ${{ steps.cache-ui-dist.outputs.cache-hit != 'true' }}
working-directory: ./sealdice-ui
run: npm run build
- name: Upload UI
uses: actions/upload-artifact@v3
with:
name: sealdice-ui
path: ./sealdice-ui/dist
core-build:
name: Build Core
runs-on: ubuntu-latest
needs: ui-build
strategy:
matrix:
# target: linux/amd64, linux/arm64, windows/386, windows/amd64
goos: [ linux, windows ]
goarch: [ '386', amd64, arm64 ]
exclude:
- goos: linux
goarch: '386'
- goos: windows
goarch: arm64
fail-fast: true
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Install Cross-compiler for Windows
if: matrix.goos == 'windows'
run: sudo apt-get -y install mingw-w64
- name: Install Cross-compiler for Linux Arm64
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
run: sudo apt-get -y install gcc-aarch64-linux-gnu
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: stable
- name: Install Dependencies
working-directory: ./sealdice-core
run: |
go mod tidy
go get .
- name: Get UI Resources
uses: actions/download-artifact@v3
with:
name: sealdice-ui
path: ./sealdice-core/static/frontend
- name: Set Env
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
working-directory: ./sealdice-core
run: |
echo "PROJECT_VERSION=dev-${COMMIT_ID::7}" >> $GITHUB_ENV;
if [ $GOOS = 'windows' ]; then
echo "BINARY_NAME=sealdice-core.exe" >> $GITHUB_ENV;
else
echo "BINARY_NAME=sealdice-core" >> $GITHUB_ENV;
fi
if [ $GOOS = 'windows' ] && [ $GOARCH = '386' ]; then
echo "CC=i686-w64-mingw32-gcc" >> $GITHUB_ENV;
elif [ $GOOS = 'windows' ] && [ $GOARCH = 'amd64' ]; then
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV;
elif [ $GOOS = 'linux' ] && [ $GOARCH = 'amd64' ]; then
echo "CC=gcc" >> $GITHUB_ENV;
elif [ $GOOS = 'linux' ] && [ $GOARCH = 'arm64' ]; then
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV;
fi
- name: Build Binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GO111MODULE: on
CGO_ENABLED: ${{ matrix.goarch != 'arm64' && 1 || 0 }}
CGO_FLAGS: -Werror=unused-variable -Werror=implicit-function-declaration -O2 -H=windowsgui
working-directory: ./sealdice-core
run: go build -o "output/$BINARY_NAME" -trimpath -ldflags "-s -w -X sealdice-core/dice.VERSION=$PROJECT_VERSION" .
- name: Upload Core
uses: actions/upload-artifact@v3
with:
name: sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: ./sealdice-core/output
core-darwin-build:
name: Build Core
runs-on: macos-latest
needs: ui-build
strategy:
matrix:
# target: darwin/amd64 darwin/arm64
goos: [ darwin ]
goarch: [ amd64, arm64 ]
fail-fast: true
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: stable
- name: Install dependencies
working-directory: ./sealdice-core
run: |
go mod tidy
go get .
- name: Get UI Resources
uses: actions/download-artifact@v3
with:
name: sealdice-ui
path: ./sealdice-core/static/frontend
- name: Set Env
working-directory: ./sealdice-core
run: echo "PROJECT_VERSION=dev-${COMMIT_ID::7}" >> $GITHUB_ENV;
- name: Build Binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GO111MODULE: on
CGO_ENABLED: 1
CGO_FLAGS: -Werror=unused-variable -Werror=implicit-function-declaration -O2
working-directory: ./sealdice-core
run: go build -o "output/sealdice-core" -trimpath -ldflags "-s -w -X sealdice-core/dice.VERSION=$PROJECT_VERSION" .
- name: Upload Core
uses: actions/upload-artifact@v3
with:
name: sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: ./sealdice-core/output
core-android-build:
name: Build Core (android, arm64)
runs-on: ubuntu-latest
needs: ui-build
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Android NDK
id: setup-ndk
uses: nttld/setup-ndk@v1
with:
ndk-version: ${{ env.ANDROID_NDK_VERSION }}
link-to-sdk: true
local-cache: true
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Install dependencies
working-directory: ./sealdice-core
run: |
go mod tidy
go get .
- name: Get UI Resources
uses: actions/download-artifact@v3
with:
name: sealdice-ui
path: ./sealdice-core/static/frontend
- name: Set env
run: |
echo "PROJECT_VERSION=dev-${COMMIT_ID::7}" >> $GITHUB_ENV;
- name: Build binary
env:
GOOS: android
GOARCH: arm64
CGO_ENABLED: 1
CC: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
CGO_FLAGS: -Werror=unused-variable -Werror=implicit-function-declaration -O2
working-directory: ./sealdice-core
run: go build -o "output/sealdice-core" -trimpath -ldflags "-s -w -X sealdice-core/dice.VERSION=$PROJECT_VERSION" .
- name: Upload Core
uses: actions/upload-artifact@v3
with:
name: sealdice-core_${{ env.PROJECT_VERSION }}_android_arm64
path: ./sealdice-core/output
android-build:
name: Build Android Apk
runs-on: ubuntu-latest
needs:
- core-android-build
- resources-download
- gocqhttp-android-build
steps:
- name: Code
uses: actions/checkout@v3
with:
submodules: true
- name: Set Env
run: echo "PROJECT_VERSION=dev-${COMMIT_ID::7}" >> $GITHUB_ENV;
- name: Get Core-android
uses: actions/download-artifact@v3
with:
name: sealdice-core_${{ env.PROJECT_VERSION }}_android_arm64
path: ./sealdice-android/app/src/main/assets/sealdice
- name: Get Documents
uses: actions/download-artifact@v3
with:
name: documents
path: ./sealdice-android/app/src/main/assets/sealdice/data
- name: Get Gocqhttp
uses: actions/download-artifact@v3
with:
name: go-cqhttp_android_arm64
path: ./sealdice-android/app/src/main/assets/sealdice/go-cqhttp/
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Set Execution Flag
working-directory: ./sealdice-android
run: chmod +x gradlew
- name: Remove ARCA Config
working-directory: ./sealdice-android/app/src/main/java/com/sealdice/dice
run: |
sed -i '/secrets.Auth.*/d' MyApplication.kt
sed -i '/httpSender {/,/}/d' MyApplication.kt
- name: Set Version
working-directory: ./sealdice-android/app
run: |
sed -i 's/versionName ".*"/versionName "${{ env.PROJECT_VERSION }}"/g' build.gradle
- name: Build Apk
working-directory: ./sealdice-android
run: |
bash ./gradlew assembleDebug --stacktrace
mv ./app/build/outputs/apk/debug/app-debug.apk ./app/build/outputs/apk/debug/sealdice-android_$PROJECT_VERSION.apk
- name: Upload Apk
uses: actions/upload-artifact@v1
with:
name: sealdice_${{ env.PROJECT_VERSION }}_android_arm64
path: ./sealdice-android/app/build/outputs/apk/debug/sealdice-android_${{ env.PROJECT_VERSION }}.apk
pc-pack:
name: PC Pack
runs-on: ubuntu-latest
needs:
- resources-download
- gocqhttp-build
- core-build
- core-darwin-build
strategy:
matrix:
# target: linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [ linux, windows, darwin ]
goarch: [ '386', amd64, arm64 ]
exclude:
- goos: linux
goarch: '386'
- goos: windows
goarch: arm64
- goos: darwin
goarch: '386'
steps:
- name: Set Env
run: echo "PROJECT_VERSION=dev-${COMMIT_ID::7}" >> $GITHUB_ENV;
- name: Get Documents
uses: actions/download-artifact@v3
with:
name: documents
path: ./data
- name: Get Gocqhttp
uses: actions/download-artifact@v3
with:
name: go-cqhttp_${{ matrix.goos }}_${{ matrix.goarch }}
path: ./go-cqhttp/
- name: Get Core
uses: actions/download-artifact@v3
with:
name: sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}
path: .
- name: Set Execute Attribute
if: matrix.goos != 'windows'
run: chmod +x ./sealdice-core
- name: Set Archive Extension Default
run: |
echo "AEXT=tar" >> $GITHUB_ENV;
echo "AEXTF=tar.gz" >> $GITHUB_ENV;
- name: Set Archive Extension Windows
if: matrix.goos == 'windows'
run: |
echo "AEXT=zip" >> $GITHUB_ENV;
echo "AEXTF=zip" >> $GITHUB_ENV;
- name: Archive Release Windows
uses: thedoctor0/[email protected]
if: matrix.goos == 'windows'
with:
type: ${{ env.AEXT }}
filename: sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ env.AEXTF }}
exclusions: '*.git* /*node_modules/* .editorconfig'
- name: Archive Release !Windows
if: matrix.goos != 'windows'
run: |
tar --exclude='.DS_Store' -czvf /tmp/sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ env.AEXTF }} . --warning=no-file-changed
cp /tmp/sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ env.AEXTF }} ./
- name: Upload
uses: actions/upload-artifact@v3
with:
name: sealdice_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ env.AEXTF }}
path: sealdice-core_${{ env.PROJECT_VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}.${{ env.AEXTF }}
clear-temp-artifact:
name: Clear Temp Artifacts
if: always()
runs-on: ubuntu-latest
needs:
- pc-pack
- android-build
steps:
- uses: geekyeggo/delete-artifact@v2
with:
name: |
documents
go-cqhttp*
sealdice-ui
sealdice-core*