ci: use async aptly publish

This commit is contained in:
André Roth
2024-09-14 17:34:20 +02:00
parent a22dc9be1b
commit 8e8cf90a71
2 changed files with 60 additions and 65 deletions

View File

@@ -131,7 +131,7 @@ jobs:
- name: "Install packages"
run: |
apt-get update
apt-get install -y --no-install-recommends make ca-certificates git curl build-essential devscripts dh-golang binutils-i686-linux-gnu binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf
apt-get install -y --no-install-recommends make ca-certificates git curl build-essential devscripts dh-golang binutils-i686-linux-gnu binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf jq
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: "Checkout repository"
@@ -164,7 +164,7 @@ jobs:
cd build && ls -l *.deb
- name: "Publish CI release to aptly"
if: github.ref == 'refs/heads/master'
# if: github.ref == 'refs/heads/master'
env:
APTLY_USER: ${{ secrets.APTLY_USER }}
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}

View File

@@ -14,23 +14,26 @@ action=$1
dist=$2
usage() {
echo "Usage: $0 nighly jammy|focal|bookworm" >&2
echo "Usage: $0 ci buster|bullseye|bookworm|focal|jammy" >&2
echo " $0 release" >&2
}
# repos and publish must be created before using this script:
# repos and publish must be created beforehand:
#!/bin/sh
#
#for dist in buster bullseye bookworm focal jammy
#for dist in buster bullseye bookworm focal jammy noble
#do
# aptly repo create -distribution=$dist -component=main aptly-ci-$dist
# aptly publish repo -multi-dist -architectures="amd64,i386,arm64,armhf" -acquire-by-hash \
# -component=main -distribution=$dist -batch -keyring=aptly.pub aptly-ci-$dist \
# s3:repo.aptly.info:ci
# for build in ci release
# do
# echo
# echo "# Creating and publishing $build/$dist"
# aptly repo create -distribution=$dist -component=main aptly-$build-$dist
# aptly publish repo -multi-dist -architectures="amd64,i386,arm64,armhf" -acquire-by-hash -component=main \
# -distribution=$dist -batch -keyring=aptly.pub \
# aptly-$build-$dist \
# s3:repo.aptly.info:$build
# done
#done
if [ -z "$action" ]; then
usage
exit 1
@@ -48,18 +51,35 @@ upload()
echo "\nUploading files:"
for file in $packages; do
echo " - $file"
curl -fsS -X POST -F "file=@$file" -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder
jsonret=`curl -fsS -X POST -F "file=@$file" -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder`
done
echo
}
cleanup() {
echo "\nCleanup..."
curl -fsS -X DELETE -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder
echo
jsonret=`curl -fsS -X DELETE -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder`
}
trap cleanup EXIT
update_publish() {
_publish=$1
_dist=$2
jsonret=`curl -fsS -X PUT -H 'Content-Type: application/json' --data \
'{"AcquireByHash": true, "MultiDist": true,
"Signing": {"Batch": true, "Keyring": "aptly.repo/aptly.pub", "secretKeyring": "aptly.repo/aptly.sec", "PassphraseFile": "aptly.repo/passphrase"}}' \
-u $aptly_user:$aptly_password ${aptly_api}/api/publish/$_publish/$_dist?_async=true`
_task_id=`echo $jsonret | jq .ID`
for t in `seq 180`
do
jsonret=`curl -fsS -u $aptly_user:$aptly_password ${aptly_api}/api/tasks/$_task_id`
_state=`echo $jsonret | jq .State`
if [ "$_state" = "2" ]; then
break
fi
sleep 1
done
}
if [ "$action" = "ci" ]; then
if echo "$version" | grep -vq "+"; then
# skip ci when on release tag
@@ -77,56 +97,31 @@ fi
upload
echo "\nAdding packages to $aptly_repository ..."
curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder
echo
jsonret=`curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder`
echo "\nUpdating published repo $aptly_published ..."
curl -fsS -X PUT -H 'Content-Type: application/json' --data \
'{"AcquireByHash": true, "MultiDist": true,
"Signing": {"Batch": true, "Keyring": "aptly.repo/aptly.pub", "secretKeyring": "aptly.repo/aptly.sec", "PassphraseFile": "aptly.repo/passphrase"}}' \
-u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published/$dist
echo
update_publish $aptly_published $dist
if [ $dist = "focal" ]; then
echo "\nUpdating legacy nightly repo..."
aptly_repository=aptly-nightly
aptly_published=s3:repo.aptly.info:./nightly
upload
echo "\nAdding packages to $aptly_repository ..."
curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder
echo
echo "\nUpdating published repo $aptly_published ..."
curl -fsS -X PUT -H 'Content-Type: application/json' --data \
'{"AcquireByHash": true, "Signing": {"Batch": true, "Keyring": "aptly.repo/aptly.pub",
"secretKeyring": "aptly.repo/aptly.sec", "PassphraseFile": "aptly.repo/passphrase"}}' \
-u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published
echo
fi
if [ "$action" = "OBSOLETErelease" ]; then
aptly_repository=aptly-release
aptly_snapshot=aptly-$version
aptly_published=s3:repo.aptly.info:./squeeze
echo "\nAdding packages to $aptly_repository..."
curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder
echo
echo "\nCreating snapshot $aptly_snapshot from repo $aptly_repository..."
curl -fsS -X POST -u $aptly_user:$aptly_password -H 'Content-Type: application/json' --data \
"{\"Name\":\"$aptly_snapshot\"}" ${aptly_api}/api/repos/$aptly_repository/snapshots
echo
echo "\nSwitching published repo $aptly_published to use snapshot $aptly_snapshot..."
curl -fsS -X PUT -H 'Content-Type: application/json' --data \
"{\"AcquireByHash\": true, \"Snapshots\": [{\"Component\": \"main\", \"Name\": \"$aptly_snapshot\"}],
\"Signing\": {\"Batch\": true, \"Keyring\": \"aptly.repo/aptly.pub\",
\"secretKeyring\": \"aptly.repo/aptly.sec\", \"PassphraseFile\": \"aptly.repo/passphrase\"}}" \
-u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published
echo
fi
# if [ "$action" = "OBSOLETErelease" ]; then
# aptly_repository=aptly-release
# aptly_snapshot=aptly-$version
# aptly_published=s3:repo.aptly.info:./squeeze
#
# echo "\nAdding packages to $aptly_repository..."
# curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder
# echo
#
# echo "\nCreating snapshot $aptly_snapshot from repo $aptly_repository..."
# curl -fsS -X POST -u $aptly_user:$aptly_password -H 'Content-Type: application/json' --data \
# "{\"Name\":\"$aptly_snapshot\"}" ${aptly_api}/api/repos/$aptly_repository/snapshots
# echo
#
# echo "\nSwitching published repo $aptly_published to use snapshot $aptly_snapshot..."
# curl -fsS -X PUT -H 'Content-Type: application/json' --data \
# "{\"AcquireByHash\": true, \"Snapshots\": [{\"Component\": \"main\", \"Name\": \"$aptly_snapshot\"}],
# \"Signing\": {\"Batch\": true, \"Keyring\": \"aptly.repo/aptly.pub\",
# \"secretKeyring\": \"aptly.repo/aptly.sec\", \"PassphraseFile\": \"aptly.repo/passphrase\"}}" \
# -u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published
# echo
# fi