Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a comment trigger #8

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/parse_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import os
import sys

if __name__ == "__main__":
comment = os.environ["COMMENT_BODY"]

args = {}
for line in comment.splitlines():
line = line.strip()
if not line or line.find('=') < 0:
continue
k, v = line.split('=')
args[k] = v

if 'COLCON_ARGS' in args:
args['COLCON_BUILD_ARGS'] = args['COLCON_ARGS']
args['COLCON_TEST_ARGS'] = args['COLCON_ARGS']

github_env = os.environ["GITHUB_ENV"]
with open(github_env, 'w') as f:
for (k, v) in args.items():
f.write(f'{k}={v}\n')

sys.exit(0)
142 changes: 142 additions & 0 deletions .github/workflows/comment_trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: My Comment-based Pipeline
on:
issues:
types: [opened]
issue_comment:
types: [created]

jobs:
pixi-build:
name: Build workspace on-demand
permissions: write-all
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
BUILDCACHE_MAX_CACHE_SIZE: 2000000000 # optional: Need a bigger cache?
# BUILDCACHE_LOG_FILE: ${{ matrix.label }}.buildcache.log # optional: include log output
# BUILDCACHE_DEBUG: 2 # optional: debug level, less is more
BUILDCACHE_DIRECT_MODE: true # optional: Allow direct caching
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.17.1
cache: true

- uses: mjcarroll/buildcache-action@v2
with:
cache_key: ${{ matrix.label }}
upload_buildcache_log: 'false'
zero_buildcache_stats: 'true'

- env:
EVENT_CONTEXT: ${{ toJSON(github.event) }}
run: |
echo $EVENT_CONTEXT

- name: "Set node id (issue)"
if: ${{ github.event.action }} == "opened"
run: |
echo "NODE_ID=${{ github.event.issue.node_id }}" >> "$GITHUB_ENV"

- name: "Set node id (comment)"
if: ${{ github.event.action }} == "created"
run: |
echo "NODE_ID=${{ github.event.comment.node_id }}" >> "$GITHUB_ENV"

- name: "React"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"

- name: "Parse issue body"
if: ${{ github.event.action }} == "opened"
env:
COMMENT_BODY: ${{ github.event.issue.body }}
run: |
.github/parse_comment.py

- name: "Parse comment body"
if: ${{ github.event.action }} == "created"
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
.github/parse_comment.py

- run: pixi run sync --repos-uri $REPOS

- name: Export compiler variables [Linux]
if: contains(matrix.os, 'ubuntu')
shell: bash -l {0}
run: |
echo "BUILDCACHE_CC=x86_64-conda-linux-gnu-gcc" >> $GITHUB_ENV
echo "BUILDCACHE_CXX=x86_64-conda-linux-gnu-g++" >> $GITHUB_ENV
echo "CMAKE_C_COMPILER_LAUNCHER=buildcache" >> $GITHUB_ENV
echo "CMAKE_CXX_COMPILER_LAUNCHER=buildcache" >> $GITHUB_ENV

- run: |
pixi run build --cmake-args \
-GNinja \
--no-warn-unused-cli \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DCMAKE_C_COMPILER_LAUNCHER=buildcache \
-DCMAKE_CXX_COMPILER_LAUNCHER=buildcache \
-DSTACK_DETAILS_AUTO_DETECT:BOOL=FALSE \
-DSTACK_DETAILS_BFD:BOOL=FALSE \
-DBUILD_DOCS:BOOL=FALSE \
-DCMAKE_C_COMPILER=$BUILDCACHE_CC \
-DCMAKE_CXX_COMPILER=$BUILDCACHE_CXX \
$COLCON_BUILD_ARGS

- name: "Notify on success"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_UP}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"
(
echo "**Success: ${{ github.workflow }}**"
echo "REPOS_FILE: ${REPOS}"
echo "COLCON_ARGS: ${COLCON_ARGS}"
echo "COLCON_BUILD_ARGS: ${COLCON_BUILD_ARGS}"
echo "COLCON_TEST_ARGS: ${COLCON_BUILD_ARGS}"
echo "You can find the workflow here:"
echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
) | \
gh issue comment "${{ github.event.issue.number }}" --repo ${{ github.repository }} -F -


notify-job:
needs: [pixi-build]
if: ${{ always() && contains(needs.*.result, 'failure') }}
runs-on: ubuntu-latest
name: Report workspace failure
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: "Set node id (issue)"
if: ${{ github.event.action }} == "opened"
run: |
echo "NODE_ID=${{ github.event.issue.node_id }}" >> "$GITHUB_ENV"

