ci: fix ref if main #282
Workflow file for this run
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: test | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
env: | |
RETRY-TEST-NUM: 10 | |
jobs: | |
test: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 5 | |
container: osrf/ros:humble-desktop-full | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Apt update install | |
run: | | |
sudo apt update -y | |
sudo apt install -y \ | |
psmisc \ | |
rsync \ | |
xvfb \ | |
ros-$ROS_DISTRO-navigation2 \ | |
ros-$ROS_DISTRO-nav2-bringup \ | |
ros-$ROS_DISTRO-turtlebot3-gazebo | |
- name: Build | |
run: | | |
mkdir -p /root/ros2_ws/src/emcl2_ros2/ | |
rsync -av ./ /root/ros2_ws/src/emcl2_ros2/ | |
cd /root/ros2_ws | |
source /opt/ros/$ROS_DISTRO/setup.bash | |
rosdep update | |
rosdep install -i -y --from-path src --rosdistro $ROS_DISTRO | |
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release | |
shell: bash | |
- name: Exec | |
run: | | |
source /root/ros2_ws/install/setup.bash | |
ros2 run emcl2 test.bash | |
shell: bash | |
retry: | |
runs-on: ubuntu-22.04 | |
needs: test | |
if: ${{ always() && needs.test.result == 'failure' }} | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
async function run() { | |
const { owner, repo } = context.repo; | |
const workflow_id = 'rerun.yml'; | |
const ref = ('${{ github.head_ref }}' === '' || '${{ github.head_ref }}' === 'main') ? 'main' : '${{ github.head_ref }}'; | |
const run_id = context.runId; | |
try { | |
const workflow_run = await github.rest.actions.getWorkflowRun({ | |
owner, | |
repo, | |
run_id | |
}); | |
if (workflow_run.data.run_attempt < ${{ env.RETRY-TEST-NUM }}) { | |
console.log('Triggering workflow dispatch...'); | |
await github.rest.actions.createWorkflowDispatch({ | |
owner, | |
repo, | |
workflow_id, | |
ref | |
}); | |
} else { | |
console.log('Conditions not met for re-dispatch.'); | |
} | |
} catch (error) { | |
console.error('Failed to fetch workflow run or dispatch:', error); | |
} | |
} | |
run(); |