发布软件 #157
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: 发布软件 | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- '**/*.md' | |
- '**/*.yml' | |
- .gitignore | |
- .editorconfig | |
permissions: write-all # 给所有工作写权限 | |
jobs: | |
jobs_v: | |
name: 构建版本号和变更信息 | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.create_version.outputs.tag_name }} # 版本号 | |
body: ${{ steps.create_version.outputs.body }} # 版本变更内容 | |
newBody: ${{ steps.setOutput.outputs.newBody }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: 更新描述文件 | |
shell: bash | |
run: | | |
pwd | |
git log --pretty=format:"%an | %s | %h | %ad | %H" --date=format:'%Y-%m-%d %H:%M' -n 10 | |
git describe --tags --abbrev=0 | |
git log --pretty=format:"%an | %s | %h | %ad | %H" --date=format:'%Y-%m-%d %H:%M' $(git describe --tags --abbrev=0)^..HEAD | |
cd ./citool/gitLogSum/ | |
chmod 777 ./gitLogSum | |
./gitLogSum > updateLog.md | |
cat updateLog.md | |
echo "::set-output name=newBody::$(cat updateLog.md)" | |
- name: 检查是否 "发布" | |
run: | | |
latest_commit_message=$(git log -1 --pretty=%B) | |
if [[ $latest_commit_message == *"发布"* ]]; then | |
echo "找到发布关键字继续工作流" | |
else | |
echo "没有找到发布关键字停止工作流" | |
exit 1 # 停止工作流程 | |
fi | |
- uses: release-drafter/release-drafter@v5 | |
id: create_version | |
with: | |
config-name: release-drafter.yml # 配置文件在 .github/release-drafter.yml | |
disable-autolabeler: false # 禁止自动标签 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: 查看变量 | |
run: | | |
echo ${{ format('version={0}', steps.create_version.outputs.tag_name ) }} | |
echo "New Body: ${{ steps.setOutput.outputs.newBody }}" | |
jobs_macos: | |
# 暂停 | |
#if: false | |
needs: [ jobs_v ] | |
name: 构建macos软件 | |
runs-on: macos-12 | |
env: | |
version: ${{ needs.jobs_v.outputs.version }} | |
body: ${{ needs.jobs_v.outputs.body }} | |
newBody: ${{ needs.jobs_v.outputs.newBody }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: 构建缓存 | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/Users/runner/.npm | |
key: ${{ runner.os }}-js-${{ hashFiles('**/package.json') }} | |
restore-keys: | | |
${{ runner.os }}-js- | |
- name: 查看文件 | |
run: | | |
pwd | |
ls -la | |
echo "New Body: ${{ env.newBody }}" | |
- name: 安装 go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '^1.21.0' | |
cache-dependency-path: | | |
**/go.sum | |
**/go.mod | |
go-version-file: 'go.mod' | |
- run: go version | |
- name: 安装 wails 工具 | |
run: | | |
go install github.com/wailsapp/wails/v2/cmd/wails@latest | |
wails | |
- name: 生成 Version.go 文件 | |
run: | | |
echo -e "package mymodel\n\nvar Version = \"${version}\"" > GoEasyDesigner/mymodel/Version.go | |
cat GoEasyDesigner/mymodel/Version.go | |
- name: 编译 | |
run: | | |
pwd | |
cd GoEasyDesigner | |
wails build | |
ls -la | |
- name: 查看编译的文件保存 | |
run: | | |
ls -la | |
mkdir -p /tmp/artifacts | |
cp -r GoEasyDesigner/build/bin/GoEasyDesigner.app /tmp/artifacts/GoEasyDesigner.app | |
cp -r GoEasyDesigner/build/dmg.sh /tmp/artifacts/dmg.sh | |
chmod +x /tmp/artifacts/GoEasyDesigner.app/Contents/MacOS/GoEasyDesigner | |
- name: 创建压缩包 | |
run: | | |
cd /tmp/artifacts/ | |
./dmg.sh | |
zip -r ./GoEasyDesigner_MacOS.zip ./GoEasyDesigner.app | |
- name: 上传产物 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: macos | |
path: | | |
/tmp/artifacts/*.zip | |
/tmp/artifacts/*.dmg | |
jobs_window: | |
needs: jobs_v # 等待 jobs_v 任务完成才执行 | |
name: 构建window软件 | |
timeout-minutes: 20 | |
runs-on: windows-2022 | |
env: | |
version: ${{ needs.jobs_v.outputs.version }} | |
body: ${{ needs.jobs_v.outputs.body }} | |
newBody: ${{ needs.jobs_v.outputs.newBody }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: 构建缓存 | |
uses: actions/cache@v3 | |
with: | |
path: | | |
C:\npm\cache | |
key: ${{ runner.os }}-js-${{ hashFiles('**/package.json') }} | |
restore-keys: | | |
${{ runner.os }}-js- | |
- name: 读入环境信息 | |
run: | | |
echo ${{ format('version {0}', env.version ) }} # 版本号 | |
- name: 安装 go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '^1.21.0' | |
cache-dependency-path: | | |
**/go.sum | |
**/go.mod | |
go-version-file: 'go.mod' | |
- run: go version | |
- name: 安装 UPX | |
uses: crazy-max/ghaction-upx@v2 | |
with: | |
install-only: true | |
- name: 安装 wails 工具 | |
run: | | |
go install github.com/wailsapp/wails/v2/cmd/wails@latest | |
wails | |
- name: 生成 Version.go 文件 | |
shell: bash | |
run: | | |
echo -e "package mymodel\n\nvar Version = \"${version}\"" > GoEasyDesigner/mymodel/Version.go | |
cat GoEasyDesigner/mymodel/Version.go | |
- name: 编译exe | |
run: | | |
cd GoEasyDesigner | |
wails build -webview2 embed -upx | |
ls | |
- name: 上传产物 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: window | |
path: | | |
GoEasyDesigner/build/bin/*.exe | |
jobs4: | |
needs: [ jobs_v,jobs_macos,jobs_window ] | |
name: 发布版本 | |
runs-on: ubuntu-latest | |
env: | |
version: ${{ needs.jobs_v.outputs.version }} | |
body: ${{ needs.jobs_v.outputs.body }} | |
newBody: ${{ needs.jobs_v.outputs.newBody }} | |
steps: | |
- name: 下载产物 | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
path: ./ | |
- name: 读入环境信息 | |
run: | | |
echo ${{ format('version {0}', env.version ) }} | |
echo ${{steps.download.outputs.download-path}} | |
ls -R | |
- name: 发布文件 | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
allowUpdates: true # 覆盖文件 | |
#draft: true # 草稿 自己可见 版本号会保持一样 默认是自动发布 latest | |
#prerelease: true # 预发布 别人可以看到 版本号会继续加 | |
tag: ${{ env.version }} # 版本号 v0.1.0 | |
body: ${{ env.newBody }} # 输出的内容 | |
artifacts: "macos/*.zip,macos/*.dmg,window/*.exe,window/*.zip" | |