Skip to content

1.4.1-beta5.9

1.4.1-beta5.9 #52

Workflow file for this run

name: Build and Release
on:
release:
types: [ published ]
workflow_dispatch:
inputs:
tag_name:
description: '对应Release tag名字(例:1.4.2)'
required: true
default: ''
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Maven
run: mvn -B clean package --file pom.xml -DskipTests
- name: Prepare Docker Build Context
run: |
cd target
# 为 Docker 构建准备 ROOT.war
for file in *.war; do
if [ -f "$file" ] && [[ ! "$file" =~ \.original$ ]]; then
cp "$file" ROOT.war
echo "Prepared ROOT.war for Docker build"
break
fi
done
ls -la ROOT.war
- name: Set Version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
TAG_NAME="${{ github.event.release.tag_name }}"
else
TAG_NAME="${{ github.event.inputs.tag_name }}"
fi
# 移除 v 前缀(如果有)
VERSION=${TAG_NAME#v}
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version: ${VERSION}, Tag: ${TAG_NAME}"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./target
file: ./Docker/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/biliupforjava:${{ steps.version.outputs.version }}
${{ secrets.DOCKERHUB_USERNAME }}/biliupforjava:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Rename WAR file
run: |
cd target
TAG_NAME="${{ steps.version.outputs.tag }}"
for file in *.war; do
if [ -f "$file" ] && [[ ! "$file" =~ \.original$ ]] && [ "$file" != "ROOT.war" ]; then
mv "$file" "biliupforjava-${TAG_NAME}.war"
echo "Renamed: $file -> biliupforjava-${TAG_NAME}.war"
break
fi
done
ls -la *.war
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Looking for WAR files in target/"
ls -la target/*.war || true
TAG_NAME="${{ steps.version.outputs.tag }}"
ARTIFACT="target/biliupforjava-${TAG_NAME}.war"
if [ ! -f "$ARTIFACT" ]; then
echo "ERROR: Expected WAR file not found: $ARTIFACT"
ls -la target
exit 1
fi
echo "Uploading release asset: $ARTIFACT to tag: $TAG_NAME"
gh release upload "$TAG_NAME" "$ARTIFACT" --clobber