Skip to content
Merged
Show file tree
Hide file tree
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
211 changes: 128 additions & 83 deletions .github/workflows/qcom-build-debian-package-reusable-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Qualcomm Build Debian Package Reusable Workflow
on:
workflow_call:
inputs:
ref:
description: The ref name thad was used to invoke this reusable workflow
type: string
required: true
use_local_ppa:
description: 'Whether to use a local PPA for testing'
type: boolean
Expand All @@ -11,105 +15,115 @@ on:
description: 'Whether to clear the PPA'
type: boolean
required: false
default: false
default: false
secrets:
ACTIONS_SSH_KEY:
required: true
required: true

permissions:
contents: read
security-events: write

env:
PPA_HTTP_DIRECTORY: /var/www/html/github-actions-ppa
PPA_HTTP_SERVER_PORT: 12345
PPA_HTTP_SERVER_SCREEN_NAME: github-actions-ppa-http-server
PPA_URL: https://qualcomm-linux.github.io/qcom-oss-staging-ppa/

# This variable is set to true below if the ABI check is not able to find an initial
# version of the package in the PPA
INITIAL_UPLOAD_TO_PPA: false
# version of the package in the PPA.
INITIAL_UPLOAD_TO_PPA: 'false'
ABI_CHECK_RETURN_VALUE: 0

PRODUCT_DISTRO: null
PRODUCT_CODENAME: null
PRODUCT_ARCH: null

PPA_PACKAGES_FILE_REPO_PATH: null

jobs:
qcom-build-debian-package:
build-debian-package-reusable-workflow:

runs-on: [self-hosted, Linux, ARM64]

