Skip to content

Add .gitignore file for Maven project #4

Add .gitignore file for Maven project

Add .gitignore file for Maven project #4

name: CI-Build & Release
on:
push:
branches: [ master ]
tags: [ 'v*' ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
- name: 生成短 SHA
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')
id: sha
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: 设置快照版本
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')
run: |
mvn -B versions:set \
-DnewVersion=#${{ steps.sha.outputs.SHORT_SHA }} \
-DgenerateBackupPoms=false
- name: 编译测试 & 打包快照
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')
run: mvn -B package
- name: 上传快照包
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: ExamCountdown-#${{ steps.sha.outputs.SHORT_SHA }}
path: target/ExamCountdown-*.jar
- name: 设置发布版本
if: startsWith(github.ref, 'refs/tags/v')
run: |
VERSION=${GITHUB_REF_NAME#v}
mvn -B versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false
- name: 重新构建(跳过测试)
if: startsWith(github.ref, 'refs/tags/v')
run: mvn -B package -DskipTests
- name: 发布 Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
files: target/ExamCountdown-*.jar
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
generate_release_notes: true