-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (133 loc) · 5.07 KB
/
test.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
name: Test
on: [ push ]
jobs:
# This job builds the Docker image that will be used in the following test job.
# It also publishes the image to the GitHub Container Registry, so every PR can
# have an up-to-date image by the name of ghcr.io/GITHUB_USERNAME/PROJECT_NAME:BRANCH_NAME
build-image:
runs-on: ubuntu-24.04
env:
BUILT_IMAGE_NAME: ghcr.io/urbanmachine/node_helpers
PROJECT_NAME: node_helpers
defaults:
run:
shell: bash
steps:
- name: Create A Unique Tag For This Image Based On Branch Name
id: prep
run: |
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]
then
# This is a build on a branch
TAG=${GITHUB_REF#refs/heads/}
elif [[ "${GITHUB_REF}" == "refs/pull/"* ]]
then
# This is a PR build
TAG=${GITHUB_REF#refs/pull/}
elif [[ "${GITHUB_REF}" == "refs/tags/"* ]]
then
# This is a tagged build
TAG=${GITHUB_REF#refs/tags/}
else
echo "Unexpected reference format ${GITHUB_REF}"
exit 1
fi
# Remove slashes, since they're not allowed in Docker tags
TAG=$(echo "${TAG}" | sed 's#/#-#g')
echo "tagged_image=${BUILT_IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Load Previous Docker Layers Cache
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
# Key is named differently to avoid collision
key: v1-${{ env.PROJECT_NAME }}-${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: v1-${{ env.PROJECT_NAME }}-${{ runner.os }}-multi-buildx
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Get Base Image Name
id: get_base_image
run: |
source .env
echo "base_image=${BASE_IMAGE}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.prep.outputs.tagged_image }}
build-args: |
BASE_IMAGE=${{ steps.get_base_image.outputs.base_image }}
cache-from: type=local,src=/tmp/.buildx-cache
# Note the mode=max here
# More: https://github.com/moby/buildkit#--export-cache-options
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# This is done to avoid storing outdated build steps in the cache, since
# BuildKit never clears stuff out of the cache itself
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
outputs:
tagged_image: ${{ steps.prep.outputs.tagged_image }}
# This job runs the colcon tests for the project
ros-tests:
needs: build-image
runs-on: ubuntu-24.04
defaults:
run:
shell: bash
timeout-minutes: 15
container:
image: ${{needs.build-image.outputs.tagged_image}}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_WORKSPACE: /repo/
steps:
- name: Install Git LFS
run: sudo apt-get update && sudo apt-get install git-lfs
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Fix git error in the following line
# Caused by an update to git that dislikes when users of different ID's touch
# the same git directory, which happens when using a docker runner in CI
# This fixes test reporting in the `Generate Test Report` section
# https://github.blog/2022-04-12-git-security-vulnerability-announced/
# https://github.com/actions/checkout/issues/760
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Copy Python dependencies to github workspace
run: cp -r /robot/install install
- name: Copy Build output to github workspace
run: cp -r /robot/install build
- name: Move launch-profile files to /robot/launch-profiles so hardcoded paths work
run: cp -r ${GITHUB_WORKSPACE}/launch-profiles /robot/
- name: Run tests
run: |
enter-workspaces colcon test \
--base-paths pkgs \
--pytest-with-coverage \
--test-result-base test-results \
--pytest-args \
--durations=50
- name: Generate Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: "Test report"
path: test-results/**/*.xml
reporter: java-junit
- name: Report Codecov Coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}