Skip to content

1.移除sqllite数据库使用mysql 修改其他脚本支持mysql #37

1.移除sqllite数据库使用mysql 修改其他脚本支持mysql

1.移除sqllite数据库使用mysql 修改其他脚本支持mysql #37

name: Java CI with Maven and Release
on:
push:
branches: [ 2.0 ] # 只在提交到2.0分支时触发
env:
APP_VERSION: ""
DOCKER_USERNAME: "${{ secrets.DOCKER_USERNAME }}"
DOCKER_PASSWORD: "${{ secrets.DOCKER_PASSWORD }}"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
cache-dependency-path: 'pom.xml' # optional
- name: Install yq
run: |
wget https://github.com/mikefarah/yq/releases/download/v4.16.2/yq_linux_amd64 -O /usr/local/bin/yq
chmod +x /usr/local/bin/yq
- name: Read Application Version
id: app_version
run: |
VERSION=$(cd src/main/resources && yq e '.version' application.yml)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
echo "APP_VERSION: $VERSION"
echo "$VERSION" > version.txt
- name: List Environment Variables
run: env
- name: Build with Maven
run: |
mvn -B package --file pom.xml
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: java-artifact
path: |
target/*.jar
version.txt
- name: Build the Docker image
run: |
docker version
# 登录阿里云镜像仓库
docker login --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD registry.cn-hangzhou.aliyuncs.com
# 使用Dockerfile构建镜像
docker build . --file Dockerfile_jar --tag registry.cn-hangzhou.aliyuncs.com/sqdockler/sq_docker:v$APP_VERSION
# 推送镜像到镜像仓库
docker push registry.cn-hangzhou.aliyuncs.com/sqdockler/sq_docker:v$APP_VERSION
release:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/2.0' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: java-artifact
- name: Display structure of downloaded files
run: ls -R
- name: Read Version from Artifact
id: app_version
run: |
VERSION=$(cat version.txt)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "APP_VERSION: $VERSION"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.app_version.outputs.version }} # 从 artifact 中读取版本号 release_name: Release ${{ env.APP_VERSION }}
release_name: Release ${{ steps.app_version.outputs.version }}
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/MusicServer2.0.jar
asset_name: MusicServer${{ steps.app_version.outputs.version }}.jar
asset_content_type: application/octet-stream