Skip to content

Commit

Permalink
Reusable build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Aug 29, 2023
1 parent c79d083 commit be66679
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 27 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
name: CI

on:
workflow_dispatch:
inputs:
DEB_DISTRO:
type: string
required: false
description: 'Ubuntu/Debian distro:'
default: jammy
ROS_DISTRO:
type: string
required: false
description: 'ROS distribution codename:'
default: one
push:
branches: [ main ]
paths-ignore: [ '.github/**' ]

env:
DEBS_PATH: ${{ vars.DEBS_PATH || '~/debs' }}
REPO_PATH: ${{ vars.REPO_PATH || '~/repo' }}
DEBS_PATH: ${{ inputs.DEBS_PATH || vars.DEBS_PATH || '~/debs' }}
REPO_PATH: ${{ inputs.REPO_PATH || vars.REPO_PATH || '~/repo' }}
TERM: xterm # needed for colored output of unittests

concurrency:
Expand Down Expand Up @@ -70,7 +83,7 @@ jobs:

- name: Run main action
uses: ./
with:
env:
DEB_DISTRO: ${{ matrix.DEB_DISTRO }}
ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
ROS_SOURCES: .github/workflows/minimal.repos
Expand Down
181 changes: 181 additions & 0 deletions .github/workflows/generic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: reusable workflow

on:
# make this workflow reusable (and only so)
workflow_call:
inputs:
# target names
ROS_DISTRO:
type: string
description: ROS distribution codename to compile for
required: false # defaults to 'one'
DEB_DISTRO:
type: string
description: The Debian/Ubuntu distribution codename to compile for.
required: false # defaults to 'lsb_release -cs'
ROS_SOURCES:
type: string
description: ROS sources to compile. See README.md for details.
required: false

# workflow control
CONTINUE_PREVIOUS_RUN:
type: boolean
description: Continue previous workflow run, skipping existing packages
required: false
default: false
BUILD_TIMEOUT:
type: number
description: Cancel build after this time, before github will do (minutes)
required: false
default: 340

# debian package repository options
EXTRA_DEB_SOURCES:
type: string
description: extra debian sources to add to sources.list
required: false
INSTALL_GPG_KEYS:
type: string
description: code to run for installing GPG keys (for use with EXTRA_DEB_SOURCES)
required: false
EXTRA_ROSDEP_SOURCES:
type: string
description: path to a rosdep-compatible yaml file specifying custom dependency mappings
required: false

# build options
EXTRA_SBUILD_CONFIG:
type: string
description: lines to add to ~/.sbuildrc
required: false
EXTRA_SBUILD_OPTS:
type: string
description: options to pass to sbuild on commandline
required: false
DEB_BUILD_OPTIONS:
type: string
description: options used debian/rules
required: false
default: nocheck
CONTINUE_ON_ERROR:
type: boolean
description: Continue building even if some packages already failed
required: false
default: false

# deploy options
DEBS_PATH:
type: string
description: path to store generated .debs in
required: false
default: ~/debs

REPO_PATH:
type: string
description: path to generate package repository in
required: false
default: ~/repo

# Define environment variables from input, from configuration variables, or defaults - in this order!
# https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows
env:
ROS_DISTRO: ${{ inputs.ROS_DISTRO || vars.ROS_DISTRO }}
DEB_DISTRO: ${{ inputs.DEB_DISTRO || vars.DEB_DISTRO }}
ROS_SOURCES: ${{ inputs.ROS_SOURCES || vars.ROS_SOURCES }}
EXTRA_DEB_SOURCES: ${{ inputs.EXTRA_DEB_SOURCES || vars.EXTRA_DEB_SOURCES }}
INSTALL_GPG_KEYS: ${{ inputs.INSTALL_GPG_KEYS || vars.INSTALL_GPG_KEYS }}
EXTRA_ROSDEP_SOURCES: ${{ inputs.EXTRA_ROSDEP_SOURCES || vars.EXTRA_ROSDEP_SOURCES }}
EXTRA_SBUILD_CONFIG: ${{ inputs.EXTRA_SBUILD_CONFIG || vars.EXTRA_SBUILD_CONFIG }}
EXTRA_SBUILD_OPTS: ${{ inputs.EXTRA_SBUILD_OPTS || vars.EXTRA_SBUILD_OPTS }}
DEBS_PATH: ${{ inputs.DEBS_PATH || vars.DEBS_PATH }}
REPO_PATH: ${{ inputs.REPO_PATH || vars.REPO_PATH }}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
debs:
runs-on: ubuntu-latest
name: build debs

