1- name : Build and Release
2-
3- on :
4- push :
5- tags :
6- - ' v*.*.*' # Trigger the workflow on version tags
7-
8- jobs :
9- release :
10- runs-on : ubuntu-20.04
11-
12- steps :
13- - name : Checkout code
14- uses : actions/checkout@v2
15-
16- - name : Zip source code
17- run : |
18- zip -r source_code.zip .
19-
20- - name : Create release
21- id : create_release
22- uses : actions/create-release@v1
23- env :
24- GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
25- with :
26- tag_name : ${{ github.ref }}
27- release_name : Release ${{ github.ref }}
28- draft : false
29- prerelease : false
30-
31- - name : Upload Release Asset
32- uses : actions/upload-release-asset@v1
33- env :
34- GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
35- with :
36- upload_url : ${{ steps.create_release.outputs.upload_url }}
37- asset_path : source_code.zip
38- asset_name : source_code.zip
39- asset_content_type : application/zip
1+ name : Build and Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+
8+ jobs :
9+ build-standard :
10+ name : Build on ${{ matrix.name }}
11+ runs-on : ${{ matrix.os }}
12+ strategy :
13+ fail-fast : false
14+ matrix :
15+ include :
16+ - os : windows-latest
17+ name : Windows
18+ binary_name : snmp-discovery-windows
19+ asset_name : snmp-discovery-windows.exe
20+ - os : ubuntu-22.04
21+ name : Debian
22+ binary_name : snmp-discovery-debian
23+ asset_name : snmp-discovery-debian
24+
25+ steps :
26+ - uses : actions/checkout@v4
27+
28+ - name : Set up Python
29+ uses : actions/setup-python@v5
30+ with :
31+ python-version : ' 3.12'
32+
33+ - name : Install dependencies
34+ run : |
35+ python -m pip install --upgrade pip
36+ pip install -r requirements.txt
37+ pip install pyinstaller
38+
39+ - name : Build with PyInstaller
40+ run : |
41+ pyinstaller --onefile --name ${{ matrix.binary_name }} main.py
42+
43+ - name : Upload Artifacts
44+ uses : actions/upload-artifact@v4
45+ with :
46+ name : ${{ matrix.binary_name }}
47+ path : dist/
48+
49+ build-rhel :
50+ name : Build on RHEL
51+ runs-on : ubuntu-latest
52+ container :
53+ image : rockylinux:9
54+
55+ steps :
56+ - uses : actions/checkout@v4
57+
58+ - name : Install Python and dependencies
59+ run : |
60+ dnf install -y python3.11 python3.11-pip python3.11-devel gcc binutils
61+ python3.11 -m pip install --upgrade pip
62+ python3.11 -m pip install -r requirements.txt
63+ python3.11 -m pip install pyinstaller
64+
65+ - name : Build with PyInstaller
66+ run : |
67+ python3.11 -m PyInstaller --onefile --name snmp-discovery-rhel main.py
68+
69+ - name : Upload Artifacts
70+ uses : actions/upload-artifact@v4
71+ with :
72+ name : snmp-discovery-rhel
73+ path : dist/
74+
75+ release :
76+ needs : [build-standard, build-rhel]
77+ runs-on : ubuntu-latest
78+ permissions :
79+ contents : write
80+
81+ steps :
82+ - uses : actions/checkout@v4
83+
84+ - name : Download Windows artifact
85+ uses : actions/download-artifact@v4
86+ with :
87+ name : snmp-discovery-windows
88+ path : dist/windows/
89+
90+ - name : Download Debian artifact
91+ uses : actions/download-artifact@v4
92+ with :
93+ name : snmp-discovery-debian
94+ path : dist/debian/
95+
96+ - name : Download RHEL artifact
97+ uses : actions/download-artifact@v4
98+ with :
99+ name : snmp-discovery-rhel
100+ path : dist/rhel/
101+
102+ - name : Prepare assets
103+ run : |
104+ mkdir -p release
105+ cp dist/windows/snmp-discovery-windows.exe release/ 2>/dev/null || cp dist/windows/snmp-discovery-windows release/snmp-discovery-windows.exe
106+ cp dist/debian/snmp-discovery-debian release/
107+ cp dist/rhel/snmp-discovery-rhel release/
108+ chmod +x release/snmp-discovery-debian release/snmp-discovery-rhel
109+ zip -r release/source-code.zip . -x ".git/*" -x "dist/*" -x "release/*" -x "build/*" -x "__pycache__/*"
110+ ls -la release/
111+
112+ - name : Create Release
113+ uses : softprops/action-gh-release@v1
114+ with :
115+ name : Release ${{ github.ref_name }}
116+ tag_name : ${{ github.ref_name }}
117+ generate_release_notes : true
118+ files : |
119+ release/snmp-discovery-windows.exe
120+ release/snmp-discovery-debian
121+ release/snmp-discovery-rhel
122+ release/source-code.zip
123+ env :
124+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments