Repository navigation
141 lines (124 loc) · 4.31 KB
/
Copy pathrelease.yml
File metadata and controls
141 lines (124 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Build and Release with Python3.13
on:
release:
types: [published]
push:
tags:
- 220*
workflow_dispatch:
inputs:
tag:
description: "Tag"
required: true
prerelease:
description: "是否作为预发布(pre-release)"
required: false
default: "false"
jobs:
init-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
# https://github.com/actions/runner/issues/1985#issuecomment-1573518052
- name: Set matrix
id: set-matrix
run: |
items=()
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners
items+=('{"build": "macos", "os": "macos-latest", "arch": "aarch64"}')
items+=('{"build": "windows", "os": "windows-latest", "arch": "x86_64"}')
# 合并items到json数组
matrix="matrix=["
for ((i=0; i<${#items[@]}; i++)); do
matrix+=" ${items[i]}"
if ((i != ${#items[@]}-1)); then
matrix+=","
fi
done
matrix+="]"
# 输出matrix到GITHUB_OUTPUT
echo $matrix >> $GITHUB_OUTPUT
build-app:
needs: init-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.init-matrix.outputs.matrix)}}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
activate-environment: true
- name: Set up python env
run: uv sync --locked --all-extras --dev
- name: Build macOS app - macOS
if: ${{ matrix.build == 'macos' }}
run: |
version="${{ github.ref_name }}"
# 如果是手动触发,则使用输入的tag
if [ -n "${{ github.event.inputs.tag }}" ]; then
version="${{ github.event.inputs.tag }}"
fi
uv run scripts/build.py --create-dmg --version "$version" --debug
- name: Build Windows app - Windows
if: ${{ matrix.build == 'windows' }}
env:
PYTHONIOENCODING: utf-8
run: uv run scripts/build.py --debug
- name: Get changelog
id: get-changelog
shell: bash
run: |
if [ ! -s changelog.md ]; then
echo "changelog.md 不存在或为空,无法生成 Release 说明。"
exit 1
fi
delimiter="__MDCX_CHANGELOG_EOF__"
{
echo "CHANGELOG<<$delimiter"
cat changelog.md
echo
echo "$delimiter"
} >> "$GITHUB_OUTPUT"
- name: Resolve release type
id: release-type
shell: bash
run: |
prerelease=false
if [ "${{ github.event_name }}" = "release" ]; then
prerelease="${{ github.event.release.prerelease }}"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.prerelease }}" = "true" ]; then
prerelease=true
fi
echo "prerelease=$prerelease" >> $GITHUB_OUTPUT
- name: Create Release - macOS
uses: svenstaro/upload-release-action@v2
if: ${{ matrix.build == 'macos' }}
with:
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}-${{ github.sha }}.dmg
file: dist/MDCx.dmg
prerelease: ${{ steps.release-type.outputs.prerelease }}
body: ${{ steps.get-changelog.outputs.CHANGELOG }}
tag: ${{ github.event.inputs.tag || github.ref }}
- name: Create Release - Windows
uses: svenstaro/upload-release-action@v2
if: ${{ matrix.build == 'windows' }}
with:
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}-${{ github.sha }}.exe
file: dist/MDCx.exe
prerelease: ${{ steps.release-type.outputs.prerelease }}
body: ${{ steps.get-changelog.outputs.CHANGELOG }}
tag: ${{ github.event.inputs.tag || github.ref }}