Build and Release #30
Workflow file for this run
This file contains 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
name: Build and Release | |
on: | |
workflow_dispatch: # 手动触发工作流 | |
jobs: | |
check_version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 检出代码 | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # 拉取所有标签和完整历史 | |
- name: 获取最新发布版本标签 | |
id: get_release_tag | |
run: | | |
RESPONSE=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest") | |
RELEASE_TAG=$(echo "${RESPONSE}" | jq -r .tag_name) | |
echo "最新发布的版本标签: ${RELEASE_TAG}" | |
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV # 设置环境变量 | |
- name: 获取 myLazyNoSo 分支的最新标签 | |
id: get_my_lazy_tag | |
run: | | |
git fetch --tags # 确保获取所有标签 | |
TAGS=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags | grep -E '^v' | head -n 1) | |
echo "myLazyNoSo 分支的最新标签: ${TAGS}" | |
echo "TAGS=${TAGS}" >> $GITHUB_ENV # 设置环境变量 | |
- name: 比较版本标签 | |
id: compare_versions | |
run: | | |
echo "比较版本: RELEASE_TAG=${{ env.RELEASE_TAG }}, TAGS=${{ env.TAGS }}" | |
if [[ "${{ env.RELEASE_TAG }}" != "${{ env.TAGS }}" ]]; then | |
echo "版本不同: 发布版本标签 (${{ env.RELEASE_TAG }}) 和 myLazyNoSo 分支标签 (${{ env.TAGS }}) 不同,开始打包" | |
echo "should_build=true" >> $GITHUB_ENV | |
else | |
echo "版本相同: 发布版本标签 (${{ env.RELEASE_TAG }}) 和 myLazyNoSo 分支标签 (${{ env.TAGS }}) 相同,无需发版" | |
echo "should_build=false" >> $GITHUB_ENV | |
fi | |
- name: 获取更新日志 | |
if: env.should_build == 'true' | |
id: get_changelog | |
run: | | |
# 获取两个标签之间的提交日志,并将换行符转换为空格 | |
CHANGELOG=$(git log ${{ env.RELEASE_TAG }}..${{ env.TAGS }} --pretty=format:"%s" | tr '\n' ' ') | |
echo "更新日志: $CHANGELOG" | |
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV # 将日志存储为单行 | |
- name: 安装 JDK 11 | |
if: env.should_build == 'true' | |
run: | | |
sudo apt update | |
sudo apt install -y openjdk-11-jdk | |
- name: 验证 JDK 安装 | |
if: env.should_build == 'true' | |
run: | | |
java -version | |
- name: 下载并安装 Gradle | |
if: env.should_build == 'true' | |
run: | | |
wget https://services.gradle.org/distributions/gradle-7.6-bin.zip | |
unzip gradle-7.6-bin.zip | |
sudo mv gradle-7.6 /opt/gradle | |
sudo ln -s /opt/gradle/bin/gradle /usr/local/bin/gradle | |
- name: 验证 Gradle 安装 | |
if: env.should_build == 'true' | |
run: | | |
gradle -v | |
- name: 添加执行权限到 gradlew | |
if: env.should_build == 'true' | |
run: | | |
chmod +x ./gradlew # 给 gradlew 文件添加执行权限 | |
- name: 打包 myLazyNoSo 分支 (Gradle) | |
if: env.should_build == 'true' | |
run: | | |
echo "开始打包 myLazyNoSo 分支..." | |
./gradlew clean assembleCompatibleRelease | |
- name: 选择最新的 APK 文件 | |
if: env.should_build == 'true' | |
id: select_latest_apk | |
run: | | |
LATEST_APK=$(ls -t APK/Release/*.apk | head -n 1) | |
echo "最新的 APK 文件: $LATEST_APK" | |
echo "LATEST_APK=$LATEST_APK" >> $GITHUB_ENV | |
- name: 发布到 GitHub | |
if: env.should_build == 'true' | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.RELEASE_TAG }} | |
name: "XQE_lazy_${{ env.TAGS }}" # 自定义发布标题 | |
body: ${{ env.CHANGELOG }} # 更新日志 | |
files: ${{ env.LATEST_APK }} # 发布最新的 APK 文件 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |