Skip to content

initial 初始化

initial 初始化 #2

Workflow file for this run

name: initial 初始化
on:
workflow_dispatch:
inputs:
id:
description: '请输入模块id,例如Zygisk_shamiko'
required: true
name:
description: '请输入模块名,例如shamiko'
required: true
author:
description: '作者名'
required: true
description:
description: '模块描述'
required: true
jobs:
init:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
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: Get Version 获取版本
id: get_version
run: |
echo "date=$(date +%Y%m%d)" >> "$GITHUB_ENV"
- name: 获取仓库 URL
id: get_repo_url
run: |
echo "repo_url=https://github.com/${{ github.repository }}" >> "$GITHUB_ENV"
- name: Add the id key in the file 将模块id写入模块配置文件
run: |
echo "id=${{ github.event.inputs.id }}" > MyModule/module.prop
echo "id=${{ github.event.inputs.id }}" >> $GITHUB_ENV
- name: Add the name key in the file 将模块名写入模块配置文件
run: |
echo "name=${{ github.event.inputs.name }}" >> MyModule/module.prop
echo "name=${{ github.event.inputs.name }}" >> $GITHUB_ENV
- name: Add the version key in the file 将模块初始版本0.0.0写入模块配置文件
run: |
echo "version=0.0.0" >> MyModule/module.prop
echo "version=0.0.0" >> $GITHUB_ENV
- name: Add the version code key in the file 将版本代码写入模块配置文件
run: |
echo "versionCode=${{ env.date }}" >> MyModule/module.prop
echo "versionCode=${{ env.date }}" >> $GITHUB_ENV
- name: Add the author key in the file 将作者写入模块配置文件
run: |
echo "author=${{ github.event.inputs.author }}" >> MyModule/module.prop
echo "author=${{ github.event.inputs.author }}" >> $GITHUB_ENV
- name: Add the description key in the file 将描述写入模块配置文件
run: |
echo "description=${{ github.event.inputs.description }}" >> MyModule/module.prop
echo "description=${{ github.event.inputs.description }}" >> $GITHUB_ENV
- name: Add the updateJson key in the file 将更新链接写入模块配置文件
run: |
echo "updateJson=http://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/update.json" >> MyModule/module.prop
echo "updateJson=http://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/update.json" >> $GITHUB_ENV
- name: List files for debug 让我看看运行情况
run: |
ls -la
cd MyModule
ls -la
cd ..
- name: init__update.json 初始化更新用的json文件
run: |
echo "" > update.json
cat <<EOF > update.json
{
"version": "${{ env.version }}",
"versionCode": "${{ env.date }}",
"zipUrl": "${{ env.repo_url }}/releases/download/${{ env.version }}/${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }}.zip",
"changelog": "${{ env.repo_url }}/raw/${{ github.ref_name }}/CHANGELOG.md"
}
EOF
- name: init__CHANGELOG.md 初始化更新记录文件
run: |
echo "" > CHANGELOG.md
echo -e "# Changelog 0.0.0\n\n1. 恭喜你成功创建了一个 KernelSU/Aptch/Magisk 模块项目\n2. 这是一个示例\n" >> CHANGELOG.md
- name: Configure Git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
- name: Debugging Output 调试一下
run: |
git status
git log -1
# 即便没有任何改动也不会报错,方便debug
- name: Check for changes
run: |
if git diff-index --quiet HEAD --; then
echo "skip=true" >> $GITHUB_ENV
fi
- name: Commit changes
if: env.skip != 'true'
run: |
git config --global user.name "GitHub Action"
git add update.json CHANGELOG.md MyModule/module.prop
git commit -m "Automated commit by GitHub Action"
- 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 # 如果使用这个,确保 generate_release_notes 不启用
files: |
${{ env.name }}-${{ env.version }}-${{ env.versionCode }}-by${{ env.author }}.zip
fail_on_unmatched_files: false # 如果文件匹配失败不会导致工作流失败
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}