steps:
- name: Clear PPA if requested
if: ${{ inputs.clear_ppa == 'true' }}
run: |
rm -rf ${{ env.PPA_HTTP_DIRECTORY }}/*
echo "Directory ${{ env.PPA_HTTP_DIRECTORY }} removed"

- name: Setup HTTP PPA server
run : |
echo "Check if PPA serving folder exists ${{ env.PPA_HTTP_DIRECTORY }}"
if [ -d "${{ env.PPA_HTTP_DIRECTORY }}" ]; then
echo "Directory exists"
else
echo "Directory does not exist"
mkdir ${{ env.PPA_HTTP_DIRECTORY }}
fi

echo "Check if PPA html server is running"

if screen -list | grep -q "${{ env.PPA_HTTP_SERVER_SCREEN_NAME }}"; then
echo "Screen session ${{ env.PPA_HTTP_SERVER_SCREEN_NAME }} already exists. Skipping server start."
else
screen -dmS ${{ env.PPA_HTTP_SERVER_SCREEN_NAME }} bash -c 'python3 -m http.server ${{ env.PPA_HTTP_SERVER_PORT }} --directory ${{ env.PPA_HTTP_DIRECTORY }}'
echo "Started HTTP server in screen session ${{ env.PPA_HTTP_SERVER_SCREEN_NAME }}"
fi
- name: Ensure Workspace Is Clean
run: rm -rf * # Ensure workspace is clean from previous runs

echo "Check if PPA server works"
if curl --silent --output /dev/null --fail http://localhost:${{ env.PPA_HTTP_SERVER_PORT }}/; then
echo "HTTP server works"
else
echo "Error: HTTP server is not responding. Exiting"
exit 1
fi

echo "Check if PPA server is populated"
if [ -f "${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages.gz" ]; then
echo "PPA server is populated, listing the content of Packages:"
cat ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages
else
echo "Error: PPA server is not populated. Populating"
mkdir -p ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/
dpkg-scanpackages ${{ env.PPA_HTTP_DIRECTORY }} > ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages
gzip -9 < ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages > ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages.gz
fi
# This checkout is done so that any change in qcom-build-utils doesnt't need to be propagated up
# Simply relaunching a job that uses this reusable workflow for a given ref will automatically see the changes
- name: Checkout Tip of qcom-build-utils For The Specified Ref
uses: actions/checkout@v4
with:
repository: qualcomm-linux/qcom-build-utils
ref: ${{ inputs.ref }}
ssh-key: ${{ secrets.ACTIONS_SSH_KEY }}
path: ./qcom-build-utils
fetch-depth: 1

- name : Checkout Repository With Submodules
- name: Checkout Repository And Submodules Recursively
uses: actions/checkout@v4 # Using public GitHub action to checkout repo, see https://github.com/actions/checkout
with:
clean: true # Make sure the workspace is cleaned up from previous runs
ref: ${{ github.head_ref }}
clean: false # A rm -rf * was done first, don't clean otherwise this would delete qcom-build-utils cloned above
submodules: 'recursive' # Make sure all submodules are recursively checked out
ssh-key: ${{ secrets.ACTIONS_SSH_KEY }} # Add SSH key for cloning private repos
fetch-depth: 1 # Speedup things since full history isn't needed

- name: Prepare Workspace Structure
- name: Exctract Product Configuration From qcom-product.conf
run: |
CONFIG_FILE="qcom-distro-ubuntu/qcom-product.conf"

DISTRO=$(grep '^Distro:' "$CONFIG_FILE" | cut -d':' -f2 | xargs)
CODENAME=$(grep '^Codename:' "$CONFIG_FILE" | cut -d':' -f2 | xargs)
ARCH=$(grep '^Arch:' "$CONFIG_FILE" | cut -d':' -f2 | xargs)

echo "Distro: $DISTRO"
echo "Codename: $CODENAME"
echo "Arch: $ARCH"

echo "PRODUCT_DISTRO=${DISTRO}" >> $GITHUB_ENV
echo "PRODUCT_CODENAME=${CODENAME}" >> $GITHUB_ENV
echo "PRODUCT_ARCH=${ARCH}" >> $GITHUB_ENV

echo "PPA_PACKAGES_FILE_REPO_PATH=dists/$CODENAME/stable/main/binary-$ARCH" >> $GITHUB_ENV

# The build.py script expects a specific directory structure
# This step creates the required directories and links the example package sources to the expected location
# The build_deb script will go through the WORKSPACE/sources directory and find every "debian" folder and exctract the package names
# from the Control file and build a list of available packages to build.
# from the Control file and build a list of available packages to build.
- name: Prepare Workspace Structure For The Build
run: |
echo "Listing the content of what was checked out"; tree
echo "Listing the content of what was checked out, exclusing .md files : "; tree -I '*.md|LICENSE.txt'
mkdir WORKSPACE
mkdir WORKSPACE/sources
mkdir WORKSPACE/sources/${{ github.event.repository.name }}
cp -r debian/ WORKSPACE/sources/${{ github.event.repository.name }}
cp -r qcom-example-package-source WORKSPACE/sources/${{ github.event.repository.name }}

- name: Build Debian Package
run : ./qcom-distro-ubuntu/qcom-build-utils/ubuntu/build.py --workspace ./WORKSPACE --gen-debians --no-abi-check
- name: Validate Or Create Chroot Environment
run: |
./qcom-build-utils/scripts/prep_chroot_env.py \
--arch ${{ env.PRODUCT_ARCH }} \
--os-codename ${{ env.PRODUCT_CODENAME }} \
--suffix ${{ env.PRODUCT_DISTRO }}

- name: Build Debian Packages
run: |
./qcom-build-utils/scripts/build.py \
--workspace ./WORKSPACE \
--gen-debians

- name: ABI Check
run: |
set +e
./qcom-distro-ubuntu/qcom-build-utils/ubuntu/deb_abi_checker.py \

./qcom-build-utils/scripts/deb_abi_checker.py \
--new-package-dir ./WORKSPACE/debian_packages/temp/${{ github.event.repository.name }} \
--apt-server-config "deb [arch=arm64 trusted=yes] http://localhost:${{ env.PPA_HTTP_SERVER_PORT }} noble/stable main"
--apt-server-config "deb [arch=${{ env.PRODUCT_ARCH }} trusted=yes] ${{ env.PPA_URL }} ${{ env.PRODUCT_CODENAME }}/stable main" \
--result-file ./results.txt

RET=$?
set -e
set -e

echo "ABI check returned $RET"

# (0): RETURN_ABI_NO_DIFF
Expand All @@ -120,55 +134,86 @@ jobs:
# Bit 4 (16): RETURN_PPA_ERROR

if (( RET == 0 )); then
echo "ABI check passed"
echo "ABI check returned NO_DIFF"
fi

if (( RET & 1 )); then
echo "ABI check returned COMPATIBLE DIFF"
echo "⚠️ABI check returned COMPATIBLE DIFF"
fi

if (( RET & 2 )); then
echo "ABI check returned INCOMPATIBLE DIFF"
echo "⚠️ABI check returned INCOMPATIBLE DIFF"
fi

if (( RET & 4 )); then
echo "ABI check returned STRIPPED PACKAGE"
echo "❌ ABI check returned STRIPPED PACKAGE"
exit 1
fi

if (( RET & 8 )); then
echo "ABI check failed because the PPA did not contained an old version for the package."
echo "⚠️ABI check failed because the PPA did not contained an old version for the package."
echo "Assumption is that this is the first time the package was build."
echo "INITIAL_UPLOAD_TO_PPA=true" >> $GITHUB_ENV
fi

if (( RET & 16 )); then
echo "ABI check failed because there was an error on the PPA"
echo "❌ ABI check failed because there was an error on the PPA"
exit 1
fi

- name: Upload Debian Package To PPA Server If First Build
if: ${{ env.INITIAL_UPLOAD_TO_PPA == 'true' }}
echo "ABI_CHECK_RETURN_VALUE=${RET}" >> $GITHUB_ENV

- name: Package Version Increment Check
if: ${{ env.INITIAL_UPLOAD_TO_PPA == 'false' }}
run: |
echo "Uploading Debian Package To PPA Server..."
cp -r ./WORKSPACE/debian_packages/oss/ ${{ env.PPA_HTTP_DIRECTORY }}
echo "Copied, here is the new tree of the PPA :"; tree ${{ env.PPA_HTTP_DIRECTORY }}
echo "Run package version check here with ret value ${{ env.ABI_CHECK_RETURN_VALUE }}"
echo "Content of result file :"
cat ./results.txt

if grep -qE '^\s*-\s*Version:\s*.*FAIL' ./results.txt; then
echo "❌ Test failed: At least one FAIL found in - Version: line"
exit 1
else
echo "✅ Test passed: All versions are PASS"
fi

echo "Removing olf Packages/.gz files"
- name: Checkout PPA staging repo
if: ${{ env.INITIAL_UPLOAD_TO_PPA == 'true' }}
uses: actions/checkout@v4
with:
repository: qualcomm-linux/qcom-oss-staging-ppa
ref: main
ssh-key: ${{ secrets.ACTIONS_SSH_KEY }}
path: ./qcom-oss-staging-ppa
fetch-depth: 1

rm -f ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages || true
rm -f ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages.gz || true
- name: Upload Debian Packages To PPA Server If First Build
if: ${{ env.INITIAL_UPLOAD_TO_PPA == 'true' }}
run: |
echo "Uploading Debian Package To PPA Server : ${{ env.PPA_URL }}"

echo "Updating the Packages/.gz files"
for dir in ./WORKSPACE/debian_packages/oss/*/; do
PACKAGE=$(basename $dir)
echo "Creating directory for package $PACKAGE" in the PPA
mkdir -p ./qcom-oss-staging-ppa/pool/${{env.PRODUCT_CODENAME}}/stable/main/$PACKAGE

