Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 232 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
name: Build and Package OpenOCD

on:
workflow_dispatch:
push:
release:
types: [published]

permissions:
contents: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
#Fixes the backward compatibility.
container:
image: ubuntu:20.04
options: --user root

steps:
- name: Install Build Dependencies
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
apt-get install -y \
build-essential git automake autoconf libtool texinfo \
libusb-1.0-0-dev libftdi1-dev libjaylink-dev libcapstone-dev \
pkg-config patchelf ca-certificates curl

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Compute version
id: version
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION="${{ github.ref_name }}"
else
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-dev")
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Bootstrap
run: ./bootstrap with-submodules

- name: Configure
run: |
./configure \
--prefix=/usr \
--datarootdir=/usr/share/openocd-adi \
--datadir=/usr/share/openocd-adi \
--with-pkgversion="${VERSION}" \
--enable-internal-jimtcl \
--enable-internal-libjaylink

- name: Build
run: make -j$(nproc)

- name: Create Bundle
run: |
mkdir -p staging/bin
mkdir -p staging/lib
mkdir -p staging/share/openocd-adi

cp src/openocd staging/bin/openocd-adi
cp -r tcl/* staging/share/openocd-adi/

echo "Bundling dependencies..."
ldd src/openocd | grep -E "libusb|libftdi|libjaylink|libcapstone" | awk '{print $3}' | xargs -I '{}' cp -v '{}' staging/lib/

echo "Patching RPATH..."
patchelf --set-rpath '$ORIGIN/../lib' staging/bin/openocd-adi

- name: Upload Bundle
uses: actions/upload-artifact@v4
with:
name: openocd-portable-build
path: staging/

package:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout for Versioning
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Download Bundle
uses: actions/download-artifact@v4
with:
name: openocd-portable-build
path: pkg-root/usr/lib/openocd-adi

- name: Create System Wrapper
run: |
mkdir -p pkg-root/usr/bin

printf '#!/bin/sh\nexec /usr/lib/openocd-adi/bin/openocd-adi -s /usr/lib/openocd-adi/share/openocd-adi "$@"\n' > pkg-root/usr/bin/openocd-adi

chmod +x pkg-root/usr/bin/openocd-adi
chmod +x pkg-root/usr/lib/openocd-adi/bin/openocd-adi

- name: Install FPM
run: |
sudo apt-get update && sudo apt-get install -y ruby ruby-dev rubygems rpm
sudo gem install --no-document fpm

- name: Package DEB
run: |
fpm -s dir -t deb \
-n openocd-adi \
-v "$VERSION" \
-m "Ozan Durgut <ozan.durgut@analog.com>" \
--license "GPL-2.0" \
--description "OpenOCD for ADI" \
-C pkg-root \
.

- name: Package RPM
run: |
fpm -s dir -t rpm \
-n openocd-adi \
-v "$VERSION" \
-m "Ozan Durgut <ozan.durgut@analog.com>" \
--license "GPL-2.0" \
--description "OpenOCD for ADI" \
-C pkg-root \
.

- name: Upload Artifacts to GitHub
uses: actions/upload-artifact@v4
with:
name: openocd-packages
path: |
*.deb
*.rpm

test-packages:
needs: package
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: Ubuntu
image: ubuntu:24.04
pkg_type: deb
install_cmd: apt-get update && apt-get install -y
- name: Fedora
image: fedora:latest
pkg_type: rpm
install_cmd: dnf install -y

container: ${{ matrix.image }}

steps:
- name: Download Packages
uses: actions/download-artifact@v4
with:
name: openocd-packages
path: ./pkgs

- name: Install Package
run: |
echo "Installing ${{ matrix.pkg_type }} on ${{ matrix.image }}..."
${{ matrix.install_cmd }} ./pkgs/*.${{ matrix.pkg_type }}

- name: Verify Binary Execution
run: |
if ldd $(which openocd-adi) | grep "not found"; then
echo "Missing shared libraries detected!"
exit 1
else
echo "Library linkage looks good."
fi

openocd-adi --version

LOG_OUTPUT=$(openocd-adi -d3 -c "exit" 2>&1)

if echo "$LOG_OUTPUT" | grep -q "/usr/lib/openocd-adi/share/openocd-adi"; then
echo "Search path is set correctly."
else
echo "Search path is erroneus."
echo "DEBUG LOGS:"
echo "$LOG_OUTPUT"
exit 1
fi

RUN_OUTPUT=$(openocd-adi -f interface/ice1000.cfg -c "exit" 2>&1 || true)

if echo "$RUN_OUTPUT" | grep -q "Can't find interface/ice1000.cfg"; then
echo "Script file 'interface/ice1000.cfg' not found!"
exit 1
else
echo "Script file found and parsed."
fi

echo "All Tests Passed!"

publish:
needs: test-packages
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV

- name: Download Packages
uses: actions/download-artifact@v4
with:
name: openocd-packages
path: ./pkgs

- name: Authenticate Cloudsmith OIDC
uses: cloudsmith-io/cloudsmith-cli-action@v1.0.3
with:
oidc-namespace: "adi"
oidc-service-slug: ${{ secrets.CLOUDSMITH_SERVICE_SLUG }}
oidc-auth-only: "false"

- name: Publish to Cloudsmith
run: |
cloudsmith push deb adi/openocd/any-distro/any-version *.deb
cloudsmith push rpm adi/openocd/any-distro/any-version *.rpm