release #58
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: release | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Release Tag (就填版本号)' | |
required: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4.1.0 | |
with: | |
ref: modules | |
path: modules | |
- uses: actions/checkout@v4.1.0 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Manage large files with Git LFS | |
run: | | |
# 安装 Git LFS | |
git lfs install | |
# 拉取 LFS 文件 | |
git lfs pull | |
# 找到 MyModule 目录下超过 100MB 的文件并通过 Git LFS 进行跟踪 | |
find MyModule/ -type f -size +100M | while read -r file; do | |
git lfs track "$file" | |
done | |
# 添加 .gitattributes 文件和所有被 LFS 跟踪的文件到暂存区 | |
git add .gitattributes | |
git add $(git lfs ls-files -n) | |
# 提交更改 | |
git commit -m "Track large files with Git LFS" || echo "No changes to commit" | |
- name: 获取仓库 URL | |
id: get_repo_url | |
run: | | |
echo "repo_url=https://github.com/${{ github.repository }}" >> "$GITHUB_ENV" | |
- name: 获取版本 | |
id: get_version | |
run: | | |
echo "date=$(date +%Y%m%d)" >> "$GITHUB_ENV" | |
- name: Extract variables from module.prop 获取一些变量的值,以便后续调用 | |
id: extract_vars | |
run: | | |
# 提取变量并保存到环境变量中 | |
id=$(awk -F= '/id=/ {print $2}' MyModule/module.prop) | |
name=$(awk -F= '/name=/ {print $2}' MyModule/module.prop) | |
version=$(awk -F= '/version=/ {print $2}' MyModule/module.prop) | |
versionCode=$(awk -F= '/versionCode=/ {print $2}' MyModule/module.prop) | |
author=$(awk -F= '/author=/ {print $2}' MyModule/module.prop) | |
description=$(awk -F= '/description=/ {print $2}' MyModule/module.prop) | |
updateJson=$(awk -F= '/updateJson=/ {print $2}' MyModule/module.prop) | |
# 检查提取的变量是否为空,并输出提示信息 | |
if [ -z "$id" ] || [ -z "$name" ] || [ -z "$version" ] || [ -z "$versionCode" ] || [ -z "$author" ] || [ -z "$description" ] || [ -z "$updateJson"]; then | |
echo "请先执行 initial 工作流以生成 module.prop 文件" | |
exit 1 | |
fi | |
# 保存变量到环境文件 | |
echo "id=${id}" >> $GITHUB_ENV | |
echo "name=${name}" >> $GITHUB_ENV | |
echo "version-old=${version}" >> $GITHUB_ENV | |
echo "versionCode-old=${versionCode}" >> $GITHUB_ENV | |
echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_ENV | |
echo "versionCode=${{ env.date }}" >> $GITHUB_ENV | |
echo "author=${author}" >> $GITHUB_ENV | |
echo "description=${description}" >> $GITHUB_ENV | |
echo "updateJson=${updateJson}" >> $GITHUB_ENV | |
- name: 调试变量 | |
run: | | |
echo "版本: ${{ env.version }}" | |
echo "版本号: ${{ env.versionCode }}" | |
echo "旧版本: ${{ env.version-old }}" | |
echo "旧版本号: ${{ env.versionCode-old }}" | |
echo "日期: ${{ env.date }}" | |
echo "作者: ${{ env.author }}" | |
- name: Check if updates are needed & 更新 update.json 和 module.prop | |
run: | | |
if [ "${{ env.version }}" != "${{ env.version-old }}" ]; then | |
echo "Version needs update." | |
sed -i "s/${{ env.version-old }}/${{ env.version }}/g" "MyModule/module.prop" | |
fi | |
if [ "${{ env.versionCode }}" != "${{ env.versionCode-old }}" ]; then | |
echo "VersionCode needs update." | |
sed -i "s/${{ env.versionCode-old }}/${{ env.date }}/g" "MyModule/module.prop" | |
fi | |
# 即便没有任何改动也不会报错,方便debug | |
- name: Check for changes | |
run: | | |
if git diff-index --quiet HEAD --; then | |
echo "No changes to commit." | |
echo "skip=true" >> $GITHUB_ENV | |
exit 0 | |
fi | |
- name: Commit changes | |
if: env.skip != 'true' | |
run: | | |
git config --global user.name "GitHub Action" | |
git config --global user.email "action@github.com" | |
git add update.json MyModule/module.prop | |
git commit -m "更新 update.json和module.prop" | |
- name: Push changes | |
if: env.skip != 'true' | |
run: git push origin ${{ github.ref_name }} | |
- name: Package module 打包模块 | |
run: | | |
# 打包模块 | |
cd MyModule && zip -r "${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }}.zip" * && mv *.zip .. && cd .. | |
- name: Create GitHub Release 发布模块 | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.version }} | |
name: "${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }} 模块现已发布" | |
body_path: CHANGELOG.md | |
files: | | |
${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }}.zip | |
generate_release_notes: false # 使用changeloge.md的内容 | |
fail_on_unmatched_files: false # 如果文件匹配失败不会导致工作流失败 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: upload 上传(需要设置token/可选) | |
if: env.UPSTREAM_ACCESS_TOKEN != '' | |
run: | | |
# 推送到母仓库 | |
git status | |
git checkout -b modules | |
git pull upstream module --rebase | |
git remote add upstream https://github.com/LIghtJUNction/KernelSu-Module-Model-.git | |
git add ${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }}.zip | |
git commit -m "模块共享" | |
git push upstream module | |
env: | |
UPSTREAM_ACCESS_TOKEN: ${{ secrets.UPSTREAM_ACCESS_TOKEN }} | |
# 用于身份验证的 token | |
- name: Notify if UPSTREAM_ACCESS_TOKEN is missing 提醒下你,不喜欢可以删掉 | |
if: env.UPSTREAM_ACCESS_TOKEN == '' | |
run: | | |
echo "UPSTREAM_ACCESS_TOKEN is missing. Creating an issue to notify you:)." | |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d '{"title":"UPSTREAM_ACCESS_TOKEN Missing","body":"The UPSTREAM_ACCESS_TOKEN 缺失,(运行工作流发布模块的时候)如果你想要在发布模块的同时,上传到母仓库,请在设置界面填写UPSTREAM_ACCESS_TOKEN,如果你不想上传,忽略即可:)"}' \ | |
https://api.github.com/repos/${{ github.repository }}/issues |