Build and Release #22
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: Check and Notify Version | |
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: 安装 Gradle 和 JDK | |
if: env.should_build == 'true' | |
run: | | |
sudo apt update | |
sudo apt install -y openjdk-11-jdk | |
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 | |
gradle -v | |
- name: 打包 myLazyNoSo 分支 (Gradle) | |
if: env.should_build == 'true' | |
run: | | |
echo "开始打包 myLazyNoSo 分支..." | |
./gradlew clean assembleCompatibleRelease | |
- name: 获取更新日志 | |
if: env.should_build == 'true' | |
id: get_changelog | |
run: | | |
# 获取两个标签之间的提交日志 | |
CHANGELOG=$(git log ${{ env.RELEASE_TAG }}..${{ env.TAGS }} --pretty=format:"* %s" | sed 's/^/ - /') | |
echo "更新日志:" | |
echo "${CHANGELOG}" | |
echo "CHANGELOG=${CHANGELOG}" >> $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: build/outputs/apk/compatible/release/*.apk # 更新为实际生成的 APK 路径 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |