-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Build Meshtastic build container | ||
on: | ||
push: | ||
# build and push anytime commits are pushed/merged | ||
branches: | ||
- main | ||
release: | ||
# build and push upon release creation | ||
types: | ||
- created | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build_and_push_latest: | ||
runs-on: ubuntu-24.04 | ||
name: Build and push upon merge | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
attestations: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: docker/setup-qemu-action@v3 | ||
|
||
- uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker Login GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
# platforms: linux/amd64 | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import requests | ||
import tarfile | ||
import sys | ||
|
||
inputs = { | ||
'arch': os.getenv('INPUT_ARCH'), | ||
'board': os.getenv('INPUT_BOARD'), | ||
'build-script-path': os.path(os.getenv('INPUT_BUILD-SCRIPT-PATH')), | ||
'remove-debug-flags': str(os.getenv('INPUT_REMOVE-DEBUG-FLAGS', '')).split(), | ||
'ota-firmware-source': os.getenv('INPUT_OTA-FIRMWARE-SOURCE', ''), | ||
'ota-firmware-target': os.getenv('INPUT_OTA-FIRMWARE-TARGET', ''), | ||
'include-web-ui': bool(os.getenv('INPUT_INCLUDE-WEB-UI', False)) | ||
} | ||
|
||
env = { | ||
'GITHUB_ACTIONS': bool(os.getenv('GITHUB_ACTIONS')), | ||
'XDG_CACHE_HOME': os.path(os.getenv('XDG_CACHE_HOME')) | ||
} | ||
|
||
def gh_latest_release(owner, repo): | ||
r = requests.get(f"https://api.github.com/repos/{owner}/{repo}/releases/latest") | ||
r_j = r.json() | ||
if r.status_code == 200: | ||
return r_j | ||
else: | ||
raise Exception(f"Failed to fetch latest release from {owner}/{repo}") | ||
|
||
def download_file(url, dest): | ||
print(f"Downloading {url} to {dest}") | ||
r = requests.get(url, stream=True) | ||
with open(dest, 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=8192): | ||
f.write(chunk) | ||
|
||
def extract_tar(tar_file, extract_to, remove_src=False): | ||
print(f"Extracting {tar_file} to {extract_to}") | ||
with tarfile.open(tar_file, 'r') as tar: | ||
tar.extractall(extract_to) | ||
if remove_src == True: | ||
print(f"..Cleaning up {tar_file}") | ||
os.remove(tar_file) | ||
|
||
# ============== | ||
|
||
# Fix cache permissions | ||
if os.path.exists(env['XDG_CACHE_HOME']): | ||
os.system(f'chmod -R 777 {env['XDG_CACHE_HOME']}') | ||
|
||
# Workaround for the "safe.directory" issue | ||
os.system("git config --system --add safe.directory /github/workspace") | ||
|
||
# Web UI | ||
if inputs['include-web-ui'] == True: | ||
mt_web = gh_latest_release('meshtastic', 'web') | ||
for asset in mt_web['assets']: | ||
if asset['name'] == 'build.tar': | ||
# Download build.tar | ||
download_file(asset['browser_download_url'], 'build.tar') | ||
# Extract build.tar | ||
extract_tar('build.tar','data/static', remove_src=True) | ||
|
||
# Remove debug flags for release | ||
if len(inputs['remove-debug-flags']) > 0: | ||
for flag in inputs['remove-debug-flags']: | ||
os.system(f"sed -i /DDEBUG_HEAP/d {flag}") | ||
|
||
# Run the Build | ||
r_build = subprocess.run([inputs['build-script-path'], inputs['board']], check=True) | ||
|
||
# Pull OTA firmware | ||
if inputs['ota-firmware-source'] != '' and inputs['ota-firmware-target'] != '': | ||
ota_fw = gh_latest_release('meshtastic', 'firmware-ota') | ||
for asset in ota_fw['assets']: | ||
if asset['name'] == inputs['ota-firmware-source']: | ||
# Download firmware.bin | ||
download_file(asset['browser_download_url'], inputs['ota-firmware-target']) | ||
|
||
# When running in GitHub Actions | ||
if env['GITHUB_ACTIONS']: | ||
# Hack! - Add checked-out firmware/bin to the python module path | ||
cwd_bin = os.path.join(os.getcwd(), 'bin') | ||
sys.path.append(cwd_bin) | ||
from readprops import readProps # type: ignore | ||
# /Hack! | ||
|
||
# Get release version string | ||
verObj = readProps("version.properties") | ||
version_str = verObj['long'] | ||
# Write version string to GitHub Actions output | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
print(f'version={version_str}', file=fh) | ||
|
||
# Fix cache permissions | ||
os.system(f'chmod -R 777 {env['XDG_CACHE_HOME']}') |
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