Build & Publish JPackage #66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created | |
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle | |
name: Build & Publish JPackage | |
on: | |
push: | |
tags: ['*'] | |
workflow_dispatch: | |
inputs: | |
os: | |
description: 'Target OS for packaging (select "all" for all platforms)' | |
required: true | |
default: 'macos-latest' | |
type: choice | |
options: | |
- ubuntu-latest | |
- windows-latest | |
- macos-latest | |
- all | |
jobs: | |
setup-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
os: ${{ steps.set-matrix-full.outputs.os }}${{ steps.set-matrix-single.outputs.os }} | |
steps: | |
- name: Set full matrix for tag push or 'all' dispatch | |
id: set-matrix-full | |
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || (github.event_name == 'workflow_dispatch' && inputs.os == 'all') | |
run: echo "os=['ubuntu-latest', 'macos-latest', 'windows-latest']" >> $GITHUB_OUTPUT | |
- name: Set single matrix for specific OS dispatch | |
id: set-matrix-single | |
if: github.event_name == 'workflow_dispatch' && inputs.os != 'all' | |
run: echo "os=['${{ inputs.os }}']" >> $GITHUB_OUTPUT | |
build: | |
needs: setup-matrix | |
strategy: | |
matrix: | |
os: ${{ fromJSON(needs.setup-matrix.outputs.os) }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'corretto' | |
- name: Cache Gradle | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches/ | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# 版本号设置逻辑 | |
- name: Set Version from Tag (Auto) | |
shell: bash | |
run: | | |
echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV | |
# 平台依赖安装 | |
# liboss4-salsa-asound2 libasound2t64 仅需选择其一安装 | |
# 其中 libasound2t64 要求 Ubuntu >= 24。Ubuntu 22 找不到对应包 | |
- name: Install Dependencies (Ubuntu) | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y --no-install-recommends \ | |
libgtk-3-0 \ | |
libxtst6 \ | |
alsa-base \ | |
liboss4-salsa-asound2 | |
# libasound2t64 | |
- name: Install Dependencies (Windows) | |
if: matrix.os == 'windows-latest' | |
run: | | |
# Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
# choco install wixtoolset --version=3.14.1 -y | |
# choco install visualcppbuildtools -y | |
# choco install dotnetruntime -y | |
# 构建&打包 | |
- name: Build & Package with Gradle | |
# windows会默认使用pwsh,导致语法不一致,需要指定shell | |
shell: bash | |
run: | | |
if [ -n "$version" ]; then | |
./gradlew clean jpackage -Pversion="$version" # 传递版本号给 Gradle | |
else | |
./gradlew clean jpackage | |
fi | |
# 产物上传逻辑 | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: QuickOutline_${{ env.version }}_${{ matrix.os }} | |
path: ./build/jpackage/* | |
# 停止Gradle进程以缓存(windows下不执行会导致tar失败警告) | |
- name: Stop Gradle Daemon | |
if: matrix.os == 'windows-latest' | |
shell: pwsh # Windows | |
run: ./gradlew.bat --stop | |
publish-release: | |
name: Publish Pre-Release | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
permissions: | |
contents: write | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts/ | |
- name: Create Pre-Release and Upload Assets | |
uses: softprops/action-gh-release@v2 | |
with: | |
prerelease: true | |
files: | | |
artifacts/**/*.dmg | |
artifacts/**/*.msi | |
artifacts/**/*.deb | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |