-
Notifications
You must be signed in to change notification settings - Fork 3
180 lines (162 loc) · 6.03 KB
/
main.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
tags:
- v*
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
IMAGE_NAME_BASE: seerep_base
IMAGE_NAME_SERVER: seerep_server
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
create-ids:
runs-on: ubuntu-20.04
outputs:
base_id: ${{ steps.tagsBase.outputs.base_id }}
server_id: ${{ steps.tagsServer.outputs.server_id }}
version: ${{ steps.tagsBase.outputs.version }}
steps:
-
id: tagsBase
name: Generate tags base
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_BASE
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[[ "${{ github.ref }}" != "refs/tags/"* ]] && VERSION=latest
echo "base_id=$IMAGE_ID" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
-
id: tagsServer
name: Generate tags server
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_SERVER
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# save to output
echo "server_id=$IMAGE_ID" >> $GITHUB_OUTPUT
# builds the docker image if the corresponding files changed
build-docker:
needs: create-ids
# run on ubuntu
runs-on: ubuntu-20.04
permissions:
packages: write
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 2
# check if files have changed
- name: Get changed files
id: changed-files-specific-docker-base
uses: tj-actions/changed-files@v42
with:
files: |
docker/base/Dockerfile
docker/base/requirements.dev.txt
docker/base/requirements.docs.txt
-
name: Set up Docker Buildx
if: github.ref_type == 'tag' || steps.changed-files-specific-docker-base.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v3
-
name: Login to Container Registry
if: github.ref_type == 'tag' || steps.changed-files-specific-docker-base.outputs.any_changed == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push base image
if: github.ref_type == 'tag' || steps.changed-files-specific-docker-base.outputs.any_changed == 'true'
uses: docker/build-push-action@v5
with:
file: Dockerfile
context: "{{defaultContext}}:docker/base"
push: ${{ GitHub.event_name != 'pull_request'}}
tags: ${{ needs.create-ids.outputs.base_id }}:${{ needs.create-ids.outputs.version }}
cache-from: type=registry,ref=${{ needs.create-ids.outputs.base_id }}:${{ needs.create-ids.outputs.version }}
cache-to: type=inline
build-code:
needs: [build-docker, create-ids]
runs-on: ubuntu-20.04
container:
image: ${{ needs.create-ids.outputs.base_id }}:${{ needs.create-ids.outputs.version }}
options: --user root
steps:
- uses: actions/checkout@v4
with:
path: src
fetch-depth: 0
- name: Build ROS workspace
run: |
source /opt/ros/noetic/setup.bash
catkin build --workspace $GITHUB_WORKSPACE/
shell: bash
- name: Run pre-commit tests
run: |
source /opt/ros/noetic/setup.bash
source $GITHUB_WORKSPACE/devel/setup.bash
cd $GITHUB_WORKSPACE/src; pre-commit run -a
shell: bash
- name: Build pypi packages
run: |
cd $GITHUB_WORKSPACE/src
python3 -m build --wheel
- name: Publish packages to pypi
if: github.ref_type == 'tag'
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload $GITHUB_WORKSPACE/src/dist/*
build-docker-deployment:
needs: [build-code, create-ids]
# run on ubuntu
runs-on: ubuntu-20.04
permissions:
packages: write
if: ${{ GitHub.event_name != 'pull_request'}}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push server image
uses: docker/build-push-action@v5
with:
file: docker/server/Dockerfile
push: ${{ GitHub.event_name != 'pull_request'}}
tags: ${{ needs.create-ids.outputs.server_id }}:${{ needs.create-ids.outputs.version }}
cache-from: type=registry,ref=${{ needs.create-ids.outputs.server_id }}:${{ needs.create-ids.outputs.version }}
cache-to: type=inline
build-args: |
IMAGEBASE=${{ needs.create-ids.outputs.base_id }}
IMAGEBASETAG=${{ needs.create-ids.outputs.version }}