forked from mihomo-party-org/mihomo-party
-
Notifications
You must be signed in to change notification settings - Fork 53
175 lines (155 loc) · 5.53 KB
/
build.yml
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Build
permissions: write-all
on:
workflow_dispatch:
inputs:
version:
description: "Tag version to release"
required: false
push:
branches:
- master
tags:
- v*
paths-ignore:
- 'README.md'
- '.github/ISSUE_TEMPLATE/**'
- '.github/workflows/issues.yml'
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [macos-latest]
arch: [arm64]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
run: npm install -g pnpm
- name: Determine and Update Version
shell: bash
run: |
GIT_COMMIT_HASH=$(git rev-parse --short HEAD)
VERSION=$(jq -r '.version' package.json)
if [ "${{ github.event.inputs.version }}" == "" ]; then
BASE_VERSION=$(echo $VERSION | awk -F. '{print $1"."$2"."$3+1}')
VERSION_PREFIX=${VERSION_PREFIX:-beta}
RELEASE_VERSION="${BASE_VERSION}-${VERSION_PREFIX}-${GIT_COMMIT_HASH}"
else
INPUT_VERSION="${{ github.event.inputs.version }}"
CLEAN_VERSION=$(echo "$INPUT_VERSION" | sed 's/^v//')
if [[ ! "$CLEAN_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $INPUT_VERSION"
exit 1
fi
RELEASE_VERSION="$CLEAN_VERSION"
fi
jq --arg version "$RELEASE_VERSION" '.version = $version' package.json > tmp.json && mv tmp.json package.json
- name: Install Dependencies and Prepare
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: |
pnpm install
pnpm add @mihomo-party/sysproxy-${{ matrix.os == 'windows-latest' && 'win32' || matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}-${{ matrix.arch }}${{ matrix.os == 'ubuntu-latest' && '-gnu' || matrix.os == 'windows-latest' && '-msvc' || '' }}
pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: |
chmod +x build/pkg-scripts/postinstall
pnpm build:${{ matrix.os == 'windows-latest' && 'win' || matrix.os == 'ubuntu-latest' && 'linux' || 'mac' }} --${{ matrix.arch }}
- name: Add Portable Flag
if: matrix.os == 'windows-latest'
run: |
New-Item -Path "PORTABLE" -ItemType File
Get-ChildItem dist/*portable.7z | ForEach-Object {
7z a $_.FullName PORTABLE
}
- name: Generate latest.yml
run: pnpm updater
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}
path: |
dist/mihomo-party-*
latest.yml
changelog.md
pre-release:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: bin/
merge-multiple: true
# - name: Delete Current
# uses: 8Mi-Tech/delete-release-assets-action@main
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# tag: pre-release
# deleteOnlyFromDrafts: true
- name: Delete Pre-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release list
gh release delete pre-release --yes
git log -1 --pretty=format:"%s%n%b" > changelog.md
- name: Publish Prerelease
if: success()
uses: softprops/action-gh-release@v2
with:
tag_name: pre-release
body_path: changelog.md
files: |
bin/latest.yml
bin/dist/*
prerelease: true
release:
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.version != '')
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Version
run: |
INPUT_VERSION="${{ github.event.inputs.version }}"
CLEAN_VERSION=$(echo "$INPUT_VERSION" | sed 's/^v//')
if [[ ! "$CLEAN_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $INPUT_VERSION"
exit 1
fi
jq --arg version "$CLEAN_VERSION" '.version = $version' package.json > tmp.json && mv tmp.json package.json
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add package.json
git commit -m "Update version to $CLEAN_VERSION"
git push
- uses: actions/download-artifact@v4
with:
path: bin/
merge-multiple: true
- name: Delete Current
uses: 8Mi-Tech/delete-release-assets-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.version != '' && github.event.inputs.version || github.ref }}
deleteOnlyFromDrafts: false
- name: Publish Release
if: success()
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.version != '' && github.event.inputs.version || github.ref }}
body_path: bin/changelog.md
files: |
bin/latest.yml
bin/dist/*