-
Notifications
You must be signed in to change notification settings - Fork 60
145 lines (129 loc) · 5.1 KB
/
build-on-release.yaml
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
name: Build and Release
on:
release:
types: [created]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller
- name: Install dependancies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y binutils
- name: Build with PyInstaller
shell: bash
run: |
pyinstaller main.py
ls dist
- name: Zip the application (Unix)
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest'
run: |
cd dist
zip -r main-${{ matrix.os }}-${{ github.ref_name }}.zip main
mv main-${{ matrix.os }}-${{ github.ref_name }}.zip ../
cd ..
- name: Zip the application (Windows)
if: matrix.os == 'windows-latest'
run: |
Set-Location -Path dist
Compress-Archive -Path main -DestinationPath main-${{ matrix.os }}-${{ github.ref_name }}.zip -Force
Move-Item -Path main-${{ matrix.os }}-${{ github.ref_name }}.zip -Destination ..\
Set-Location -Path ..
- name: Upload Release Asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./main-${{ matrix.os }}-${{ github.ref_name }}.zip
asset_name: main-${{ matrix.os }}-${{ github.ref_name }}.zip
asset_content_type: application/octet-stream
- name: Upload build as artifact
uses: actions/upload-artifact@v2
with:
name: main-${{ matrix.os }}-${{ github.ref_name }}
path: ./main-${{ matrix.os }}-${{ github.ref_name }}.zip
check-latest:
needs: build
runs-on: ubuntu-latest
outputs:
IS_LATEST: ${{ steps.check-latest.outputs.release == github.ref_name }}
steps:
- id: check-latest
uses: pozetroninc/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
excludes: prerelease, draft
# Define MacOS hash job
mac-hash:
needs: check-latest
runs-on: ubuntu-latest
if: needs.check-latest.outputs.IS_LATEST
outputs:
MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Download MacOS artifact
uses: actions/download-artifact@v2
with:
name: main-macos-latest-${{ github.ref_name }}
- name: Calculate hash
id: calc-hash
run: echo "::set-output name=MAC_BUILD_HASH::$(sha256sum main-macos-latest-${{ github.ref_name }}.zip | awk '{print $1}')"
# Define Linux hash job
linux-hash:
needs: check-latest
runs-on: ubuntu-latest
if: needs.check-latest.outputs.IS_LATEST
outputs:
LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Download Linux artifact
uses: actions/download-artifact@v2
with:
name: main-ubuntu-latest-${{ github.ref_name }}
- name: Calculate hash
id: calc-hash
run: echo "::set-output name=LINUX_BUILD_HASH::$(sha256sum main-$-ubuntu-latest-${{ github.ref_name }}.zip | awk '{print $1}')"
# TODO: update homebrew formula
update-formula:
needs: [mac-hash, linux-hash]
runs-on: ubuntu-latest
steps:
- name: Checkout homebrew-holmesgpt repository
uses: actions/checkout@v2
with:
repository: robusta-dev/homebrew-holmesgpt
token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }}
- name: Update holmesgpt.rb formula
run: |
MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }}
LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.LINUX_BUILD_HASH }}
TAG_NAME=${{ github.ref_name }}
awk 'NR==6{$0=" url \"https://github.com/robusta-dev/holmestgpt/releases/download/'"$TAG_NAME"'/main-macos-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/holmesgpt.rb > temp && mv temp ./Formula/holmesgpt.rb
awk 'NR==7{$0=" sha256 \"'$MAC_BUILD_HASH'\""}1' ./Formula/holmesgpt.rb > temp && mv temp ./Formula/holmesgpt.rb
awk 'NR==9{$0=" url \"https://github.com/robusta-dev/holmestgpt/releases/download/'"$TAG_NAME"'/main-ubuntu-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/holmesgpt.rb > temp && mv temp ./Formula/holmesgpt.rb
awk 'NR==10{$0=" sha256 \"'$LINUX_BUILD_HASH'\""}1' ./Formula/holmesgpt.rb > temp && mv temp ./Formula/holmesgpt.rb
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -am "Update formula for release ${TAG_NAME}"
git push