-
Notifications
You must be signed in to change notification settings - Fork 2
145 lines (125 loc) · 4.57 KB
/
ymu_auto_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
143
144
145
# This workflow will install Python dependencies, run tests, build an executable then upload it to github releases
name: YMU Automatic Release
on:
push:
paths:
- "ymu.py"
jobs:
build:
runs-on: windows-latest
name: Build YMU
outputs:
full_sha: ${{ steps.var.outputs.full_sha }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pyinstaller
pip install -r requirements.txt
- name: Verify With Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build Executable
run: |
pyinstaller "ymu.py" --noconfirm --onefile --windowed --noconsole --icon "./assets/icon/ymu.ico" --splash "./assets/splash.png" --add-data "./assets/;assets/" --version-file "./version.txt"
- name: Generate Build Info
id: var
run: |
echo "full_sha=$(git rev-parse HEAD)" >> $env:GITHUB_OUTPUT
echo "short_sha=$(git rev-parse --short HEAD)" >> $env:GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: binary
path: |
dist\ymu.exe
create_release:
runs-on: ubuntu-latest
name: Delete Old Release
needs: build
steps:
- uses: actions/checkout@v4
- name: Delete Old Release
id: delete_ex_release
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// List all releases
const releases = await github.rest.repos.listReleases({
owner: owner,
repo: repo,
});
// Iterate over each release and delete it
for (const release of releases.data) {
await github.rest.repos.deleteRelease({
owner: owner,
repo: repo,
release_id: release.id,
});
console.log(`Deleted release with ID ${release.id}`);
}
// List all tags
const tags = await github.rest.repos.listTags({
owner: owner,
repo: repo,
});
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: binary
- name: Increment Version
id: increment_version
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// Get the latest tag
const tags = await github.rest.repos.listTags({
owner: owner,
repo: repo,
});
let newVersion;
let oldTag;
if (tags.data.length === 0) {
// No tags found, start with a default version
console.log('No existing tags found. Starting with version v1.0.1');
newVersion = 'v1.0.1';
} else {
// Extract the latest tag name
const latestTag = tags.data[0].name;
const versionParts = latestTag.substring(1).split('.').map(Number);
versionParts[2] += 1; // Increment the patch version
newVersion = `v${versionParts.join('.')}`;
oldTag = latestTag;
}
core.setOutput("new_version", newVersion);
core.setOutput("old_tag", oldTag);
- name: Echo build_sha256
id: build_sha
run: |
sha256sum ymu.exe > sha256.checksum
echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT
cat sha256.checksum
- name: Upload Release
uses: softprops/action-gh-release@v2
with:
name: YMU ${{ steps.increment_version.outputs.new_version }}
tag_name: ${{ steps.increment_version.outputs.new_version }}
body: |
>[!NOTE]
>**This automatic release was built by Github Actions**
>| [Link to build](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
>| ------------- |
files: |
ymu.exe