Added functionality for running CI unit tests on modified modules only #284
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: Build and Test Monorepo | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
get_changed_modules: | |
runs-on: ubuntu-latest | |
name: Get changed modules | |
outputs: | |
modified_modules: ${{ steps.output-changes.outputs.modified_modules }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. | |
- name: Find changed files inside action folder | |
id: changed-files-action | |
uses: tj-actions/changed-files@v43 | |
with: | |
files: src/action/** | |
- name: Get changed files inside interfacing folder | |
id: changed-files-interfacing | |
uses: tj-actions/changed-files@v42 | |
with: | |
files: src/interfacing/** | |
- name: Get changed files inside perception folder | |
id: changed-files-perception | |
uses: tj-actions/changed-files@v42 | |
with: | |
files: src/perception/** | |
- name: Get changed files inside samples folder | |
id: changed-files-samples | |
uses: tj-actions/changed-files@v42 | |
with: | |
files: src/samples/** | |
- name: Get changed files inside simulation folder | |
id: changed-files-simulation | |
uses: tj-actions/changed-files@v42 | |
with: | |
files: src/simulation/** | |
- name: Get changed files inside world_modeling folder | |
id: changed-files-world-modeling | |
uses: tj-actions/changed-files@v42 | |
with: | |
files: src/world_modeling/** | |
- name: Update CHANGED_MODULES for changes | |
if: steps.changed-files-action.outputs.any_changed == 'true' | |
run: | | |
if [steps.changed-files-action.outputs.any_changed == 'true']; then | |
echo "Detected action changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES action" >> $GITHUB_ENV | |
fi | |
if [steps.changed-files-interfacing.outputs.any_changed == 'true']; then | |
echo "Detected interfacing changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES interfacing" >> $GITHUB_ENV | |
fi | |
if [steps.changed-files-perception.outputs.any_changed == 'true']; then | |
echo "Detected perception changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES perception" >> $GITHUB_ENV | |
fi | |
if [steps.changed-files-samples.outputs.any_changed == 'true']; then | |
echo "Detected samples changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES samples" >> $GITHUB_ENV | |
fi | |
if [steps.changed-files-simulation.outputs.any_changed == 'true']; then | |
echo "Detected simulation changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES simulation" >> $GITHUB_ENV | |
fi | |
if [steps.changed-files-world-modeling.outputs.any_changed == 'true']; then | |
echo "Detected world_modeling changes" | |
echo "CHANGED_MODULES=$CHANGED_MODULES world_modeling" >> $GITHUB_ENV | |
fi | |
- name: Output list of changed modules | |
id: output-changes | |
run: | | |
echo "The changed modules are: $CHANGED_MODULES" | |
echo "modified_modules=$CHANGED_MODULES" >> $GITHUB_OUTPUT | |
setup-environment: | |
name: Setup environment | |
runs-on: ubuntu-latest | |
needs: get_changed_modules | |
env: | |
modified_modules: ${{ needs.get_changed_modules.outputs.modified_modules }} | |
outputs: | |
docker_matrix: ${{ steps.docker-environment.outputs.docker_matrix }} | |
registry: ${{ steps.docker-environment.outputs.registry }} | |
repository: ${{ steps.docker-environment.outputs.repository }} | |
source_branch: ${{ steps.github-environment.outputs.source_branch }} | |
target_branch: ${{ steps.github-environment.outputs.target_branch }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Setup Watod Environment | |
run: ./watod_scripts/watod-setup-env.sh | |
shell: bash | |
- name: Check module changes | |
run: echo "changed is ${{ env.modified_modules }}" | |
- name: Generate Docker Environment | |
id: docker-environment | |
uses: "./.github/templates/docker_context" | |
with: | |
modified_modules: ${{ env.modified_modules }} | |
- name: Generate GitHub Environment | |
id: github-environment | |
uses: "./.github/templates/github_context" | |
build-and-unittest: | |
name: Build Image and Run Unit Testing Suite | |
runs-on: ubuntu-latest | |
needs: setup-environment | |
env: | |
DOCKER_REGISTRY: ${{ needs.setup-environment.outputs.registry }} | |
DOCKER_REPOSITORY: ${{ needs.setup-environment.outputs.repository }} | |
SOURCE_BRANCH: ${{ needs.setup-environment.outputs.source_branch }} | |
TARGET_BRANCH: ${{ needs.setup-environment.outputs.target_branch }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.setup-environment.outputs.docker_matrix) }} | |
concurrency: | |
group: ${{ matrix.service }}-${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Construct Registry URL | |
id: construct-registry-url | |
run: | | |
echo "url=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPOSITORY }}/${{ matrix.module }}/${{ matrix.service }}" \ | |
>> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
id: buildx | |
- name: Docker Login | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ secrets.GHCR_USER }} | |
password: ${{ secrets.GHCR_PWD }} | |
- name: Prepare Image Dependencies | |
if: ${{ matrix.module != 'infrastructure' }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile | |
push: true | |
tags: | | |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }} | |
cache-from: | | |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }} | |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.TARGET_BRANCH }} | |
cache-to: type=inline | |
builder: ${{ steps.buildx.outputs.name }} | |
target: dependencies | |
- name: Build Image from Source | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile | |
push: true | |
tags: | | |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }} | |
cache-from: | | |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }} | |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }} | |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.TARGET_BRANCH }} | |
cache-to: type=inline | |
builder: ${{ steps.buildx.outputs.name }} | |
target: build | |
- name: Security Sanitation for Deployment | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile | |
push: true | |
tags: | | |
${{ steps.construct-registry-url.outputs.url }}:${{ env.SOURCE_BRANCH }} | |
cache-from: | | |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }} | |
${{ steps.construct-registry-url.outputs.url }}:${{ env.SOURCE_BRANCH }} | |
${{ steps.construct-registry-url.outputs.url }}:${{ env.TARGET_BRANCH }} | |
cache-to: type=inline | |
builder: ${{ steps.buildx.outputs.name }} | |
target: deploy | |
- name: Run testing suite | |
uses: "./.github/templates/test" | |
env: | |
DOCKER_BUILDKIT: 1 | |
COMPOSE_DOCKER_CLI_BUILD: 1 | |
BUILDKIT_INLINE_CACHE: 1 | |
with: | |
image: ${{ steps.construct-registry-url.outputs.url }} | |
tag: build_${{ env.SOURCE_BRANCH }} |