make a new release on aptly (stage->release) #177
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "make a new release on aptly (stage->release)" | |
on: | |
#schedule: | |
# run this every Monday morning at 4 am | |
# - cron: "0 4 * * 1" | |
workflow_dispatch: | |
inputs: | |
repo: | |
description: "The name of the repo to update" | |
required: true | |
default: "lcas_ros" | |
distro: | |
description: "The name of the distro to update" | |
required: true | |
default: "jammy" | |
prefix: | |
description: "The prefix to use for the published snapshots" | |
required: true | |
default: "lcas" | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Setup jq' | |
uses: dcarbone/install-jq-action@v2 | |
- name: "Create Snapshots and release them" | |
run: | | |
echo ::group::Setup | |
set -e -x | |
APTLY_API="https://lcas.lincoln.ac.uk/apt/api" | |
REPO=${{ github.event.inputs.repo }} | |
DISTRO=${{ github.event.inputs.distro }} | |
PUBLISH_PREFIX=${{ github.event.inputs.prefix }} | |
TIMESTAMP=`date +%Y%m%d%H%M` | |
REPO_SNAPSHOT="${REPO}_${TIMESTAMP}" | |
DATA="{\"Name\": \"${REPO_SNAPSHOT}\"}" | |
echo ::endgroup:: | |
echo "::group::Create snapshot ${REPO_SNAPSHOT} from ${REPO}" | |
# create snapshot | |
curl -f -X POST -H 'Content-Type: application/json' --data "${DATA}" -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/repos/${REPO}/snapshots | |
echo ::endgroup:: | |
echo "::group::Get last mirror snapshot and merge it with the new repo snapshot" | |
# get mirror snapshots | |
LAST_MIRRORS_SNAPSHOT=`curl -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep '^mirrors_' | sort | tail -n1` | |
# create release snapshot merging the last mirror snapshot and the new repo snapshot | |
RELEASE_SNAPSHOT="release_${TIMESTAMP}" | |
DATA="{\"Destination\": \"${RELEASE_SNAPSHOT}\", \"Sources\": [\"${REPO_SNAPSHOT}\", \"${LAST_MIRRORS_SNAPSHOT}\"]}" | |
curl -f -X POST -H 'Content-Type: application/json' --data "${DATA}" -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/merge | |
echo ::endgroup:: | |
echo "::group::Publish the release snapshot" | |
# publish the release snapshot | |
DATA="{\"Snapshots\": [{\"Component\": \"lcas\", \"Name\": \"${RELEASE_SNAPSHOT}\"}], \"ForceOverwrite\": true}" | |
curl -f -X PUT -H 'Content-Type: application/json' --data "${DATA}" -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/publish/${PUBLISH_PREFIX}/${DISTRO} | |
echo ::endgroup:: | |
echo "::group::Cleanup old snapshots" | |
# cleanup old snapshots | |
RELEASE_SNAPSHOTS=`curl -f -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep '^release_'` | |
for m in $RELEASE_SNAPSHOTS; do | |
curl -f -X DELETE -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/${m} || echo "NOT deleted $m as still needed" | |
done | |
MIRRORS_SNAPSHOTS=`curl -f -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep '^mirrors_'` | |
for m in $MIRRORS_SNAPSHOTS; do | |
curl -f -X DELETE -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/${m} || echo "NOT deleted $m as still needed" | |
done | |
REPO_SNAPSHOTS=`curl -f -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep "^${REPO}_"` | |
for m in $REPO_SNAPSHOTS; do | |
curl -f -X DELETE -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/${m} || echo "NOT deleted $m as still needed" | |
done | |
OSRF_SNAPSHOTS=`curl -f -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep '^osrf_'` | |
for m in $OSRF_SNAPSHOTS; do | |
curl -f -X DELETE -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/${m} || echo "NOT deleted $m as still needed" | |
done | |
NVIDIA_SNAPSHOTS=`curl -f -s -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots | jq -r '.[].Name'| grep '^nvidia_'` | |
for m in $NVIDIA_SNAPSHOTS; do | |
curl -f -X DELETE -u lcas:${{ secrets.APTLY_TOKEN }} ${APTLY_API}/snapshots/${m} || echo "NOT deleted $m as still needed" | |
done | |
echo ::endgroup:: | |
echo "Published snapshot ${RELEASE_SNAPSHOT} on ${PUBLISH_PREFIX}/${DISTRO}" >> $GITHUB_STEP_SUMMARY |