Skip to content

fix: use dynamic key lookup for bottle JSON parsing #6

fix: use dynamic key lookup for bottle JSON parsing

fix: use dynamic key lookup for bottle JSON parsing #6

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
# ── Job 1: Create source tarball and draft release ─────────────────────────
source-tarball:
name: Source tarball
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tarball_sha256: ${{ steps.tarball.outputs.sha256 }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
- name: Create source tarball
id: tarball
run: |
VERSION=${{ steps.version.outputs.version }}
tar czf /tmp/mavsim-viewer-${VERSION}.tar.gz \
--exclude='.git' \
--exclude='tests/fixtures/*.ulg' \
--exclude='build' \
--transform="s,^\.,mavsim-viewer-${VERSION}," \
.
mv /tmp/mavsim-viewer-${VERSION}.tar.gz .
SHA=$(sha256sum mavsim-viewer-${VERSION}.tar.gz | awk '{print $1}')
echo "sha256=${SHA}" >> "$GITHUB_OUTPUT"
echo "Tarball SHA256: ${SHA}"
- name: Create release
run: |
gh release create ${{ github.ref_name }} \
--title "${{ github.ref_name }}" \
--generate-notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload source tarball
run: |
VERSION=${{ steps.version.outputs.version }}
gh release upload ${{ github.ref_name }} mavsim-viewer-${VERSION}.tar.gz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── Job 2a: macOS arm64 bottle ─────────────────────────────────────────────
bottle-arm64:
name: Bottle (arm64)
needs: source-tarball
runs-on: macos-14
outputs:
bottle_sha256: ${{ steps.bottle.outputs.sha256 }}
bottle_tag: ${{ steps.bottle.outputs.tag }}
steps:
- name: Set up tap with formula
env:
VERSION: ${{ needs.source-tarball.outputs.version }}
TARBALL_SHA: ${{ needs.source-tarball.outputs.tarball_sha256 }}
TAG: ${{ github.ref_name }}
run: |
export FORMULA_DIR="$(brew --repo)/Library/Taps/mavlink/homebrew-tap/Formula"
mkdir -p "$FORMULA_DIR"
python3 -c "
import os
formula = '''class MavsimViewer < Formula
desc \"3D MAVLink vehicle viewer for SITL simulation\"
homepage \"https://github.com/mavlink/mavsim-viewer\"
url \"https://github.com/mavlink/mavsim-viewer/releases/download/{tag}/mavsim-viewer-{version}.tar.gz\"
sha256 \"{sha}\"
license \"BSD-3-Clause\"
depends_on \"cmake\" => :build
def install
system \"cmake\", \"-S\", \".\", \"-B\", \"build\", \"-DCMAKE_BUILD_TYPE=Release\", \"-DHOMEBREW_ALLOW_FETCHCONTENT=ON\", *std_cmake_args
system \"cmake\", \"--build\", \"build\"
system \"cmake\", \"--install\", \"build\", \"--prefix\", prefix
end
test do
assert_predicate bin/\"mavsim-viewer\", :executable?
end
end
'''.format(
tag=os.environ['TAG'],
version=os.environ['VERSION'],
sha=os.environ['TARBALL_SHA'],
)
with open(os.environ['FORMULA_DIR'] + '/mavsim-viewer.rb', 'w') as f:
f.write(formula)
"
- name: Build bottle
run: brew install --build-bottle mavlink/tap/mavsim-viewer
- name: Package bottle
id: bottle
run: |
TAG=${{ github.ref_name }}
brew bottle \
--json \
--root-url="https://github.com/mavlink/mavsim-viewer/releases/download/${TAG}" \
mavlink/tap/mavsim-viewer
BOTTLE_JSON=$(ls mavsim-viewer--*.bottle.json)
BOTTLE_FILE=$(ls mavsim-viewer--*.bottle.tar.gz)
CLEAN_NAME=$(echo "$BOTTLE_FILE" | sed 's/--/-/')
mv "$BOTTLE_FILE" "$CLEAN_NAME"
BOTTLE_SHA=$(python3 -c "
import json, sys
data = json.load(open(sys.argv[1]))
formula = list(data.keys())[0]
tags = data[formula]['bottle']['tags']
tag = list(tags.keys())[0]
print(tags[tag]['sha256'])
" "$BOTTLE_JSON")
BOTTLE_TAG=$(python3 -c "
import json, sys
data = json.load(open(sys.argv[1]))
formula = list(data.keys())[0]
tags = data[formula]['bottle']['tags']
print(list(tags.keys())[0])
" "$BOTTLE_JSON")
echo "sha256=${BOTTLE_SHA}" >> "$GITHUB_OUTPUT"
echo "tag=${BOTTLE_TAG}" >> "$GITHUB_OUTPUT"
echo "file=${CLEAN_NAME}" >> "$GITHUB_OUTPUT"
- name: Upload bottle to release
run: gh release upload ${{ github.ref_name }} ${{ steps.bottle.outputs.file }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── Job 2b: Linux amd64 .deb ──────────────────────────────────────────────
deb-amd64:
name: Deb (amd64)
needs: source-tarball
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-dev libx11-dev libxrandr-dev \
libxinerama-dev libxcursor-dev libxi-dev
- name: Configure
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DMAVSIM_VERSION=${{ needs.source-tarball.outputs.version }}
- name: Build
run: cmake --build build --config Release
- name: Package .deb
run: cd build && cpack -G DEB
- name: Smoke test
run: |
sudo dpkg -i build/*.deb
which mavsim-viewer
ls /usr/share/mavsim-viewer/models/
ls /usr/share/mavsim-viewer/shaders/
ls /usr/share/mavsim-viewer/fonts/
- name: Upload .deb to release
run: gh release upload ${{ github.ref_name }} build/*.deb
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── Job 3: Update Homebrew tap ─────────────────────────────────────────────
update-tap:
name: Update Homebrew tap
needs: [source-tarball, bottle-arm64]
runs-on: ubuntu-latest
steps:
- name: Update formula in tap
env:
VERSION: ${{ needs.source-tarball.outputs.version }}
TAG: ${{ github.ref_name }}
TARBALL_SHA: ${{ needs.source-tarball.outputs.tarball_sha256 }}
ARM64_SHA: ${{ needs.bottle-arm64.outputs.bottle_sha256 }}
ARM64_TAG: ${{ needs.bottle-arm64.outputs.bottle_tag }}
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
git clone https://x-access-token:${TAP_TOKEN}@github.com/mavlink/homebrew-tap.git tap
mkdir -p tap/Formula
python3 -c "
import os
formula = '''class MavsimViewer < Formula
desc \"3D MAVLink vehicle viewer for SITL simulation\"
homepage \"https://github.com/mavlink/mavsim-viewer\"
url \"https://github.com/mavlink/mavsim-viewer/releases/download/{tag}/mavsim-viewer-{version}.tar.gz\"
sha256 \"{tarball_sha}\"
license \"BSD-3-Clause\"
bottle do
root_url \"https://github.com/mavlink/mavsim-viewer/releases/download/{tag}\"
sha256 cellar: :any_skip_relocation, {arm64_tag}: \"{arm64_sha}\"
end
depends_on \"cmake\" => :build
def install
system \"cmake\", \"-S\", \".\", \"-B\", \"build\",
\"-DCMAKE_BUILD_TYPE=Release\",
\"-DHOMEBREW_ALLOW_FETCHCONTENT=ON\",
*std_cmake_args
system \"cmake\", \"--build\", \"build\"
system \"cmake\", \"--install\", \"build\", \"--prefix\", prefix
end
test do
assert_predicate bin/\"mavsim-viewer\", :executable?
end
end
'''.format(
tag=os.environ['TAG'],
version=os.environ['VERSION'],
tarball_sha=os.environ['TARBALL_SHA'],
arm64_sha=os.environ['ARM64_SHA'],
arm64_tag=os.environ['ARM64_TAG'],
)
with open('tap/Formula/mavsim-viewer.rb', 'w') as f:
f.write(formula)
"
cd tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/mavsim-viewer.rb
git commit -m "mavsim-viewer ${VERSION}"
git push