Skip to content

Commit

Permalink
Merge remote-tracking branch 'personal/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Fievet committed Aug 12, 2024
2 parents ba7d9a9 + cb3a9af commit 186bf6e
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: 'Build and Deploy to BOINC Server'

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:

define-version:
uses: ./.github/workflows/identify_target_version.yml
with:
# we use the description to fetch the latest version of the app from the BOINC server apps page
boinc_app_description: ${{ vars.APP_DESCRIPTION }}

generate-freeze-config:
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
# https://github.com/actions/checkout
uses: actions/checkout@v4
- name: "Create cxFreeze config file"
env:
EXECUTABLE: ${{ vars.EXECUTABLE }}
APP_DESCRIPTION: ${{ vars.APP_DESCRIPTION }}
run: |
sed -e "s/{EXECUTABLE}/$EXECUTABLE/g" -e "s/{APP_DESCRIPTION}/$APP_DESCRIPTION/g" boinc/freeze_config_template.py > freeze_config.py
- name: "Upload cxFreeze config artifact"
uses: actions/upload-artifact@v4
with:
name: freeze_config.py
path: freeze_config.py
overwrite: true

build-binaries:
needs: [generate-freeze-config]
runs-on: ${{ matrix.runner }}
strategy:
matrix:
runner:
# - ubuntu-latest
# - macos-latest
- windows-latest
include:
# - runner: ubuntu-latest
# # we use this platform string to make our download artifacts unique for the same version across platforms
# platform: 'linux'
- runner: windows-latest
# we use this platform string to make our download artifacts unique for the same version across platforms
platform: 'win'
# - runner: macos-latest
# # we use this platform string to make our download artifacts unique for the same version across platforms
# platform: 'mac'
steps:
- name: "Checkout repository"
# https://github.com/actions/checkout
uses: actions/checkout@v4
- name: "Configure python"
# https://github.com/actions/setup-python
uses: actions/setup-python@v5
with:
python-version: "3.11.7"
- name: "Install system dependencies on macOS"
if: runner.os == 'macOS'
run: |
brew install postgresql
brew link postgresql
- name: "Install dependencies and cxFreeze"
run: |
pip install -e .
pip install --upgrade cx_Freeze
- name: "Download previously created freeze configuration"
uses: actions/download-artifact@v4
with:
name: freeze_config.py
- name: "Build binary"
run: | # See https://cx-freeze.readthedocs.io/en/stable/script.html#script
cat freeze_config.py
python freeze_config.py build
- name: "Upload cxFreeze binaries"
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}
path: build/executable
overwrite: true

bundle-and-deploy:
needs: [define-version, build-binaries]
uses: ./.github/workflows/bundle_app.yml
secrets: inherit
with:
new_version: ${{ needs.define-version.outputs.new_version }}
platform: ${{ matrix.platform }}
wrapper: ${{ matrix.wrapper }}
boinc_platform: ${{ matrix.boinc_platform }}
executable: ${{ vars.EXECUTABLE }}
app_dir: ${{ vars.APP_DIR }}
strategy:
matrix:
platform:
# - linux
# - mac
- win
include:
# - platform: 'linux'
# # These wrappers come from BOINC and should be watched for newer versions: https://boinc.berkeley.edu/dl/?C=M;O=D
# wrapper: 'wrapper_26002_x86_64-pc-linux-gnu'
# boinc_platform: 'x86_64-pc-linux-gnu'
- platform: 'win'
wrapper: 'wrapper_26016_windows_x86_64'
boinc_platform: 'windows_x86_64'
# - platform: 'mac'
# wrapper: 'wrapper_26017_universal-apple-darwin'
# boinc_platform: 'arm64-apple-darwin'

cleanup:
needs: [bundle-and-deploy]
runs-on: ubuntu-latest
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: |
version
freeze_config.py
# linux
# mac
win
failOnError: false
148 changes: 148 additions & 0 deletions .github/workflows/bundle_app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: 'Prepare Deployment Bundle'

on:
workflow_call:
inputs:
new_version:
description: 'The target version for this bundle, based on what is currently deployed on the BOINC server'
type: string
required: true
platform:
description: 'User friendly platform name used to distinctly name artifacts across platforms'
type: string
required: true
boinc_platform:
description: 'Must match one of the platforms in the BOINC server project.xml and https://boinc.berkeley.edu/trac/wiki/BoincPlatforms'
type: string
required: true
wrapper:
description: 'Name of the wrapper to use - these get updated every so often and can be found here https://boinc.berkeley.edu/dl/?C=M;O=D'
type: string
required: true
executable:
description: 'Executable name as used in naming cxFreeze output binary'
type: string
required: true
app_dir:
description: 'Short name of the app as defined in the BOINC server, also the name of the directory where the binaries are deposited'
type: string
required: true

jobs:
bundle:
runs-on: ubuntu-latest
env:
NEW_VERSION: ${{ inputs.new_version }}
PLATFORM: ${{ inputs.platform }}
BOINC_PLATFORM: ${{ inputs.boinc_platform }}
WRAPPER: ${{ inputs.wrapper }}
EXECUTABLE: ${{ inputs.executable }}
APP_DIR: ${{ inputs.app_dir }}
steps:
- name: "Checkout repository"
# https://github.com/actions/checkout
uses: actions/checkout@v4
- name: "Download BOINC wrapper"
# wrapper documentation is outdated, latest wrapper version can be found here https://boinc.berkeley.edu/dl/?C=M;O=D
run: |
curl -O https://boinc.berkeley.edu/dl/$WRAPPER.zip
- name: "Unzip wrapper"
run: |
unzip $WRAPPER.zip
if [[ -d "$WRAPPER" ]]; then
mv $WRAPPER/* .
fi
- name: "Create job.xml (Windows)"
if: ${{ inputs.platform == 'win' }}
run: |
sed -e "s/{{EXECUTABLE}}/$EXECUTABLE.exe/g" boinc/job_template.xml > job.$NEW_VERSION-$PLATFORM.xml
- name: "Create job.xml (non-Windows)"
if: ${{ inputs.platform != 'win' }}
run: |
sed -e "s/{{EXECUTABLE}}/$EXECUTABLE/g" boinc/job_template.xml > job.$NEW_VERSION-$PLATFORM.xml
- name: "Create version.xml"
run: |
sed -e "s/{{WRAPPER}}/$WRAPPER/g" -e "s/{{VERSION}}/$NEW_VERSION/g" -e "s/{{PLATFORM}}/$PLATFORM/g" boinc/version_template.xml > version.xml
- name: "Create directory for previously created binaries"
run: |
mkdir app.$NEW_VERSION-$PLATFORM
- name: "Download previously compiled binaries"
uses: actions/download-artifact@v4
with:
name: ${{ env.PLATFORM }}
path: app.${{ env.NEW_VERSION }}-${{ env.PLATFORM }}
- name: "Zip build output"
run: |
zip -r app.$NEW_VERSION-$PLATFORM.zip app.$NEW_VERSION-$PLATFORM
- name: "Sign files"
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
run: |
echo "$SIGNING_KEY" > key
./boinc/sign_executable job.$NEW_VERSION-$PLATFORM.xml key > job.$NEW_VERSION-$PLATFORM.xml.sig
./boinc/sign_executable app.$NEW_VERSION-$PLATFORM.zip key > app.$NEW_VERSION-$PLATFORM.zip.sig
- name: "Sign executables (Windows)"
if: ${{ inputs.platform == 'win' }}
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
run: |
./boinc/sign_executable $WRAPPER.exe key > $WRAPPER.exe.sig
- name: "Sign executables (non-Windows)"
if: ${{ inputs.platform != 'win' }}
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
run: |
./boinc/sign_executable $WRAPPER key > $WRAPPER.sig
- name: "Create app bundle (Windows)"
if: ${{ inputs.platform == 'win' }}
run: |
zip -r --junk-paths $BOINC_PLATFORM.zip . -i version.xml job.$NEW_VERSION-$PLATFORM.xml job.$NEW_VERSION-$PLATFORM.xml.sig $WRAPPER.exe $WRAPPER.exe.sig app.$NEW_VERSION-$PLATFORM.zip app.$NEW_VERSION-$PLATFORM.zip.sig
- name: "Create app bundle (non-Windows)"
if: ${{ inputs.platform != 'win' }}
run: |
zip -r --junk-paths $BOINC_PLATFORM.zip . -i version.xml job.$NEW_VERSION-$PLATFORM.xml job.$NEW_VERSION-$PLATFORM.xml.sig $WRAPPER $WRAPPER.sig app.$NEW_VERSION-$PLATFORM.zip app.$NEW_VERSION-$PLATFORM.zip.sig
- name: "Upload binary to GitHub"
uses: actions/upload-artifact@v4
with:
name: ${{ env.BOINC_PLATFORM }}.zip
path: ${{ env.BOINC_PLATFORM }}.zip
overwrite: true

- name: 'Prepare BOINC server access'
run: |
mkdir -pv ~/.ssh/
- name: 'Write key'
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
run: |
echo "$SSH_KEY" > ~/.ssh/actions.key
chmod 600 ~/.ssh/actions.key
- name: 'Write ssh config'
run: |
cat >>~/.ssh/config <<END
Host boinc
HostName 172.105.4.251
User root
IdentityFile ~/.ssh/actions.key
StrictHostKeyChecking=no
ServerAliveCountMax=10
ServerAliveInterval=60
END
- name: 'Make target directory'
if: ${{ ! vars.DO_NOT_DEPLOY }}
run: |
ssh boinc 'sudo su - boincadm -c "mkdir -p /home/boincadm/projects/boinc/apps/${{env.APP_DIR}}/${{env.NEW_VERSION}}"'
- name: 'Copy binaries to server'
if: ${{ ! vars.DO_NOT_DEPLOY }}
run: |
scp $BOINC_PLATFORM.zip boinc:/home/boincadm/projects/boinc/apps/${{env.APP_DIR}}/${{env.NEW_VERSION}}
ssh boinc 'sudo su - boincadm -c "chown boincadm /home/boincadm/projects/boinc/apps/${{env.APP_DIR}}/${{env.NEW_VERSION}}"'
ssh boinc 'sudo su - boincadm -c "chgrp boincadm /home/boincadm/projects/boinc/apps/${{env.APP_DIR}}/${{env.NEW_VERSION}}"'
- name: 'Unpack binaries'
if: ${{ ! vars.DO_NOT_DEPLOY }}
run: |
ssh boinc 'sudo su - boincadm -c "cd /home/boincadm/projects/boinc/apps/${{env.APP_DIR}}/${{env.NEW_VERSION}} && unzip -o -q -d ${{env.BOINC_PLATFORM}} ${{env.BOINC_PLATFORM}}.zip"'
- name: 'Run BOINC update versions'
if: ${{ ! vars.DO_NOT_DEPLOY }}
run: |
ssh boinc 'sudo su - boincadm -c "cd /home/boincadm/projects/boinc && ./bin/update_versions"'
55 changes: 55 additions & 0 deletions .github/workflows/identify_target_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Identify Target Version'

on:
workflow_call:
inputs:
boinc_app_description:
description: 'The BOINC app "description" value from the BOINC server / database'
required: true
type: string
outputs:
new_version:
description: 'Next version number to be applied to build artifacts'
value: ${{ jobs.define_target_version.outputs.new_version }}

jobs:
define_target_version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.new_version_number.outputs.new_version }}
steps:
- name: "Fetch latest published version number"
shell: bash
run: |
curl -O https://rnma.xyz/boinc/apps.php
- name: "Define new version number"
shell: bash
id: new_version_number
env:
BOINC_APP_DESCRIPTION: ${{ inputs.boinc_app_description }}
run: |
VERSION=$(sed -n "/<th class=\"bg-primary\" colspan=4>$(printf '%s\n' "$BOINC_APP_DESCRIPTION" | sed 's/[\^$.|?*+(){}]/\\&/g')<\/th>/,/<td>\([0-9].[0-9]\)/p" apps.php | sed -n 's/.*<td>\([0-9][0-9]*\.[0-9]*\)<\/td>.*/\1/ p')
if [ -z "$VERSION" ]; then
VERSION="1.0"
fi
echo "Last published version of $BOINC_APP_DESCRIPTION is $VERSION"
MAJOR_VERSION=$(echo $VERSION | cut -d '.' -f1)
MINOR_VERSION=$(echo $VERSION | cut -d '.' -f2)
if [ $MINOR_VERSION -eq 99 ]; then
NEW_MAJOR_VERSION=$((10#$MAJOR_VERSION + 1))
NEW_MINOR_VERSION="00"
else
NEW_MAJOR_VERSION=$MAJOR_VERSION
NEW_MINOR_VERSION=$((10#$MINOR_VERSION + 1))
fi
NEW_VERSION="$NEW_MAJOR_VERSION.$(printf "%02d" $NEW_MINOR_VERSION)"
echo "New version will be $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo $NEW_VERSION > version
- name: "Upload version"
uses: actions/upload-artifact@v4
with:
name: version
path: version
overwrite: true
if-no-files-found: error
22 changes: 22 additions & 0 deletions boinc/freeze_config_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
This file is the template build configuration for cx_Freeze to generate an executable binary across platforms
Parameters EXECUTABLE and APP_DESCRIPTION come from the GitHub workflow
"""
from cx_Freeze import setup, Executable

build_options = {'packages': [],
'excludes': ['tkinter'],
'build_exe': 'build/executable' # sets name of folder under build folder in which executables end up
}

base = 'console'

executables = [
Executable('run_lirec.py', base='console', target_name='{EXECUTABLE}')
]

setup(name='{EXECUTABLE}',
version='0.1',
description='{APP_DESCRIPTION}',
options={'build_exe': build_options},
executables=executables)
14 changes: 14 additions & 0 deletions boinc/job_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- This file is a necessary component to a BOINC app version -->
<job_desc>
<task>
<!-- application should be the executable, i.e. includes .exe on Windows -->
<application>{{EXECUTABLE}}</application>
<multi_process/>
<!-- this command line works - do not change - magic -->
<command_line>0001.json</command_line>
</task>
<unzip_input>
<!-- this is a logical file name not a physical one - do not change -->
<zipfilename>app.zip</zipfilename>
</unzip_input>
</job_desc>
Binary file added boinc/sign_executable
Binary file not shown.
16 changes: 16 additions & 0 deletions boinc/version_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- This file is a necessary component to a BOINC app version -->
<version>
<file>
<physical_name>{{WRAPPER}}</physical_name>
<main_program/>
</file>
<file>
<physical_name>job.{{VERSION}}-{{PLATFORM}}.xml</physical_name>
<logical_name>job.xml</logical_name>
</file>
<file>
<physical_name>app.{{VERSION}}-{{PLATFORM}}.zip</physical_name>
<logical_name>app.zip</logical_name>
</file>
<is_wrapper/>
</version>
Loading

0 comments on commit 186bf6e

Please sign in to comment.