- name: "Set node id (comment)"
if: ${{ github.event.action }} == "created"
run: |
echo "NODE_ID=${{ github.event.comment.node_id }}" >> "$GITHUB_ENV"

- name: "Notify on failure"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"
(
echo "**Failed : ${{ github.workflow }}**"
echo "You can find the workflow here:"
echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
) | \
gh issue comment "${{ github.event.issue.number }}" --repo ${{ github.repository }} -F -
66 changes: 0 additions & 66 deletions collection-ionic.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions gazebo.toml

This file was deleted.

50 changes: 23 additions & 27 deletions helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,57 @@
import os
import shutil
import sys
import tomllib
import urllib.request

WORKSPACE_NAME = 'gazebosim_ws'
COLCON_DEFAULTS_FILE = '.github/ci/colcon_defaults.yaml'
DEFAULT_COLLECTION = 'collection-ionic.yaml'

def sync(args, rem_args):
from vcstool.commands.vcs import main as vcs_main
workspace_name = f'{args.distro}_ws'
if args.repos_file:
repos_file = args.repos_file
else:
repos_file = f'{workspace_name}/gazebodistro.repos'
urllib.request.urlretrieve(
f'https://raw.githubusercontent.com/gazebo-tooling/gazebodistro/master/collection-{args.distro}.yaml',
repos_file)

if not os.path.exists(f'{workspace_name}/src'):
os.makedirs(os.path.join(args.curdir, f'{workspace_name}/src'))

argv = ['import', '--input', repos_file, *rem_args, f'{workspace_name}/src']

uri = f'https://raw.githubusercontent.com/gazebo-tooling/gazebodistro/master/{args.collection}'
if args.repos_uri:
uri = args.repos_uri

if not os.path.exists(f'{args.workspace_name}/src'):
os.makedirs(os.path.join(args.curdir, f'{args.workspace_name}/src'))

repos_file = f'{args.workspace_name}/workspace.repos'
print(f'Fetching: {uri}')
urllib.request.urlretrieve(uri, repos_file)

argv = ['import', '--input', repos_file, *rem_args, f'{args.workspace_name}/src']
return vcs_main(argv)


def colcon(args, rem_args):
from colcon_core.command import main as colcon_main
os.environ["COLCON_DEFAULTS_FILE"] = os.path.join(args.curdir, args.colcon_defaults)
os.chdir(os.path.join(args.curdir, f'{args.distro}_ws'))
os.chdir(os.path.join(args.curdir, f'{args.workspace_name}'))
return colcon_main(argv=rem_args)


def clean(args, rem_args):
for subdir in ['build', 'install', 'log']:
try:
shutil.rmtree(os.path.join(os.curdir, f'{args.distro}_ws/{subdir}'))
shutil.rmtree(os.path.join(os.curdir, f'{args.workspace_name}/{subdir}'))
except Exception as ex:
print(ex)


if __name__ == "__main__":
# Read some configuration defaults from the toml file
with open('gazebo.toml', 'rb') as f:
data = tomllib.load(f)
defaults = data['gazebo']

if 'repos_file' not in defaults:
defaults['repos_file'] = None

parser = argparse.ArgumentParser(
prog='Pixi Task Helper',
description='Help with common pixi tasks')

parser.add_argument('--distro', type=str, default=defaults['distro'])
parser.add_argument('--colcon-defaults', type=str, default=defaults['colcon_defaults'])
parser.add_argument('--repos-file', type=str, default=defaults['repos_file'])
parser.add_argument('--workspace-name', type=str, default=WORKSPACE_NAME)
parser.add_argument('--colcon-defaults', type=str, default=COLCON_DEFAULTS_FILE)

subparsers = parser.add_subparsers()
sync_parser = subparsers.add_parser('sync')
sync_parser.add_argument('--collection', type=str, default=DEFAULT_COLLECTION)
sync_parser.add_argument('--repos-uri', type=str)
sync_parser.set_defaults(func=sync)

colcon_parser = subparsers.add_parser('colcon')
Expand All @@ -89,5 +84,6 @@ def clean(args, rem_args):
clean_parser.set_defaults(func=clean)

args, rem_args = parser.parse_known_args()

args.curdir = os.path.abspath(os.path.curdir)
sys.exit(args.func(args, rem_args))
Loading