Repository navigation
152 lines (130 loc) · 4.94 KB
/
Copy pathros2_build_test.yml
File metadata and controls
152 lines (130 loc) · 4.94 KB
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
name: ROS 2 Jazzy Docker Compose Build and Test
on:
push:
branches: [ "main" ]
# Every pull request, including ones stacked on another pull request's branch.
pull_request:
permissions:
contents: read
env:
IMAGE: ghcr.io/waybionic/waybionic_ground_station
jobs:
# Pull requests build and test with a read-only token. Keep these check names
# stable for review.
build-and-test:
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v7
- name: Build and Test with Docker Compose
run: docker compose --progress plain build test
build-and-test-arm64:
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout Repository
uses: actions/checkout@v7
- name: Build and Test with Docker Compose
run: docker compose --progress plain build test
# Pushes to main build and test the same way, then push the tested image under this commit.
publish-amd64:
if: github.event_name == 'push'
runs-on: ubuntu-24.04
outputs:
digest: ${{ steps.push.outputs.digest }}
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v7
# No registry cache: a published layer must come from this build, not from :jazzy.
- name: Build and Test with Docker Compose
run: docker compose --progress plain build --no-cache test
- name: Log in to the GitHub Container Registry
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: printf '%s' "$GHCR_TOKEN" | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
- name: Push the tested x86-64 image
id: push
shell: bash
run: |
docker tag "$IMAGE:jazzy" "$IMAGE:$GITHUB_SHA-amd64"
push_log=$(docker push "$IMAGE:$GITHUB_SHA-amd64")
printf '%s\n' "$push_log"
if [[ "$push_log" =~ digest:\ (sha256:[0-9a-f]{64}) ]]; then
echo "digest=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
else
echo "::error::docker push did not report the tested image digest"
exit 1
fi
publish-arm64:
if: github.event_name == 'push'
runs-on: ubuntu-24.04-arm
outputs:
digest: ${{ steps.push.outputs.digest }}
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v7
- name: Build and Test with Docker Compose
run: docker compose --progress plain build --no-cache test
- name: Log in to the GitHub Container Registry
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: printf '%s' "$GHCR_TOKEN" | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
- name: Push the tested ARM64 image
id: push
shell: bash
run: |
docker tag "$IMAGE:jazzy" "$IMAGE:$GITHUB_SHA-arm64"
push_log=$(docker push "$IMAGE:$GITHUB_SHA-arm64")
printf '%s\n' "$push_log"
if [[ "$push_log" =~ digest:\ (sha256:[0-9a-f]{64}) ]]; then
echo "digest=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
else
echo "::error::docker push did not report the tested image digest"
exit 1
fi
publish-image:
if: github.event_name == 'push'
needs: [publish-amd64, publish-arm64]
runs-on: ubuntu-24.04
# One run at a time moves the shared tag, after checking that its commit is still newest.
concurrency:
group: publish-image
cancel-in-progress: false
permissions:
contents: read
packages: write
steps:
- name: Log in to the GitHub Container Registry
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: printf '%s' "$GHCR_TOKEN" | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
- name: Publish one image for both architectures
shell: bash
run: |
amd64="${{ needs.publish-amd64.outputs.digest }}"
arm64="${{ needs.publish-arm64.outputs.digest }}"
if [[ ! "$amd64" =~ ^sha256:[0-9a-f]{64}$ || ! "$arm64" =~ ^sha256:[0-9a-f]{64}$ ]]; then
echo "::error::Missing tested image digest"
exit 1
fi
tags=(--tag "$IMAGE:${GITHUB_SHA::7}")
# Runs can finish out of order: only the newest commit on main moves :jazzy.
head=$(git ls-remote "https://github.com/$GITHUB_REPOSITORY" refs/heads/main | cut -f1)
if [ -z "$head" ]; then
echo "::error::Could not resolve main before moving :jazzy"
exit 1
fi
if [ "$head" = "$GITHUB_SHA" ]; then
tags+=(--tag "$IMAGE:jazzy")
else
echo "main has moved on to $head, so :jazzy stays where it is"
fi
docker buildx imagetools create "${tags[@]}" \
"$IMAGE@$amd64" "$IMAGE@$arm64"