Skip to content

Commit

Permalink
Reusable workflow deploy.yaml
Browse files Browse the repository at this point in the history
- Replace single DEPLOY_MODE with
  - CONTENT_MODE: replace | add | newer
  - PUSH_MODE: push | amend | squash

- Fix concurrency groups
- Fix CI workflow triggers
  • Loading branch information
rhaschke committed Sep 10, 2023
1 parent ad65a94 commit 20bfc88
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 186 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/generic.yaml → .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: reusable workflow
name: reusable build workflow

on:
# make this workflow reusable (and only so)
Expand Down Expand Up @@ -73,20 +73,16 @@ on:
description: Continue building even if some packages already failed
required: false

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

DEPLOY_URL:
type: string
description: repository URL for deployment
required: false
BRANCH:
type: string
description: branch to use for deployment
required: false
outputs:
LATEST_PACKAGE:
description: Name of the latest package built
value: ${{ jobs.debs.outputs.LATEST_PACKAGE }}


# Define environment variables from input, from configuration variables, or defaults - in this order!
# All inputs (declared above) are deliberately optional and don't provide an explicit default.
Expand All @@ -105,15 +101,17 @@ env:
DEBS_PATH: ${{ inputs.DEBS_PATH || vars.DEBS_PATH || '~/debs' }}

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

jobs:
debs:
runs-on: ubuntu-latest
name: build debs
outputs:
LATEST_PACKAGE: ${{ steps.build.outputs.LATEST_PACKAGE }}

