Skip to content

CI: test build

CI: test build #4

Workflow file for this run

name: Check Shape
on:
workflow_dispatch:
inputs:
base_ref:
description: 'Base ref of the PR to build against'
required: true
type: 'string'
pr_name:
description: 'PR name to use as run-name'
required: true
type: 'string'
pr_number:
description: 'PR number to build'
required: true
type: 'string'
permissions:
contents: read
statuses: write
run-name: ${{ inputs.pr_name }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
name: Check Shape
runs-on: ubuntu-latest
steps:
- name: Check PR status
id: check_pr
uses: actions/github-script@v8
env:
PR_NUMBER: ${{ inputs.pr_number }}
with:
script: |
const pr_number = process.env.PR_NUMBER;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
});
if (pr.state !== 'open') {
core.setFailed(`Pull Request #${pr_number} is not open (state: ${pr.state}). Aborting build.`);
return;
}
core.setOutput('head_sha', pr.head.sha);
- name: Set check status as pending
env:
# Token needs statuses: write
TOKEN: ${{ secrets.GITHUB_TOKEN }}
API_URL: https://api.github.com/repos/${{ github.repository }}/statuses/${{ steps.check_pr.outputs.head_sha }}
CONTEXT: ${{ github.workflow }}
OUTCOME: pending
TARGET_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ job.check_run_id }}?pr=${{ inputs.pr_number }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"$API_URL" \
-d '{"state":"'"$OUTCOME"'","target_url":"'"$TARGET_URL"'","context":"'"$CONTEXT"'"}'
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Determine branch name
env:
BASE_REF: ${{ inputs.base_ref }}
run: |
BRANCH="$BASE_REF"
case "$BRANCH" in
main|master|openwrt-[0-9]*\.[0-9]*)
;;
*)
BRANCH="master"
;;
esac
echo "Building for $BRANCH"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Determine changed packages
run: |
# only detect packages with changes
PKG_ROOTS=$(find . -name Makefile | \
grep -v ".*/src/Makefile" | \
sed -e 's@./\(.*\)/Makefile@\1/@')
CHANGES=$(git diff --diff-filter=d --name-only origin/$BRANCH...)
for ROOT in $PKG_ROOTS; do
for CHANGE in $CHANGES; do
if [[ "$CHANGE" == "$ROOT"* ]]; then
PACKAGES+=$(echo "$ROOT" | sed -e 's@\(.*/\)*\(.*\)/@\2 @')
break
fi
done
done
# fallback to test packages if nothing explicitly changes this is
# should run if other mechanics in packages.git changed
REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
if [ "$REPOSITORY_NAME" = "routing" ]; then
PACKAGES="${PACKAGES:-bird2 cjdns olsrd}"
elif [ "$REPOSITORY_NAME" = "telephony" ]; then
PACKAGES="${PACKAGES:-asterisk siproxd freeswitch}"
else
PACKAGES="${PACKAGES:-vim attendedsysupgrade-common bmon}"
fi
echo "Building $PACKAGES"
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
- name: Check package shape
id: check
uses: georgesapkin/openwrt-gh-action-sdk@entrypoint-make-build-optional
env:
ARCH: x86_64-${{ env.BRANCH }}
BUILD: 0
BUILD_LOG: 0
FEEDNAME: packages_ci
V: s
- name: Set final check status
if: always()
env:
# Token needs statuses: write
TOKEN: ${{ secrets.GITHUB_TOKEN }}
API_URL: https://api.github.com/repos/${{ github.repository }}/statuses/${{ steps.check_pr.outputs.head_sha }}
CONTEXT: ${{ github.workflow }}
OUTCOME: ${{ steps.check.outcome }}
TARGET_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ job.check_run_id }}?pr=${{ inputs.pr_number }}
run: |
case $OUTCOME in
success) state="success" ;;
*) state="failure" ;;
esac
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"$API_URL" \
-d '{"state":"'"$state"'","target_url":"'"$TARGET_URL"'","context":"'"$CONTEXT"'"}'