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
+2 -2
View File
@@ -131,7 +131,7 @@ jobs:
- name: "Install packages" - name: "Install packages"
run: | run: |
apt-get update 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" git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: "Checkout repository" - name: "Checkout repository"
@@ -164,7 +164,7 @@ jobs:
cd build && ls -l *.deb cd build && ls -l *.deb
- name: "Publish CI release to aptly" - name: "Publish CI release to aptly"
if: github.ref == 'refs/heads/master' # if: github.ref == 'refs/heads/master'
env: env:
APTLY_USER: ${{ secrets.APTLY_USER }} APTLY_USER: ${{ secrets.APTLY_USER }}
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }} APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}
+58 -63
View File
@@ -14,22 +14,25 @@ action=$1
dist=$2 dist=$2
usage() { usage() {
echo "Usage: $0 nighly jammy|focal|bookworm" >&2 echo "Usage: $0 ci buster|bullseye|bookworm|focal|jammy" >&2
echo " $0 release" >&2 echo " $0 release" >&2
} }
# repos and publish must be created before using this script: # repos and publish must be created beforehand:
#!/bin/sh #!/bin/sh
# #for dist in buster bullseye bookworm focal jammy noble
#for dist in buster bullseye bookworm focal jammy
#do #do
# aptly repo create -distribution=$dist -component=main aptly-ci-$dist # for build in ci release
# aptly publish repo -multi-dist -architectures="amd64,i386,arm64,armhf" -acquire-by-hash \ # do
# -component=main -distribution=$dist -batch -keyring=aptly.pub aptly-ci-$dist \ # echo
# s3:repo.aptly.info:ci # 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 #done
if [ -z "$action" ]; then if [ -z "$action" ]; then
usage usage
@@ -48,18 +51,35 @@ upload()
echo "\nUploading files:" echo "\nUploading files:"
for file in $packages; do for file in $packages; do
echo " - $file" 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 done
echo
} }
cleanup() { cleanup() {
echo "\nCleanup..." echo "\nCleanup..."
curl -fsS -X DELETE -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder jsonret=`curl -fsS -X DELETE -u $aptly_user:$aptly_password ${aptly_api}/api/files/$folder`
echo
} }
trap cleanup EXIT 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 [ "$action" = "ci" ]; then
if echo "$version" | grep -vq "+"; then if echo "$version" | grep -vq "+"; then
# skip ci when on release tag # skip ci when on release tag
@@ -77,56 +97,31 @@ fi
upload upload
echo "\nAdding packages to $aptly_repository ..." echo "\nAdding packages to $aptly_repository ..."
curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder jsonret=`curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder`
echo
echo "\nUpdating published repo $aptly_published ..." echo "\nUpdating published repo $aptly_published ..."
curl -fsS -X PUT -H 'Content-Type: application/json' --data \ update_publish $aptly_published $dist
'{"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
if [ $dist = "focal" ]; then # if [ "$action" = "OBSOLETErelease" ]; then
echo "\nUpdating legacy nightly repo..." # aptly_repository=aptly-release
# aptly_snapshot=aptly-$version
aptly_repository=aptly-nightly # aptly_published=s3:repo.aptly.info:./squeeze
aptly_published=s3:repo.aptly.info:./nightly #
# echo "\nAdding packages to $aptly_repository..."
upload # curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder
# echo
echo "\nAdding packages to $aptly_repository ..." #
curl -fsS -X POST -u $aptly_user:$aptly_password ${aptly_api}/api/repos/$aptly_repository/file/$folder # echo "\nCreating snapshot $aptly_snapshot from repo $aptly_repository..."
echo # 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 "\nUpdating published repo $aptly_published ..." # echo
curl -fsS -X PUT -H 'Content-Type: application/json' --data \ #
'{"AcquireByHash": true, "Signing": {"Batch": true, "Keyring": "aptly.repo/aptly.pub", # echo "\nSwitching published repo $aptly_published to use snapshot $aptly_snapshot..."
"secretKeyring": "aptly.repo/aptly.sec", "PassphraseFile": "aptly.repo/passphrase"}}' \ # curl -fsS -X PUT -H 'Content-Type: application/json' --data \
-u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published # "{\"AcquireByHash\": true, \"Snapshots\": [{\"Component\": \"main\", \"Name\": \"$aptly_snapshot\"}],
echo # \"Signing\": {\"Batch\": true, \"Keyring\": \"aptly.repo/aptly.pub\",
fi # \"secretKeyring\": \"aptly.repo/aptly.sec\", \"PassphraseFile\": \"aptly.repo/passphrase\"}}" \
# -u $aptly_user:$aptly_password ${aptly_api}/api/publish/$aptly_published
if [ "$action" = "OBSOLETErelease" ]; then # echo
aptly_repository=aptly-release # fi
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