env: # define common environment variables (cannot be passed from calling workflow)
env: # define common environment variables
CCACHE_DIR: /home/runner/ccache
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 10
DEBUG_BASH: ${{ secrets.ACTIONS_STEP_DEBUG && 'true' || 'false' }}
Expand Down Expand Up @@ -143,6 +141,7 @@ jobs:
- name: Build .deb packages
uses: ubi-agni/ros-builder-action@main
id: build
# leave some time for the remaining steps too (github cancels the job after 360 minutes)
timeout-minutes: ${{ inputs.BUILD_TIMEOUT || vars.BUILD_TIMEOUT || 340 }}
env:
Expand Down
37 changes: 17 additions & 20 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,20 @@ 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/**' ]
pull_request:
push:
branches: [ main ]

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

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

jobs:
pre-commit:
sanity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -72,14 +59,14 @@ jobs:
matrix:
DEB_DISTRO: [focal, jammy, bookworm ]
ROS_DISTRO: [one]
include:
- DEB_DISTRO: jammy
UPLOAD_DEBS: true

env:
DEB_DISTRO: ${{ matrix.DEB_DISTRO }}
ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
DEBUG_BASH: ${{ secrets.ACTIONS_STEP_DEBUG && 'true' || 'false' }}
# These two are needed for the flat-repo generation
DEPLOY_URL: ${{ vars.DEPLOY_URL || 'self' }}
BRANCH: ${{ matrix.DEB_DISTRO }}-${{ matrix.ROS_DISTRO }}-CI

name: minimal-${{ matrix.DEB_DISTRO }}-${{ matrix.ROS_DISTRO }}
steps:
Expand All @@ -93,7 +80,17 @@ jobs:
ROS_SOURCES: .github/workflows/minimal.repos

- name: Upload debs
if: matrix.UPLOAD_DEBS
uses: actions/upload-artifact@v3
with:
name: minimal-${{ matrix.DEB_DISTRO }}-${{ matrix.ROS_DISTRO }}
name: debs
path: ${{ env.DEBS_PATH }}

deploy:
needs: ci
uses: ubi-agni/ros-builder-action/.github/workflows/deploy.yaml@main
with:
DEPLOY_URL: self#ci
CONTENT_MODE: replace
PUSH_MODE: squash
MESSAGE: deployment test
92 changes: 92 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: reusable deploy workflow

on:
# make this workflow reusable (and only so)
workflow_call:
inputs:
DEPLOY_URL:
type: string
description: Where to deploy?
required: false

CONTENT_MODE:
type: string
description: |
How to handle existing packages?
- replace
- add (keep existing packages)
- newer (keep existing, but remove older versions)
required: false
PUSH_MODE:
type: string
description: push | amend | squash
required: false

DEBS_PATH:
type: string
description: path to store generated .debs in
required: false

COMMIT_NAME:
type: string
description: user name for commit
required: false
COMMIT_EMAIL:
type: string
description: user email for commit
required: false
MESSAGE:
type: string
description: Commit message
required: false

secrets:
SSH_PRIVATE_KEY:
description: SSH private key to use for deployment
required: false
TOKEN:
description: github token for pushing to own repo
required: false

# Define environment variables from input, from configuration variables, or defaults - in this order!
# All inputs (declared above) are deliberately optional and don't provide an explicit default.
# Thus, if an input is not explicitly provided, we can fall back to the configuration variable here (var.* context).
# This variable context originates from the _calling_ workflow. Finally, a hard-coded default is given.
# https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows
env:
DEBS_PATH: ${{ inputs.DEBS_PATH || vars.DEBS_PATH || '~/debs' }}

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

jobs:
deploy:
runs-on: ubuntu-latest
if: inputs.DEPLOY_URL || vars.DEPLOY_URL
env:
DEBUG_BASH: ${{ secrets.ACTIONS_STEP_DEBUG && 'true' || 'false' }}

steps:
- uses: actions/checkout@v3

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

- name: Deploy to ${{ inputs.DEPLOY_URL || vars.DEPLOY_URL }}
run: |
echo "Cloning and running deploy script"
git clone --branch main --depth 1 https://github.com/ubi-agni/ros-builder-action.git $RUNNER_TEMP/ros-builder-action
$RUNNER_TEMP/ros-builder-action/src/scripts/generic.sh $RUNNER_TEMP/ros-builder-action/src/scripts/deploy.sh
env:
DEPLOY_URL: ${{ inputs.DEPLOY_URL || vars.DEPLOY_URL }}
TOKEN: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
CONTENT_MODE: ${{ inputs.CONTENT_MODE || vars.CONTENT_MODE || 'newer' }}
PUSH_MODE: ${{ inputs.PUSH_MODE || vars.PUSH_MODE || 'push' }}
MESSAGE: ${{ inputs.MESSAGE || 'deploy' }}
COMMIT_NAME: ${{ inputs.COMMIT_NAME || github.actor }}
COMMIT_EMAIL: ${{ inputs.COMMIT_EMAIL || format('{0}@users.noreply.github.com', github.actor) }}
63 changes: 27 additions & 36 deletions .github/workflows/interactive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
required: true
description: 'ROS distribution codename:'
default: one

ROS_SOURCES:
type: string
description: 'ROS sources to compile:'
Expand All @@ -26,65 +27,55 @@ on:
type: string
description: 'colcon package selection:'
required: false
SKIP_EXISTING:

CONTINUE_BUILD:
type: boolean
description: Skip existing packages?
required: false
description: Continue build?
required: true
default: false

# Installing built packages to chroot speeds up downstream builds
INSTALL_TO_CHROOT:
type: boolean
description: Incrementally fill chroot?
required: false
DEPLOY_MODE:

PUSH_MODE:
type: choice
description: How to deploy?
description: Push to DEPLOY_URL?
required: true
default: skip
options:
- skip
- push
- amend
- squash
- append
BRANCH:
type: string
description: 'Branch to use:'
required: false

env:
BRANCH: ${{ inputs.BRANCH || format('{0}-{1}', inputs.DEB_DISTRO, inputs.ROS_DISTRO) }}

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
uses: ubi-agni/ros-builder-action/.github/workflows/build.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 }}
COLCON_PKG_SELECTION: ${{ inputs.COLCON_PKG_SELECTION || vars.COLCON_PKG_SELECTION || '' }}
# proceed from existing debs artifact if run_attempt > 1
DOWNLOAD_DEBS: ${{ github.run_attempt != '1' }}
SKIP_EXISTING: ${{ inputs.SKIP_EXISTING || vars.SKIP_EXISTING || false}}
SKIP_EXISTING: ${{ inputs.CONTINUE_BUILD }}
INSTALL_TO_CHROOT: ${{ inputs.INSTALL_TO_CHROOT || vars.INSTALL_TO_CHROOT || false }}

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.DEBS_PATH || '~/debs' }}
REPO: ${{ vars.DEPLOY_URL }}

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

- name: Deploy
uses: s0/[email protected]
env:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}
MESSAGE: "${{ inputs.DEB_DISTRO }}-${{ inputs.ROS_DISTRO }} build"
SQUASH_HISTORY: ${{ inputs.DEPLOY_MODE == 'squash' }}
if: always() && ( inputs.PUSH_MODE != 'skip' ) && vars.DEPLOY_URL
uses: ubi-agni/ros-builder-action/.github/workflows/deploy.yaml@main
with:
# content mode: 'add' if continueing build, 'replace' otherwise
CONTENT_MODE: ${{ inputs.CONTINUE_BUILD && 'add' || 'replace' }}
# default push mode: 'push' if continueing build, 'squash' otherwise
PUSH_MODE: ${{ inputs.PUSH_MODE || vars.PUSH_MODE || (inputs.CONTINUE_BUILD && 'push' || 'squash') }}
MESSAGE: "${{ needs.build.outputs.LATEST_PACKAGE \
&& format('build up to {0}', needs.build.outputs.LATEST_PACKAGE) \
|| format('{0}-{1}', inputs.DEB_DISTRO || vars.DEB_DISTRO, inputs.ROS_DISTRO || vars.ROS_DISTRO || 'one') }}"
secrets:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}
Loading

0 comments on commit 20bfc88

Please sign in to comment.