PX4-Autopilot/.github/workflows/build_docker.yml
2022-02-02 21:49:40 -08:00

121 lines
2.9 KiB
YAML

# build docker images on:
# * every pull request
# * push to master
# * stable release published
# * tag name is:
# - commit sha if pull request
# - 'latest' if push to master
# - release name if release
# pushes to registry if:
# * is not a pull request
# * is master branch
# * is the result of release
# builds all nuttx targets and deploys metadata
name: Build docker
on:
release:
types: [released]
push:
branches:
- 'main'
pull_request:
env:
TAG_NAME: |
${{
github.event_name == 'pull_request' && github.sha ||
(
github.event_name == 'push' && 'latest' ||
github.event.release.name
)
}}
jobs:
build_docker:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to Github Registry
uses: docker/login-action@v1
if: github.event_name == 'push'
with:
registry: ghrc.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v2
id: docker_build
with:
file: Tools/setup/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: "px4io/px4-dev:${{ env.TAG_NAME }}"
outputs: type=tar,dest=/tmp/px4image.tar
- name: Save container to artifacts
uses: actions/upload-artifact@v2
with:
name: px4image
path: /tmp/px4image.tar
- name: Push to Github Registry
uses: docker/build-push-action@v2
if: github.event_name == 'push'
- name: Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}
enumerate_targets:
name: Generate target list
runs-on: ubuntu-latest
needs: build_docker
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install Python packages
run: pip install kconfiglib
- id: set-matrix
name: Get all nuttx targets
run: echo "::set-output name=matrix::$(./Tools/generate_board_targets_json.py -a)"
build_px4:
name: Build targets with Docker
runs-on: ubuntu-latest
needs: enumerate_targets
strategy:
matrix: ${{ fromJson(needs.enumerate_targets.outputs.matrix) }}
steps:
- name: Get container from artifacts
uses: actions/download-artifact@v2
with:
name: px4image
path: /tmp
- name: Load Docker image
run: |
docker import /tmp/px4image.tar
docker image ls -a
- name: Build the world
run: |
DOCKER_TAG="${{ env.TAG_NAME }}" ./Tools/docker.run.sh make ${{ matrix.target }}