Add CI/testing pipelines + format code #41
This file contains hidden or 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: Micro Autonomy Build and Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| setup-environment: | |
| name: Setup Environment | |
| runs-on: ubuntu-latest | |
| 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: Get Module Changes | |
| id: get-module-changes | |
| uses: "./.github/templates/check_src_changes" | |
| - name: Setup Watod Environment | |
| run: | | |
| MODULES_DIR="$GITHUB_WORKSPACE/modules" | |
| . ./watod_scripts/watod-setup-docker-env.sh | |
| shell: bash | |
| # - name: Generate Docker Environment (from monorepo) | |
| # id: docker-environment | |
| # uses: "./.github/templates/docker_context" | |
| # with: | |
| # modified_modules: ${{ steps.get-module-changes.outputs.modified_modules }} | |
| - name: Generate Docker Environment | |
| id: docker-environment | |
| run: | | |
| matrix='{"include":[{"service":"robot","module":"","dockerfile":"docker/robot/robot.Dockerfile"}]}' | |
| echo "docker_matrix=$matrix" >> $GITHUB_OUTPUT | |
| echo "registry=ghcr.io" >> $GITHUB_OUTPUT | |
| echo "repository=watonomous/wato_f1tenth" >> $GITHUB_OUTPUT | |
| - name: Generate GitHub Environment | |
| id: github-environment | |
| uses: "./.github/templates/github_context" | |
| build-and-unittest: | |
| name: Build/Test | |
| 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.service }}" \ | |
| >> $GITHUB_OUTPUT | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| id: buildx | |
| # uses default token right now | |
| - name: Docker Login | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.DOCKER_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - 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 }}:build_${{ env.TARGET_BRANCH }} | |
| builder: ${{ steps.buildx.outputs.name }} | |
| target: build | |
| - 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 }} | |
| confirm-build-and-unittest-complete: | |
| name: Confirm Build and Unit Tests Completed | |
| needs: build-and-unittest | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Ending | |
| run: | | |
| echo "::notice:: All builds and unit tests completed!" |