0.2.2 #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
release: | |
types: [created] | |
jobs: | |
build: | |
strategy: | |
matrix: | |
# We build on an older Ubuntu as pyinstaller binaries are forward-compatible not backwards-compatible | |
# See https://pyinstaller.org/en/stable/usage.html?highlight=glibc#making-gnu-linux-apps-forward-compatible:~:text=The%20solution%20is%20to%20always%20build%20your%20app%20on%20the%20oldest%20version%20of%20GNU/Linux%20you%20mean%20to%20support.%20It%20should%20continue%20to%20work%20with%20the%20libc%20found%20on%20newer%20versions. | |
# TODO: for similar reasons, we may want to build on older Windows/MacOS versions as well | |
os: [ubuntu-20.04, 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 dependencies (Linux) | |
if: matrix.os == 'ubuntu-20.04' | |
run: | | |
sudo apt-get install -y binutils | |
- name: Update package version (Linux) | |
if: matrix.os == 'ubuntu-20.04' | |
run: sed -i 's/__version__ = .*/__version__ = "${{ github.ref_name }}"/g' holmes/__init__.py | |
# mac has BSD style sed command where you specify -i '' and not just -i | |
- name: Update package version (macOS) | |
if: matrix.os == 'macos-latest' | |
run: sed -i '' 's/__version__ = .*/__version__ = "${{ github.ref_name }}"/g' holmes/__init__.py | |
# windows has no sed, so we use powershell | |
- name: Update package version (Windows) | |
if: matrix.os == 'windows-latest' | |
run: | | |
$filePath = 'holmes/__init__.py' | |
(Get-Content $filePath) -replace '__version__ = .+', '__version__ = "${{ github.ref_name }}"' | Set-Content $filePath | |
shell: pwsh | |
- name: Build with PyInstaller | |
shell: bash | |
run: | | |
pyinstaller holmes.py --add-data 'holmes/plugins/runbooks/*:holmes/plugins/runbooks' --add-data 'holmes/plugins/prompts/*:holmes/plugins/prompts' --add-data 'holmes/plugins/toolsets/*:holmes/plugins/toolsets' | |
ls dist | |
- name: Zip the application (Unix) | |
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-20.04' | |
run: | | |
cd dist | |
zip -r holmes-${{ matrix.os }}-${{ github.ref_name }}.zip holmes | |
mv holmes-${{ 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 holmes -DestinationPath holmes-${{ matrix.os }}-${{ github.ref_name }}.zip -Force | |
Move-Item -Path holmes-${{ 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: ./holmes-${{ matrix.os }}-${{ github.ref_name }}.zip | |
asset_name: holmes-${{ matrix.os }}-${{ github.ref_name }}.zip | |
asset_content_type: application/octet-stream | |
- name: Upload build as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: holmes-${{ matrix.os }}-${{ github.ref_name }} | |
path: ./holmes-${{ matrix.os }}-${{ github.ref_name }}.zip | |
check-latest: | |
needs: build | |
runs-on: ubuntu-20.04 | |
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: holmes-macos-latest-${{ github.ref_name }} | |
- name: Calculate hash | |
id: calc-hash | |
run: echo "::set-output name=MAC_BUILD_HASH::$(sha256sum holmes-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: holmes-ubuntu-20.04-${{ github.ref_name }} | |
- name: Calculate hash | |
id: calc-hash | |
run: echo "::set-output name=LINUX_BUILD_HASH::$(sha256sum holmes-ubuntu-20.04-${{ 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/holmesgpt/releases/download/'"$TAG_NAME"'/holmes-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/holmesgpt/releases/download/'"$TAG_NAME"'/holmes-ubuntu-20.04-'"$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 |