mirror of
https://gitee.com/270580156/weiyu.git
synced 2025-12-30 10:52:26 +00:00
170 lines
6.1 KiB
YAML
170 lines
6.1 KiB
YAML
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
|
||
|
||
# This workflow uses actions that are not certified by GitHub.
|
||
# They are provided by a third-party and are governed by
|
||
# separate terms of service, privacy policy, and support
|
||
# documentation.
|
||
#
|
||
# github:依次添加以下变量,
|
||
# 路径:Settings -> Secrets And Variables -> Actions
|
||
# Repository secrets -> New repository secret -> 输入变量名和值
|
||
# SERVER_HOST / Secret:服务器公网IP
|
||
# SERVER_USERNAME / Secret:服务器用户名
|
||
# SERVER_PASSWORD / Secret:服务器密码
|
||
# SERVER_PORT / Secret:服务器端口
|
||
|
||
name: bytedesk
|
||
on:
|
||
push:
|
||
tags:
|
||
- 'v*' # 在推送的标签以"v"开头时执行
|
||
|
||
# 添加权限配置,确保有足够权限创建release
|
||
permissions:
|
||
contents: write
|
||
packages: write
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu-latest # 运行环境
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v4
|
||
# https://github.com/actions/setup-java
|
||
- name: install JDK17
|
||
uses: actions/setup-java@v4
|
||
with:
|
||
java-version: '17'
|
||
distribution: 'temurin'
|
||
cache: maven
|
||
# https://github.com/arduino/setup-protoc
|
||
- name: Install Protoc
|
||
uses: arduino/setup-protoc@v3
|
||
with:
|
||
version: 23.x
|
||
include-pre-releases: false
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
# - name: Create Maven settings
|
||
# run: |
|
||
# mkdir -p ~/.m2
|
||
# cat > ~/.m2/settings.xml << EOF
|
||
# <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||
# xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
||
# http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||
# <profiles>
|
||
# <profile>
|
||
# <id>snapshots</id>
|
||
# <repositories>
|
||
# <repository>
|
||
# <id>central-portal-snapshots</id>
|
||
# <name>Central Portal Snapshots</name>
|
||
# <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||
# <releases>
|
||
# <enabled>false</enabled>
|
||
# </releases>
|
||
# <snapshots>
|
||
# <enabled>true</enabled>
|
||
# <updatePolicy>always</updatePolicy>
|
||
# </snapshots>
|
||
# </repository>
|
||
# </repositories>
|
||
# </profile>
|
||
# </profiles>
|
||
# <activeProfiles>
|
||
# <activeProfile>snapshots</activeProfile>
|
||
# </activeProfiles>
|
||
# </settings>
|
||
# EOF
|
||
|
||
- name: Maven build
|
||
run: |
|
||
# 清理并构建
|
||
mvn clean
|
||
# 强制更新 SNAPSHOT 依赖,确保能下载到最新的 SNAPSHOT 版本
|
||
mvn -B -DskipTests=true -U install --file pom.xml
|
||
cd starter
|
||
mvn -B -DskipTests=true -U package --file pom.xml
|
||
|
||
- name: Login to Docker Hub
|
||
uses: docker/login-action@v3
|
||
with:
|
||
username: bytedesk
|
||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||
|
||
- name: Login to Aliyun Docker
|
||
uses: docker/login-action@v3
|
||
with:
|
||
registry: registry.cn-hangzhou.aliyuncs.com
|
||
username: ${{ secrets.ALIYUN_DOCKER_USERNAME }}
|
||
password: ${{ secrets.ALIYUN_DOCKER_PASSWORD }}
|
||
|
||
# Add support for more platforms with QEMU (optional)
|
||
# https://github.com/docker/setup-qemu-action
|
||
- name: Set up QEMU
|
||
uses: docker/setup-qemu-action@v3
|
||
|
||
# https://github.com/docker/setup-buildx-action
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v3
|
||
|
||
# 提取版本号,并将其设置为环境变量
|
||
- name: Extract version
|
||
id: version
|
||
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
|
||
|
||
# https://hub.docker.com/r/bytedesk/bytedesk-ce
|
||
# https://cr.console.aliyun.com/repository/cn-hangzhou/bytedesk/bytedesk-ce/images
|
||
- name: Build and push Docker images
|
||
uses: docker/build-push-action@v6
|
||
with:
|
||
context: ./starter
|
||
file: ./starter/Dockerfile
|
||
push: true
|
||
tags: |
|
||
bytedesk/bytedesk-ce:latest
|
||
bytedesk/bytedesk-ce:${{ steps.version.outputs.VERSION }}
|
||
registry.cn-hangzhou.aliyuncs.com/bytedesk/bytedesk-ce:latest
|
||
registry.cn-hangzhou.aliyuncs.com/bytedesk/bytedesk-ce:${{ steps.version.outputs.VERSION }}
|
||
platforms: linux/amd64,linux/arm64
|
||
|
||
# 准备 weiyu-server.zip 文件
|
||
- name: Prepare weiyu-server.zip
|
||
run: |
|
||
# 确保目标目录存在
|
||
mkdir -p deploy/server
|
||
|
||
# 复制打包好的jar到deploy/server目录
|
||
cp starter/target/bytedesk-starter.jar deploy/server/
|
||
|
||
# 创建zip包
|
||
cd deploy
|
||
zip -r weiyu-server.zip server/*
|
||
cd ..
|
||
|
||
# 将weiyu-server.zip上传到GitHub Release
|
||
- name: Upload to GitHub Release
|
||
uses: softprops/action-gh-release@v1
|
||
with:
|
||
files: deploy/weiyu-server.zip
|
||
name: ByteDesk v${{ steps.version.outputs.VERSION }}
|
||
body: |
|
||
ByteDesk 版本 ${{ steps.version.outputs.VERSION }} 发布
|
||
|
||
## 下载
|
||
- [weiyu-server.zip](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/weiyu-server.zip)
|
||
|
||
## Docker 镜像
|
||
```
|
||
docker pull bytedesk/bytedesk-ce:${{ steps.version.outputs.VERSION }}
|
||
```
|
||
或者
|
||
```
|
||
docker pull registry.cn-hangzhou.aliyuncs.com/bytedesk/bytedesk-ce:${{ steps.version.outputs.VERSION }}
|
||
```
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|