-
Notifications
You must be signed in to change notification settings - Fork 4
162 lines (138 loc) · 5.58 KB
/
build_images.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
name: Build and Release Docker Image
on:
schedule:
# 7am UTC, 12am PST
- cron: '0 7 * * *'
push:
# For developer updates to trigger
branches:
- main
jobs:
nightly_docker:
name: Build and Release Nightly Docker Images From Current Source
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ros_distro: [humble, jazzy, rolling]
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
pull: true
tags: ghcr.io/${{ github.repository }}:${{ matrix.ros_distro }}-nightly
platforms: linux/amd64,linux/arm64
build-args: |
ROS_DISTRO=${{ matrix.ros_distro }}
BUILD=true
release_docker:
name: Build and Release Current Nav2 Relased Version of Docker Images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version:
- { ros_distro: 'humble', main_version: '1', distro_version: '1' }
- { ros_distro: 'iron', main_version: '1', distro_version: '2' }
- { ros_distro: 'jazzy', main_version: '1', distro_version: '3' }
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Latest Tag to Build
id: get_tag
run: |
# Fetch tags from the repository
tags=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/ros-navigation/navigation2/tags | \
jq -r '.[].name')
# Get the filtered set from the release
filtered_tags=$(echo "$tags" | grep '^${{ matrix.version.main_version }}\.${{ matrix.version.distro_version }}\.[0-9]*$')
# Find the highest tag
highest_tag=$(echo "$filtered_tags" | sort -V | tail -n 1)
# Output the highest tag
echo "Highest tag: $highest_tag"
echo "highest_tag=$highest_tag" >> $GITHUB_OUTPUT
- name: Get Latest Package Version Already Built
id: latest_released_package
run: |
page=1
per_page=100
all_tags=""
while true; do
echo "Fetching page $page"
response=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/orgs/ros-navigation/packages/container/nav2_docker/versions?per_page=$per_page&page=$page")
# echo "Response from API (Page $page):"
# echo "$response"
# Check if the response is empty
if [ "$(echo "$response" | jq length)" -eq 0 ]; then
echo "No more versions found, stopping pagination."
break
fi
# Extract tags from the response
ros_distro="${{ matrix.version.ros_distro }}"
main_version="${{ matrix.version.main_version }}"
distro_version="${{ matrix.version.distro_version }}"
echo "ROS_DISTRO: $ros_distro"
echo "MAIN_VERSION: $main_version"
echo "DISTRO_VERSION: $distro_version"
extracted_tags=$(echo "$response" | jq -r '.[] | .metadata.container.tags[]')
echo "Extracted tags: $extracted_tags"
matching_tags=$(echo "$extracted_tags" | grep -E "^${ros_distro}-${main_version}\.${distro_version}\." || true)
echo "Matching Tags: $matching_tags"
# Break if the response is empty (no more pages)
# if [ -z "$extracted_tags" ]; then
# echo "No more tags found, breaking loop."
# break
# fi
all_tags="$all_tags"$'\n'"$matching_tags"
echo "All tags found: $all_tags"
page=$((page + 1))
echo "new page: $page"
done
echo "All collected tags:"
echo "$all_tags"
# Sort and find the latest version
latest_version=$(echo "$all_tags" | sort -V | tail -n 1)
# Check if we successfully found the latest version
if [ -z "$latest_version" ]; then
echo "Error: No matching package versions found."
exit 1
fi
echo "Latest version found: $latest_version"
stripped_version=$(echo "$latest_version" | cut -d '-' -f 2-)
echo "Latest version found: $stripped_version"
echo "version=$stripped_version" >> $GITHUB_OUTPUT
- name: Build and Push if New
if: steps.latest_released_package.outputs.version != steps.get_tag.outputs.highest_tag
uses: docker/build-push-action@v6
with:
push: true
pull: true
tags: ghcr.io/${{ github.repository }}:${{ matrix.version.ros_distro }}-${{ steps.get_tag.outputs.highest_tag }}
platforms: linux/amd64,linux/arm64
build-args: |
ROS_DISTRO=${{ matrix.version.ros_distro }}
BUILD=true
VERSION=${{ steps.get_tag.outputs.highest_tag }}