env: # define common environment variables (cannot be passed from calling workflow)
CCACHE_PATH: ~/.cache/ccache
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 10
DEBUG_BASH: ${{ secrets.ACTIONS_STEP_DEBUG && 'true' || 'false' }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download debs from previous run
uses: actions/download-artifact@v3
if: ${{ inputs.CONTINUE_PREVIOUS_RUN }}
with:
name: debs
path: ${{ env.DEBS_PATH }}

- name: Restore ccache
id: restore-ccache
uses: actions/cache/restore@v3
env:
CACHE_ID: "ccache-${{ inputs.DEB_DISTRO || vars.DEB_DISTRO }}\
-${{ inputs.ROS_DISTRO || vars.ROS_DISTRO }}\
-${{ hashFiles(inputs.ROS_SOURCES || vars.ROS_SOURCES) || inputs.ROS_SOURCES || vars.ROS_SOURCES }}"
with:
path: ${{ env.CCACHE_PATH }}
key: ${{ env.CACHE_ID }}-${{ github.run_id }}
restore-keys: |
${{ env.CACHE_ID }}
- name: Build .deb packages
uses: ubi-agni/ros-builder-action@main
timeout-minutes: ${{ inputs.BUILD_TIMEOUT || vars.BUILD_TIMEOUT }}
env:
CONTINUE_PREVIOUS_RUN: ${{ inputs.CONTINUE_PREVIOUS_RUN }}
CONTINUE_ON_ERROR: ${{ inputs.CONTINUE_ON_ERROR || vars.CONTINUE_ON_ERROR }}
DEB_BUILD_OPTIONS: ${{ inputs.DEB_BUILD_OPTIONS || vars.DEB_BUILD_OPTIONS }}

- name: Store ccache
uses: actions/cache/save@v3
if: always() # save cache on timeout or cancel too
with:
path: ${{ env.CCACHE_PATH }}
key: ${{ steps.restore-ccache.outputs.cache-primary-key }}

- name: Upload debs
uses: actions/upload-artifact@v3
if: always() # upload on timeout or cancel too
with:
name: debs
path: ${{ env.DEBS_PATH }}
if-no-files-found: error

repo:
needs: debs
runs-on: ubuntu-latest
name: create repo

env: # define common environment variables (cannot be passed from calling workflow)
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 10
DEBUG_BASH: ${{ secrets.ACTIONS_STEP_DEBUG && 'true' || 'false' }}

steps:
- name: Download debs from build
uses: actions/download-artifact@v3
with:
name: debs
path: ${{ env.DEBS_PATH }}

- name: Run flat-repo action
uses: ubi-agni/ros-builder-action/flat-repo@main

- name: Upload repo
uses: actions/upload-artifact@v3
if: always() # upload on timeout or cancel too
with:
name: repo
path: ${{ env.REPO_PATH }}
if-no-files-found: error
83 changes: 83 additions & 0 deletions .github/workflows/interactive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: interactive

on:
workflow_dispatch:
# The inputs should not define a default value.
# If they do, this value would be passed even if nothing is actually entered in the dialog,
# thus overriding any configuration variables set, which should be considered in this case.
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs
inputs:
DEB_DISTRO:
type: string
required: true
description: 'Ubuntu/Debian distro:'
default: jammy
ROS_DISTRO:
type: string
required: true
description: 'ROS distribution codename:'
default: one
ROS_SOURCES:
type: string
description: ROS sources to compile. See README.md for details.
required: true
default: '*.repos'
PROCEED_FROM:
type: choice
description: Where to start building?
required: true
default: from scratch
options:
- from scratch
- from previous run
# - from deployment repo
DEPLOY_MODE:
type: choice
description: |
How to deploy?
Uses vars.DEPLOY_URL and secrets.DEPLOY_PRIVATE_KEY
required: true
default: skip
options:
- skip
- squash
- append
BRANCH:
type: string
description: 'Branch to use (<deb distro>-<ros distro>):'
required: false

jobs:
build:
name: ${{ inputs.DEB_DISTRO || vars.DEB_DISTRO || 'latest' }}-${{ inputs.ROS_DISTRO || vars.ROS_DISTRO || 'one'}}
uses: ubi-agni/ros-builder-action/.github/workflows/generic.yaml@main
with:
DEB_DISTRO: ${{ inputs.DEB_DISTRO || vars.DEB_DISTRO }}
ROS_DISTRO: ${{ inputs.ROS_DISTRO || vars.ROS_DISTRO || 'one' }}
ROS_SOURCES: ${{ inputs.ROS_SOURCES || vars.ROS_SOURCES }}
PROCEED_FROM: ${{ inputs.PROCEED_FROM || 'from scratch' }}

deploy:
needs: build
runs-on: ubuntu-latest
if: ( inputs.DEPLOY_MODE != 'skip' ) && vars.DEPLOY_URL

env: # define common environment variables (cannot be passed from calling workflow)
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 10
FOLDER: ${{ vars.REPO_PATH || '~/repo' }}
REPO: ${{ vars.DEPLOY_URL }}
BRANCH: ${{ inputs.BRANCH || format('{0}-{1}', inputs.DEB_DISTRO, inputs.ROS_DISTRO) }}

steps:
- name: Download repo from build
uses: actions/download-artifact@v3
with:
name: repo
path: ${{ env.FOLDER }}

- name: Deploy
uses: s0/git-publish-subdir-action@v2.6.0
env:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}
MESSAGE: "${{ inputs.DEB_DISTRO }}-${{ inputs.ROS_DISTRO }} build"
SQUASH_HISTORY: ${{ inputs.DEPLOY_MODE == 'squash' }}
2 changes: 0 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ inputs:
ROS_SOURCES:
description: Repos file with list of repositories to package
required: false
default: '*.repos'

