-
Notifications
You must be signed in to change notification settings - Fork 3
142 lines (123 loc) · 4.09 KB
/
build_release.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
name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build-and-release:
strategy:
matrix:
include:
- os: ubuntu-latest
platform: Linux
- os: windows-latest
platform: Windows
- os: macos-latest
platform: macOS
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensures full Git history is checked out
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Build executables (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
for script in SetDNS.py SetHosts-IPv4.py SetHosts.py; do
pyinstaller --onefile "$script"
mv "dist/${script%.py}" "dist/${script%.py}-Linux-x64"
done
zip -j "cnNetTool-Linux-x64.zip" dist/*-Linux-x64
- name: Fix file permissions
run: |
chmod -R 755 ./dist
- name: Build executables (Windows)
if: matrix.os == 'windows-latest'
run: |
$scripts = @("SetDNS.py", "SetHosts-IPv4.py", "SetHosts.py")
if (Test-Path -Path "dist") {
Remove-Item -Recurse -Force "dist"
}
foreach ($script in $scripts) {
pyinstaller --onefile $script --uac-admin
$exeName = $script -replace '\.py$', ''
Move-Item "dist\$exeName.exe" "dist\$exeName-Windows-x64.exe"
}
Compress-Archive -Path dist\*-Windows-x64.exe -DestinationPath "cnNetTool-Windows-x64.zip"
shell: pwsh
- name: Build executables (macOS)
if: matrix.os == 'macos-latest'
run: |
for script in SetDNS.py SetHosts-IPv4.py SetHosts.py; do
pyinstaller --onefile "$script"
mv "dist/${script%.py}" "dist/${script%.py}-macOS-x64"
done
zip -j "cnNetTool-macOS-x64.zip" dist/*-macOS-x64
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.platform }}-executables
path: |
cnNetTool-Linux-x64.zip
cnNetTool-Windows-x64.zip
cnNetTool-macOS-x64.zip
create-release:
needs: build-and-release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensures full Git history is checked out
- name: Download all artifacts
uses: actions/download-artifact@v3
- name: Get tag description
id: tag_description
run: |
TAG_DESCRIPTION=$(git tag -l --format='%(contents)' ${{ github.ref_name }})
echo "tag_description=${TAG_DESCRIPTION}" >> $GITHUB_OUTPUT
shell: bash
- name: Get latest commit message
id: commit_message
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "commit_message=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
shell: bash
- name: Delete existing release if exists
run: |
RELEASE_ID=$(gh release view ${{ github.ref_name }} --json id --jq '.id' || echo "")
if [ -n "$RELEASE_ID" ]; then
gh release delete ${{ github.ref_name }} --yes
echo "Release deleted: ${{ github.ref_name }}"
else
echo "No existing release found for: ${{ github.ref_name }}"
fi
shell: bash
- name: List Files
run: ls -R ./
shell: bash
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ github.ref_name }} \
--title "${{ github.ref_name }} ${{ steps.tag_description.outputs.tag_description }}" \
--notes "Release for ${{ github.ref_name }}
Changes in this release:
${{ steps.commit_message.outputs.commit_message }}" \
--draft=false \
**/cnNetTool-Linux-x64.zip
**/cnNetTool-Windows-x64.zip
**/cnNetTool-macOS-x64.zip
shell: bash