Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add workflow to check package dependencies #187

Merged
merged 5 commits into from
Mar 13, 2024
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
62 changes: 62 additions & 0 deletions .github/scripts/pkg-deps/pkg-deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

set -e

export LC_COLLATE=C

if [[ -z "$branch" ]]; then
echo "error: no branch specified" >&2
exit 1
fi

version=$(echo "$branch" | grep -Eo '[0-9.]+')
docker run -i -d --rm --name ubuntu ubuntu:"$version" >&2

cleanup() {
docker rm -f ubuntu >&2
}
trap cleanup EXIT

docker exec ubuntu apt-get update >&2

msg_file="${msg_file:-$(mktemp)}"
echo "Writing dependencies diff to $msg_file" >&2
if [[ -n "$GITHUB_OUTPUT" ]]; then
echo "msg_file=$msg_file" >> $GITHUB_OUTPUT
fi

echo -e "Diff of dependencies:\n" > "$msg_file"
for f in $@; do
echo "Processing $f.." >&2
pkg=$(yq '.package' "$f")

fupstream="$(mktemp)"
docker exec ubuntu apt depends \
--no-recommends --no-suggests --no-conflicts \
--no-breaks --no-replaces --no-enhances \
"$pkg" 2>/dev/null | \
sed -nr 's/.*Depends:\s(\S*).*/\1/p' | \
sed 's/<//; s/>//; s/:any//' | \
sort | uniq > "$fupstream"

flocal="$(mktemp)"
yq '.slices.[].essential[]' "$f" | \
sed "s/_.*//; /^$pkg$/d" | sort | uniq > "$flocal"

fdiff="$(mktemp)"
if ! diff -u "$fupstream" "$flocal" > "$fdiff"; then
echo "<details>" >> "$msg_file"
echo -e "<summary>$f</summary>\n" >> "$msg_file"
echo "\`\`\`diff" >> "$msg_file"
cat "$fdiff" | tail -n +3 >> "$msg_file"
echo "\`\`\`" >> "$msg_file"
echo -e "\n</details>" >> "$msg_file"
fi
done

if ! grep "<summary>" "$msg_file"; then
echo -e "\tNone found." >> "$msg_file"
fi

echo -e "\n---" >> "$msg_file"
cat "$msg_file"
52 changes: 52 additions & 0 deletions .github/workflows/pkg-deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Package dependencies

on:
workflow_call:

jobs:
check-dependency:
name: Check dependency
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' &&
rebornplusplus marked this conversation as resolved.
Show resolved Hide resolved
startswith(github.base_ref, 'ubuntu-')
env:
branch: ${{ github.base_ref }}
main-branch-path: files-from-main
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4

- name: Check changed paths
id: changed-paths
uses: dorny/paths-filter@v3
with:
# ref: https://github.com/marketplace/actions/paths-changes-filter
filters: |
slices:
- added|modified: 'slices/**/*.yaml'
# Space delimited list usable as command-line argument list in
# Linux shell. If needed, it uses single or double quotes to
# wrap filename with unsafe characters.
list-files: shell

- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
path: ${{ env.main-branch-path }}

- name: Check dependencies
id: check-deps
env:
script-dir: "${{ env.main-branch-path }}/.github/scripts/pkg-deps"
run: |
set -ex
./${{ env.script-dir }}/pkg-deps \
${{ steps.changed-paths.outputs.slices_files }}

- name: Post messages to PR
uses: mshick/add-pr-comment@v2
with:
message-path: ${{ steps.check-deps.outputs.msg_file }}
Loading