mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-26 18:53:01 +02:00
Allow a workflow caller to run pre-build scripts though a workflow call variable. This is potentially dangerous as code can be injected here. If for example a malicious actor wants to run there C2 code in the context of someone else they could perhaps inject it here. I assume this is protected by the same mecahism as the workflow files themself. I.e. github users untrusted to the Infix org won't be able to trigger workflows before being explicitly allowed to do so. This patch also adds a checkout secret. This allows upstream callers to fetch there own spin / fork though the infix workflows, if they provide a checkout token with the correct permissions to do so. Signed-off-by: Richard Alpe <richard@bit42.se>
199 lines
6.3 KiB
YAML
199 lines
6.3 KiB
YAML
name: Build
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
target:
|
|
description: "Build target (e.g. aarch64 or aarch64_minimal)"
|
|
default: "x86_64"
|
|
type: string
|
|
parallel:
|
|
description: 'Massive parallel build of each image'
|
|
default: true
|
|
type: boolean
|
|
name:
|
|
description: "Name (for spin overrides)"
|
|
default: "infix"
|
|
type: string
|
|
infix_repo:
|
|
description: 'Repo to checkout (for spin overrides)'
|
|
default: kernelkit/infix
|
|
type: string
|
|
|
|
workflow_call:
|
|
inputs:
|
|
target:
|
|
required: true
|
|
type: string
|
|
name:
|
|
required: true
|
|
type: string
|
|
infix_repo:
|
|
required: false
|
|
type: string
|
|
default: kernelkit/infix
|
|
parallel:
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
pre_build_script:
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
description: 'Optional script to run after checkout (for spin customization)'
|
|
secrets:
|
|
CHECKOUT_TOKEN:
|
|
required: false
|
|
description: 'Token for cross-repository access'
|
|
|
|
env:
|
|
NAME: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.name || inputs.name }}
|
|
TARGET: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target || inputs.target }}
|
|
INFIX_REPO: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.infix_repo || inputs.infix_repo }}
|
|
|
|
jobs:
|
|
build:
|
|
name: Build ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.name || inputs.name }} ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target || inputs.target }}
|
|
runs-on: [ self-hosted, latest ]
|
|
env:
|
|
PARALLEL: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.parallel == 'true' || github.event_name != 'workflow_dispatch' && inputs.parallel == true }}
|
|
strategy:
|
|
fail-fast: false
|
|
outputs:
|
|
build_id: ${{ steps.vars.outputs.INFIX_BUILD_ID }}
|
|
steps:
|
|
- name: Cleanup Build Folder
|
|
run: |
|
|
ls -la ./
|
|
rm -rf ./* || true
|
|
rm -rf ./.??* || true
|
|
ls -la ./
|
|
- name: Cleanup podman state
|
|
run: |
|
|
set -x
|
|
podman ps -a || true
|
|
podman stop -a || true
|
|
podman rm -a -f || true
|
|
podman volume prune -f || true
|
|
podman system prune -a -f || true
|
|
podman system migrate || true
|
|
|
|
- name: Checkout infix repo
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ env.INFIX_REPO }}
|
|
ref: ${{ github.ref }}
|
|
clean: true
|
|
fetch-depth: 0
|
|
submodules: recursive
|
|
token: ${{ secrets.CHECKOUT_TOKEN || github.token }}
|
|
|
|
- name: Run pre-build script
|
|
if: ${{ inputs.pre_build_script != '' }}
|
|
run: |
|
|
cat > ./pre-build.sh << 'EOF'
|
|
${{ inputs.pre_build_script }}
|
|
EOF
|
|
chmod +x ./pre-build.sh
|
|
bash ./pre-build.sh
|
|
|
|
- name: Set Build Variables
|
|
id: vars
|
|
run: |
|
|
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
|
|
# Since PRs are built from an internally generated merge
|
|
# commit, reverse lookups of PRs and/or commits from
|
|
# image version information are cumbersome. Therefore:
|
|
# explicitly set a build id that references both the PR
|
|
# and the commit.
|
|
printf "INFIX_BUILD_ID=pr%d.%.7s\n" \
|
|
"${{ github.event.number }}" "${{ github.event.pull_request.head.sha }}" \
|
|
| tee -a $GITHUB_OUTPUT $GITHUB_ENV
|
|
fi
|
|
|
|
target=${{ env.TARGET }}
|
|
name=${{ env.NAME }}
|
|
echo "dir=${name}-${target}" >> $GITHUB_OUTPUT
|
|
echo "tgz=${name}-${target}.tar.gz" >> $GITHUB_OUTPUT
|
|
echo "Building target ${target}_defconfig"
|
|
|
|
- name: Restore Cache of dl/
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: dl/
|
|
key: dl-${{ hashFiles('.git/modules/buildroot/HEAD', 'configs/*', 'package/*/*.hash') }}
|
|
restore-keys: |
|
|
dl-
|
|
|
|
- name: Restore Cache of .ccache/
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: .ccache/
|
|
key: ccache-${{ env.TARGET }}-${{ hashFiles('.git/modules/buildroot/HEAD', 'package/*/*.hash') }}
|
|
restore-keys: |
|
|
ccache-${{ env.TARGET }}-
|
|
ccache-
|
|
|
|
- name: Configure ${{ env.TARGET }}
|
|
run: |
|
|
make ${{ env.TARGET }}_defconfig
|
|
|
|
- name: Cleanup stale containers and ports
|
|
run: |
|
|
podman rm -af || true
|
|
pkill -9 -f rootlessport || true
|
|
|
|
- name: Unit Test ${{ env.TARGET }}
|
|
run: |
|
|
make test-unit
|
|
|
|
- name: Prepare parallel build
|
|
id: parallel
|
|
run: |
|
|
|
|
if [ "$PARALLEL" == "true" ]; then
|
|
echo "BR2_PER_PACKAGE_DIRECTORIES=y" >> output/.config
|
|
MAKE="make -j$((`getconf _NPROCESSORS_ONLN` / 2 + 2))"
|
|
echo "Building in parallel with -j$((`getconf _NPROCESSORS_ONLN` / 2 + 2))"
|
|
else
|
|
echo "Disabling parallel build"
|
|
MAKE="make"
|
|
fi
|
|
echo "MAKE=$MAKE" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build ${{ env.TARGET }}
|
|
run: |
|
|
echo "Building ${{ env.TARGET }}_defconfig ..."
|
|
eval "${{ steps.parallel.outputs.MAKE }}"
|
|
|
|
- name: Check SBOM from Build
|
|
run: |
|
|
make legal-info
|
|
|
|
- name: Build test specification
|
|
run: |
|
|
make test-spec
|
|
|
|
- name: Resulting size of build
|
|
run: |
|
|
printf "Size of complete tree : "
|
|
du -sh .
|
|
printf "Size of output/ : "
|
|
du -sh output
|
|
printf "Size of dl/ : "
|
|
du -sh dl
|
|
printf "Size of output/images/: "
|
|
ls -l output/images/
|
|
|
|
- name: Prepare ${{ env.TARGET }} Artifact
|
|
run: |
|
|
cd output/
|
|
mv images ${{ steps.vars.outputs.dir }}
|
|
ln -s ${{ steps.vars.outputs.dir }} images
|
|
tar cfz ${{ steps.vars.outputs.tgz }} ${{ steps.vars.outputs.dir }}
|
|
|
|
- uses: actions/upload-artifact@v4
|
|
with:
|
|
path: output/${{ steps.vars.outputs.tgz }}
|
|
name: artifact-${{ env.TARGET }}
|