forgego: add package version checks
This commit is contained in:
parent
a0e397c918
commit
4953c4c159
4 changed files with 256 additions and 0 deletions
35
.forgejo/bin/check_ver.sh
Executable file
35
.forgejo/bin/check_ver.sh
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# expects the following env variables:
|
||||||
|
# downstream: downstream repo
|
||||||
|
|
||||||
|
repo=${downstream/*\/}
|
||||||
|
|
||||||
|
curl --silent $downstream/x86_64/APKINDEX.tar.gz | tar -O -zx APKINDEX > APKINDEX
|
||||||
|
|
||||||
|
owned_by_you=$(awk -v RS= -v ORS="\n\n" '/m:Antoine Martin \(ayakael\) <dev@ayakael.net>/' APKINDEX | awk -F ':' '{if($1=="o"){print $2}}' | sort | uniq)
|
||||||
|
|
||||||
|
echo "Found $(printf '%s\n' $owned_by_you | wc -l ) packages owned by you"
|
||||||
|
|
||||||
|
rm -f out_of_date not_in_anitya
|
||||||
|
|
||||||
|
for pkg in $owned_by_you; do
|
||||||
|
if $CHECK_LATEST; then
|
||||||
|
upstream_version=$(curl --fail -X GET -sS -H 'Content-Type: application/json' "https://release-monitoring.org/api/v2/packages/?name=$pkg&distribution=Alpine" | jq -r '.items.[].version')
|
||||||
|
else
|
||||||
|
upstream_version=$(curl --fail -X GET -sS -H 'Content-Type: application/json' "https://release-monitoring.org/api/v2/packages/?name=$pkg&distribution=Alpine" | jq -r '.items.[].stable_version')
|
||||||
|
fi
|
||||||
|
downstream_version=$(sed -n "/^P:$pkg$/,/^$/p" APKINDEX | awk -F ':' '{if($1=="V"){print $2}}' | sort -V | tail -n 1)
|
||||||
|
downstream_version=${downstream_version/-*}
|
||||||
|
|
||||||
|
if [ -z "$upstream_version" ]; then
|
||||||
|
echo "$pkg not in anitya"
|
||||||
|
echo "$pkg" >> not_in_anitya
|
||||||
|
elif [ "$downstream_version" != "$(printf '%s\n' $upstream_version $downstream_version | sort -V | head -n 1)" ]; then
|
||||||
|
echo "$pkg higher downstream"
|
||||||
|
continue
|
||||||
|
elif [ "$upstream_version" != "$downstream_version" ]; then
|
||||||
|
echo "$pkg upstream version $upstream_version does not match downstream version $downstream_version"
|
||||||
|
echo "$pkg $downstream_version $upstream_version $repo" >> out_of_date
|
||||||
|
fi
|
||||||
|
done
|
165
.forgejo/bin/create_issue.sh
Executable file
165
.forgejo/bin/create_issue.sh
Executable file
|
@ -0,0 +1,165 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# expects:
|
||||||
|
# env variable FORGEJO_TOKEN
|
||||||
|
# file out_of_date
|
||||||
|
|
||||||
|
IFS='
|
||||||
|
'
|
||||||
|
repo=${downstream/*\/}
|
||||||
|
|
||||||
|
does_it_exist() {
|
||||||
|
name=$1
|
||||||
|
downstream_version=$2
|
||||||
|
upstream_version=$3
|
||||||
|
repo=$4
|
||||||
|
|
||||||
|
query="$repo/$name: upgrade to $upstream_version"
|
||||||
|
query="$(echo $query | sed 's| |%20|g' | sed 's|:|%3A|g' | sed 's|/|%2F|g' )"
|
||||||
|
|
||||||
|
result="$(curl --silent -X 'GET' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues?state=open&q=$query&type=issues" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN"
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [ "$result" == "[]" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_it_old() {
|
||||||
|
name=$1
|
||||||
|
downstream_version=$2
|
||||||
|
upstream_version=$3
|
||||||
|
repo=$4
|
||||||
|
|
||||||
|
query="$repo/$name: upgrade to"
|
||||||
|
query="$(echo $query | sed 's| |%20|g' | sed 's|:|%3A|g' | sed 's|/|%2F|g' )"
|
||||||
|
|
||||||
|
result="$(curl --silent -X 'GET' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues?state=open&q=$query&type=issues" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN"
|
||||||
|
)"
|
||||||
|
|
||||||
|
result_title="$(echo $result | jq -r '.[].title' )"
|
||||||
|
result_id="$(echo $result | jq -r '.[].number' )"
|
||||||
|
result_upstream_version="$(echo $result_title | awk '{print $4}')"
|
||||||
|
|
||||||
|
if [ "$upstream_version" != "$result_upstream_version" ]; then
|
||||||
|
echo $result_id
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_title() {
|
||||||
|
name=$1
|
||||||
|
downstream_version=$2
|
||||||
|
upstream_version=$3
|
||||||
|
repo=$4
|
||||||
|
id=$5
|
||||||
|
|
||||||
|
result=$(curl --silent -X 'PATCH' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues/$id" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d "{
|
||||||
|
\"title\": \"$repo/$name: upgrade to $upstream_version\"
|
||||||
|
}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
create_issue() {
|
||||||
|
name=$1
|
||||||
|
downstream_version=$2
|
||||||
|
upstream_version=$3
|
||||||
|
repo=$4
|
||||||
|
|
||||||
|
result=$(curl --silent -X 'POST' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d "{
|
||||||
|
\"title\": \"$repo/$name: upgrade to $upstream_version\",
|
||||||
|
\"labels\": [
|
||||||
|
$LABEL_NUMBER
|
||||||
|
]
|
||||||
|
}")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -f out_of_date ]; then
|
||||||
|
out_of_date="$(cat out_of_date)"
|
||||||
|
|
||||||
|
echo "Detected $(wc -l out_of_date) out-of-date packages, creating issues"
|
||||||
|
|
||||||
|
for pkg in $out_of_date; do
|
||||||
|
name="$(echo $pkg | awk '{print $1}')"
|
||||||
|
downstream_version="$(echo $pkg | awk '{print $2}')"
|
||||||
|
upstream_version="$(echo $pkg | awk '{print $3}')"
|
||||||
|
repo="$(echo $pkg | awk '{print $4}')"
|
||||||
|
|
||||||
|
if does_it_exist $name $downstream_version $upstream_version $repo; then
|
||||||
|
echo "Issue for $repo/$name already exists"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
id=$(is_it_old $name $downstream_version $upstream_version $repo)
|
||||||
|
|
||||||
|
if [ "$id" != "0" ] && [ -n "$id" ]; then
|
||||||
|
echo "Issue for $repo/$name needs updating"
|
||||||
|
update_title $name $downstream_version $upstream_version $repo $id
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating issue for $repo/$name"
|
||||||
|
create_issue $name $downstream_version $upstream_version $repo
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f not_in_anitya ]; then
|
||||||
|
query="Add missing $repo packages to anitya"
|
||||||
|
query="$(echo $query | sed 's| |%20|g')"
|
||||||
|
|
||||||
|
result="$(curl --silent -X 'GET' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues?state=open&q=$query&type=issues" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN"
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [ "$result" == "[]" ]; then
|
||||||
|
echo "Creating anitya issue"
|
||||||
|
result=$(curl --silent -X 'POST' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d "{
|
||||||
|
\"title\": \"Add missing $repo packages to anitya\",
|
||||||
|
\"body\": \"- [ ] $(sed '{:q;N;s/\n/\\n- [ ] /g;t q}' not_in_anitya)\",
|
||||||
|
\"labels\": [
|
||||||
|
$LABEL_NUMBER
|
||||||
|
]
|
||||||
|
}")
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "Updating anitya issue"
|
||||||
|
result_id="$(echo $result | jq -r '.[].number' )"
|
||||||
|
result=$(curl --silent -X 'PATCH' \
|
||||||
|
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/issues/$result_id" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H "authorization: Basic $FORGEJO_TOKEN" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d "{
|
||||||
|
\"body\": \"- [ ] $(sed '{:q;N;s/\n/\\n- [ ] /g;t q}' not_in_anitya)\"
|
||||||
|
}"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
fi
|
28
.forgejo/workflows/check-r4.2.yml
Normal file
28
.forgejo/workflows/check-r4.2.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
schedule:
|
||||||
|
- cron: '0 5 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-r4.2:
|
||||||
|
name: Check user repo
|
||||||
|
runs-on: x86_64
|
||||||
|
container:
|
||||||
|
image: alpine:latest
|
||||||
|
env:
|
||||||
|
downstream: https://ayakael.net/api/packages/forge/alpine/edge/qubes-r4.2
|
||||||
|
FORGEJO_TOKEN: ${{ secrets.forgejo_token }}
|
||||||
|
LABEL_NUMBER: 9
|
||||||
|
CHECK_LATEST: 0
|
||||||
|
steps:
|
||||||
|
- name: Environment setup
|
||||||
|
run: apk add grep coreutils gawk curl wget bash nodejs git jq sed
|
||||||
|
- name: Get scripts
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
- name: Check out-of-date packages
|
||||||
|
run: ${{ github.workspace }}/.forgejo/bin/check_ver.sh
|
||||||
|
- name: Create issues
|
||||||
|
run: ${{ github.workspace }}/.forgejo/bin/create_issue.sh
|
28
.forgejo/workflows/check-r4.3.yml
Normal file
28
.forgejo/workflows/check-r4.3.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
schedule:
|
||||||
|
- cron: '0 5 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-r4.3:
|
||||||
|
name: Check user repo
|
||||||
|
runs-on: x86_64
|
||||||
|
container:
|
||||||
|
image: alpine:latest
|
||||||
|
env:
|
||||||
|
downstream: https://ayakael.net/api/packages/forge/alpine/edge/qubes-r4.3
|
||||||
|
FORGEJO_TOKEN: ${{ secrets.forgejo_token }}
|
||||||
|
LABEL_NUMBER: 9
|
||||||
|
CHECK_LATEST: 1
|
||||||
|
steps:
|
||||||
|
- name: Environment setup
|
||||||
|
run: apk add grep coreutils gawk curl wget bash nodejs git jq sed
|
||||||
|
- name: Get scripts
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
- name: Check out-of-date packages
|
||||||
|
run: ${{ github.workspace }}/.forgejo/bin/check_ver.sh
|
||||||
|
- name: Create issues
|
||||||
|
run: ${{ github.workspace }}/.forgejo/bin/create_issue.sh
|
Loading…
Reference in a new issue