Update CI Image #279
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Update CI Image | |
on: | |
schedule: | |
# 7am UTC, 12am PDT | |
- cron: '0 7 * * *' | |
push: | |
branches: | |
- main | |
paths: | |
- '**/package.xml' | |
- '**/*.repos' | |
- 'Dockerfile' | |
jobs: | |
check_ci_files: | |
name: Check CI Files | |
runs-on: ubuntu-latest | |
outputs: | |
trigger: ${{ steps.check.outputs.trigger }} | |
no_cache: ${{ steps.check.outputs.no_cache }} | |
steps: | |
- name: "Check package updates" | |
id: check | |
if: github.event_name == 'push' | |
run: | | |
echo "::set-output name=trigger::true" | |
echo "::set-output name=no_cache::false" | |
check_ci_image: | |
name: Check CI Image | |
if: github.event_name == 'schedule' | |
needs: check_ci_files | |
runs-on: ubuntu-latest | |
outputs: | |
trigger: ${{ steps.check.outputs.trigger }} | |
no_cache: ${{ steps.check.outputs.no_cache }} | |
container: | |
image: ghcr.io/ros-planning/navigation2:main | |
steps: | |
- name: "Check apt updates" | |
id: check | |
env: | |
SOURCELIST: sources.list.d/ros2.list | |
run: | | |
apt-get update \ | |
-o Dir::Etc::sourcelist="${SOURCELIST}" | |
apt-get --simulate upgrade \ | |
-o Dir::Etc::sourcelist="${SOURCELIST}" \ | |
> upgrade.log | |
cat upgrade.log | |
cat upgrade.log \ | |
| grep "^0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.$" \ | |
&& echo "::set-output name=trigger::false" \ | |
|| echo "::set-output name=trigger::true" | |
echo "::set-output name=no_cache::true" | |
rebuild_ci_image: | |
name: Rebuild CI Image | |
if: always() | |
needs: | |
- check_ci_files | |
- check_ci_image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set build config | |
id: config | |
run: | | |
timestamp=$(date --utc +%Y%m%d%H%M%S) | |
echo "::set-output name=timestamp::${timestamp}" | |
no_cache=false | |
if [ "${{needs.check_ci_files.outputs.no_cache}}" == 'true' ] || \ | |
[ "${{needs.check_ci_image.outputs.no_cache}}" == 'true' ] | |
then | |
no_cache=true | |
fi | |
echo "::set-output name=no_cache::${no_cache}" | |
trigger=false | |
if [ "${{needs.check_ci_files.outputs.trigger}}" == 'true' ] || \ | |
[ "${{needs.check_ci_image.outputs.trigger}}" == 'true' ] | |
then | |
trigger=true | |
fi | |
echo "::set-output name=trigger::${trigger}" | |
- name: Build and push | |
if: steps.config.outputs.trigger == 'true' | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
pull: true | |
push: true | |
no-cache: ${{ steps.config.outputs.no_cache }} | |
cache-from: type=registry,ref=ghcr.io/ros-planning/navigation2:main | |
cache-to: type=inline | |
target: builder | |
tags: | | |
ghcr.io/ros-planning/navigation2:main | |
ghcr.io/ros-planning/navigation2:main-${{ steps.config.outputs.timestamp }} | |
- name: Image digest | |
if: steps.config.outputs.trigger == 'true' | |
run: echo ${{ steps.docker_build.outputs.digest }} |