# packages sources
EXTRA_DEB_SOURCES:
Expand All @@ -35,7 +34,6 @@ inputs:
CONTINUE_ON_ERROR:
description: continue building packages once a package failed
required: false
default: false

runs:
# We need to go through JS to allow folding output generated from the shell script
Expand Down
26 changes: 13 additions & 13 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
set -euo pipefail # exit script on errors

## target names
export ROS_DISTRO=${INPUT_ROS_DISTRO:-one}
export DEB_DISTRO=${INPUT_DEB_DISTRO:-$(lsb_release -cs)}
export ROS_DISTRO=${ROS_DISTRO:-one}
export DEB_DISTRO=${DEB_DISTRO:-$(lsb_release -cs)}

## package repository options
export INSTALL_GPG_KEYS=${INSTALL_GPG_KEYS:-} # hook to install GPG keys
export EXTRA_DEB_SOURCES=${INPUT_EXTRA_DEB_SOURCES:-${EXTRA_DEB_SOURCES:-}}
export EXTRA_ROSDEP_SOURCES=${INPUT_EXTRA_ROSDEP_SOURCES:-${EXTRA_ROSDEP_SOURCES:-}}
export EXTRA_DEB_SOURCES=${EXTRA_DEB_SOURCES:-}
export EXTRA_ROSDEP_SOURCES=${EXTRA_ROSDEP_SOURCES:-}

## build options
export ROS_SOURCES=${INPUT_ROS_SOURCES:-${ROS_SOURCES:-*.repos}}
export EXTRA_SBUILD_CONFIG=${INPUT_EXTRA_SBUILD_CONFIG:-${EXTRA_SBUILD_CONFIG:-}}
export CONTINUE_ON_ERROR=${INPUT_CONTINUE_ON_ERROR:-false}
EXTRA_SBUILD_OPTS="${EXTRA_SBUILD_OPTS:-} $(echo "$EXTRA_DEB_SOURCES" | sed -n '/^ *$/ T; s/.*/--extra-repository="\0"/; p' | tr '\n' ' ')"
export DEB_BUILD_OPTIONS=nocheck # don't build/run tests
export ROS_SOURCES=${ROS_SOURCES:-*.repos}
export EXTRA_SBUILD_CONFIG=${EXTRA_SBUILD_CONFIG:-}
export CONTINUE_ON_ERROR=${CONTINUE_ON_ERROR:-false}
export EXTRA_SBUILD_OPTS=${EXTRA_SBUILD_OPTS:-}
export DEB_BUILD_OPTIONS=${DEB_BUILD_OPTIONS:-nocheck} # don't build/run tests

## deploy options
## deploy paths: 'eval echo ...' expands environment variables
export DEBS_PATH
DEBS_PATH=$(eval echo "${DEBS_PATH:-$HOME/debs}")
DEBS_PATH=$(eval echo "${DEBS_PATH}")
export REPO_PATH
REPO_PATH=$(eval echo "${REPO_PATH:-$HOME/repo}")
REPO_PATH=$(eval echo "${REPO_PATH}")

export GITHUB_TOKEN=${INPUT_GITHUB_TOKEN:-${GITHUB_TOKEN:-}}
export GITHUB_TOKEN=${GITHUB_TOKEN:-}

# configure shell debugging
export DEBUG_BASH=${DEBUG_BASH:-false}
Expand Down
24 changes: 15 additions & 9 deletions src/scripts/generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ SRC_PATH="$(realpath "$DIR_THIS/..")"
source "$SRC_PATH/env.sh"

ici_start_fold "Variables"
echo "ROS_DISTRO=$ROS_DISTRO"
echo "DEB_DISTRO=$DEB_DISTRO"
echo "EXTRA_DEB_SOURCES=$EXTRA_DEB_SOURCES"
echo "EXTRA_ROSDEP_SOURCES=$EXTRA_ROSDEP_SOURCES"
echo "ROS_SOURCES=$ROS_SOURCES"
echo "EXTRA_SBUILD_CONFIG=$EXTRA_SBUILD_CONFIG"
echo "CONTINUE_ON_ERROR=$CONTINUE_ON_ERROR"
echo "DEBS_PATH=$DEBS_PATH"
echo "DEBUG_BASH=$DEBUG_BASH"
cat <<EOF
ROS_DISTRO=$ROS_DISTRO
DEB_DISTRO=$DEB_DISTRO
ROS_SOURCES=$ROS_SOURCES
EXTRA_DEB_SOURCES=$EXTRA_DEB_SOURCES
EXTRA_ROSDEP_SOURCES=$EXTRA_ROSDEP_SOURCES
EXTRA_SBUILD_CONFIG=$EXTRA_SBUILD_CONFIG
CONTINUE_ON_ERROR=$CONTINUE_ON_ERROR
DEBS_PATH=$DEBS_PATH
REPO_PATH=$REPO_PATH
DEBUG_BASH=$DEBUG_BASH
EOF
ici_end_fold

# shellcheck source=main.sh
Expand Down

0 comments on commit be66679

Please sign in to comment.