-
Notifications
You must be signed in to change notification settings - Fork 14
108 lines (106 loc) · 3.51 KB
/
ci.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
name: CI
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:
jobs:
configure:
name: Configure
runs-on: ubuntu-20.04
outputs:
base_image: ${{ steps.compute-base-image.outputs.base_image }}
build_base_image: ${{ steps.should-build-base-image.outputs.answer }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
if: github.event_name != 'workflow_dispatch'
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- name: Compute last successfully built commit
uses: nrwl/last-successful-commit-action@v1
id: last-commit
with:
branch: ${{ steps.branch-name.outputs.current_branch }}
workflow_id: 'ci.yaml'
github_token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name != 'workflow_dispatch'
- name: Check base image files for changes since last commit
id: base-image-files-in-last-commit
uses: tj-actions/[email protected]
with:
files: tools/setup/*
base_sha: ${{ steps.last-commit.outputs.commit_hash }}
sha: ${{ github.event.pull_request.head.sha || github.sha }}
if: github.event_name != 'workflow_dispatch'
- name: Check if base image needs to be (re)built
id: should-build-base-image
run: |
echo '::set-output name=answer::true'
if: |
(github.event_name == 'workflow_dispatch') ||
(steps.base-image-files-in-last-commit.outputs.any_changed == 'true')
- name: Check base image files for changes since branching
id: base-image-files-full-diff
uses: tj-actions/[email protected]
with:
files: tools/setup/*
use_fork_point: true
if: github.event_name != 'workflow_dispatch'
- name: Compute base image name
id: compute-base-image
run: |
suffix="latest"
if ! ${{ steps.branch-name.outputs.is_default }}; then
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
suffix="$GITHUB_REF_SLUG"
fi
if [[ "${{ steps.base-image-files-full-diff.outputs.any_changed }}" == "true" ]]; then
suffix="$GITHUB_REF_SLUG"
fi
fi
echo "::set-output name=base_image::osrf/lrauv:gz-garden-${suffix}"
build-base-image:
name: Build Gazebo Garden image
runs-on: ubuntu-20.04
needs: configure
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_READ_WRITE }}
- name: Build and push Gazebo Garden image
uses: docker/build-push-action@v3
with:
file: tools/setup/Dockerfile
target: garden
tags: ${{ needs.configure.outputs.base_image }}
push: true
if: ${{ needs.configure.outputs.build_base_image }}
build-and-test:
name: Build and test lrauv code
needs: [configure, build-base-image]
runs-on: ubuntu-20.04
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Build LRAUV image
uses: docker/build-push-action@v3
with:
build-args: BASE_IMAGE=${{ needs.configure.outputs.base_image }}
file: tools/setup/Dockerfile
target: lrauv-base
tags: lrauv-base
push: false
- name: Build and run tests
run: docker run --rm -t lrauv-base
if: always()