touch ${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages
echo "Packages to copy for $PACKAGE: "; ls ./WORKSPACE/debian_packages/oss/$PACKAGE

for dir in ${{ env.PPA_HTTP_DIRECTORY }}/oss/*/; do
echo "Updating packages for dir $dir"
dpkg-scanpackages "$dir" | sed 's|/var/www/html/github-actions-ppa/||' >> "${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages"
dpkg-scanpackages --type ddeb "$dir" | sed 's|/var/www/html/github-actions-ppa/||' >> "${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages"
cp ./WORKSPACE/debian_packages/oss/$PACKAGE/* ./qcom-oss-staging-ppa/pool/${{env.PRODUCT_CODENAME}}/stable/main/$PACKAGE
done

gzip -9 < "${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages" > "${{ env.PPA_HTTP_DIRECTORY }}/dists/noble/stable/main/binary-arm64/Packages.gz"
cd ./qcom-oss-staging-ppa

dpkg-scanpackages --multiversion pool/${{ env.PRODUCT_CODENAME }} > ${{ env.PPA_PACKAGES_FILE_REPO_PATH }}/Packages
dpkg-scanpackages --type ddeb --multiversion pool/${{ env.PRODUCT_CODENAME }} >> ${{ env.PPA_PACKAGES_FILE_REPO_PATH }}/Packages

gzip -k -f ${{ env.PPA_PACKAGES_FILE_REPO_PATH }}/Packages

echo "Updated the packages.gz files"
cat ${{ env.PPA_PACKAGES_FILE_REPO_PATH }}/Packages

git add .

#TODO craft decent message
git commit -s -m "Uploaded Packages"

echo "Updated the Packages files for suite: noble"
git push
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading