-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (78 loc) · 4.85 KB
/
publish-aptly-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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