Skip to content

Commit

Permalink
Cobalt GitHub Actions workflows.
Browse files Browse the repository at this point in the history
b/276986353

Change-Id: I51dfd6967c189de598b98ba436584c59f1d66f4d
NOKEYCHECK=True
GitOrigin-RevId: 9f872f6ec84c0635001d422a285c74b4cec48e26
  • Loading branch information
isarkis authored and andrewsavage1 committed Apr 12, 2023
1 parent c739436 commit 1d51125
Show file tree
Hide file tree
Showing 36 changed files with 2,114 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Cobalt
description: Builds Cobalt targets
runs:
using: "composite"
steps:
- name: Set up Cloud SDK
if: startsWith(${{matrix.target_platform}}, 'android')
uses: google-github-actions/setup-gcloud@v1
- name: Set Android env vars
if: startsWith(${{matrix.target_platform}}, 'android')
run: |
echo "ANDROID_HOME=/root/starboard-toolchains/AndroidSdk/" >> $GITHUB_ENV
PROJECT_NAME=$(gcloud config get-value project)
echo "GCS_NIGHTLY_PATH=gs://${PROJECT_NAME}-build-artifacts" >> $GITHUB_ENV
shell: bash
- name: Build
run: |
set -x
env
if [ -z ${COBALT_BOOTLOADER+x} ]; then
BUILD_PLATFORM=${{ matrix.target_platform }}
BUILD_TARGET=all
if [[ "${{matrix.config}}" =~ ^(qa|gold)$ ]]; then
BUILD_TARGET=default
fi
else
BUILD_PLATFORM=${COBALT_BOOTLOADER}
BUILD_TARGET='loader_app_install elf_loader_sandbox_install crashpad_handler_install'
fi
# GitHub Runners have home set to /github/home.
if [ -d /root/starboard-toolchains ]; then
ln -s /root/starboard-toolchains /github/home/starboard-toolchains
fi
ninja -v -C ${GITHUB_WORKSPACE}/out/${BUILD_PLATFORM}_${{matrix.config}} ${BUILD_TARGET}
shell: bash
- name: Show Sccache Stats
run: sccache -s
shell: bash
96 changes: 96 additions & 0 deletions .github/actions/docker/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Docker Image Build
description: Builds Cobalt build docker images.
inputs:
docker_service:
description: "Docker compose service."
required: true
docker_image:
description: "Docker image name."
required: true

runs:
using: "composite"
steps:
- name: Get docker file changes
id: changed-files
uses: tj-actions/changed-files@8953e851a137075e59e84b5c15fbeb3617e82f15 # v32.1.1
with:
files: |
docker-compose.yml
docker/linux/**
.github/actions/docker/**
- name: Retrieve Docker metadata
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{env.REGISTRY}}/${{github.repository}}/${{inputs.docker_image}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Set Docker Tag
id: set-docker-tag
run: |
set -x
docker_tag="${{ steps.meta.outputs.tags }}"
docker_tag="${docker_tag%.1[+,-]}"
echo "DOCKER_TAG=${docker_tag}" >> $GITHUB_ENV
shell: bash
# We need to set docker tag properly for pull requests. In those scenarios where no docker related files
# were changed we need to use an existing image (e.g. main). In cases where docker image is rebuilt we have
# to use tag generated by the image build.
- name: Set Docker Tag
id: set-docker-tag-presubmit-non-fork
env:
REPO: ${{ github.repository }}
if: ${{ (steps.changed-files.outputs.any_changed == 'false') && (github.event_name == 'pull_request') }}
run: echo "DOCKER_TAG=ghcr.io/${REPO}/${{inputs.docker_image}}:${GITHUB_BASE_REF%.1+}" >> $GITHUB_ENV
shell: bash
- name: Set up Cloud SDK
if: ${{ (steps.changed-files.outputs.any_changed == 'true') && (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.fork) }}
uses: google-github-actions/setup-gcloud@v1
- name: Set Docker Tag
id: set-docker-tag-presubmit-fork
env:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
if: ${{ (steps.changed-files.outputs.any_changed == 'true') && (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.fork) }}
run: |
# Need to login to GCR to be able to push images created by fork based PR workflows.
PROJECT_NAME=$(gcloud config get-value project)
METADATA="http://metadata.google.internal./computeMetadata/v1"
SVC_ACCT="${METADATA}/instance/service-accounts/default"
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' ${SVC_ACCT}/token | cut -d'"' -f 4)
printf ${ACCESS_TOKEN} | docker login -u oauth2accesstoken --password-stdin https://gcr.io
echo "DOCKER_TAG=gcr.io/${PROJECT_NAME}/${{inputs.docker_image}}:pr-${GITHUB_EVENT_NUMBER}" >> $GITHUB_ENV
shell: bash
- name: Process Docker metadata
id: process-docker-metadata
run: |
set -x
set +e
docker manifest inspect $DOCKER_TAG > /dev/null
if [[ $? -ne 0 || ${{ steps.changed-files.outputs.any_changed }} == 'true' ]]; then
echo "need_to_build=true" >> $GITHUB_ENV
else
echo "need_to_build=false" >> $GITHUB_ENV
fi
shell: bash
- name: Build containers with docker-compose
id: build-image
if: env.need_to_build == 'true'
uses: smartlyio/docker-compose-action@83392e28664cc0cb5b3208e8d75697d01da8db18 # v1.7.1
with:
serviceName: ${{ inputs.docker_service }}
build: false
push: "on:push"
composeArguments: "--no-start"
- name: Tag images
id: tag-images
if: env.need_to_build == 'true'
run: docker tag ${{inputs.docker_image}} $DOCKER_TAG
shell: bash
- name: Push images
id: push-image
if: env.need_to_build == 'true'
run: docker push ${DOCKER_TAG}
shell: bash
72 changes: 72 additions & 0 deletions .github/actions/docker_win/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker Image Build
description: Builds Cobalt build docker images.
inputs:
service:
description: "Service name from docker compose."
required: true
runs:
using: "composite"
steps:
- name: Get docker file changes
id: changed-files
uses: tj-actions/changed-files@8953e851a137075e59e84b5c15fbeb3617e82f15 # v32.1.1
with:
files: |
docker-compose-windows.yml
docker/windows/**
.github/actions/docker_win/**
- name: Retrieve Docker metadata
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{env.REGISTRY}}/${{github.repository}}/cobalt-${{inputs.service}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Set Docker Tag
run: |
set -x
docker_tag="${{ steps.meta.outputs.tags }}"
docker_tag="${docker_tag%.1[+,-]}"
echo "DOCKER_TAG=${docker_tag}" >> $GITHUB_ENV
shell: bash
# We need to set docker tag properly for pull requests. In those scenarios where no docker related files
# were changed we need to use an existing image (e.g. main). In cases where docker image is rebuilt we have
# to use tag generated by the image build.
- name: Set Docker Tag
if: ${{ (steps.changed-files.outputs.any_changed == 'false') && (github.event_name == 'pull_request') }}
env:
REPO: ${{ github.repository }}
run: echo "DOCKER_TAG=ghcr.io/${REPO}/cobalt-${{inputs.service}}:${GITHUB_BASE_REF%.1+}" >> $GITHUB_ENV
shell: bash
- name: Process Docker metadata
id: process-docker
run: |
set -x
set +e
docker manifest inspect $DOCKER_TAG > /dev/null
if [[ $? -ne 0 || ${{ steps.changed-files.outputs.any_changed }} == 'true' ]]; then
echo "need_to_build=true" >> $GITHUB_ENV
else
echo "need_to_build=false" >> $GITHUB_ENV
fi
shell: bash
- name: Build containers with docker-compose
if: env.need_to_build == 'true'
env:
DOCKER_CPUS: 2
SERVICE: ${{inputs.service}}
shell: bash
run: |
set -xue
docker compose -f docker-compose-windows.yml up --no-start "${SERVICE}"
- name: Tag images
if: ${{ (env.need_to_build == 'true') && ((github.event_name != 'pull_request') || (!github.event.pull_request.head.repo.fork)) }}
run: |
docker tag cobalt-${{inputs.service}} $DOCKER_TAG
shell: bash
- name: Push images
if: ${{ (env.need_to_build == 'true') && ((github.event_name != 'pull_request') || (!github.event.pull_request.head.repo.fork)) }}
run: docker push ${DOCKER_TAG}
shell: bash
36 changes: 36 additions & 0 deletions .github/actions/gn/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: GN
description: Generates and checks GN.
runs:
using: "composite"
steps:
- name: Configure Environment
shell: bash
run: |
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Set up Cloud SDK
if: startsWith(${{matrix.target_platform}}, 'android')
uses: google-github-actions/setup-gcloud@v1
- name: Configure Android Environment
shell: bash
if: startsWith(${{matrix.target_platform}}, 'android')
run: |
echo "ANDROID_HOME=/root/starboard-toolchains/AndroidSdk/" >> $GITHUB_ENV
echo "COBALT_GRADLE_BUILD_COUNT=24" >> $GITHUB_ENV
PROJECT_NAME=$(gcloud config get-value project)
echo "GCS_NIGHTLY_PATH=gs://${PROJECT_NAME}-build-artifacts" >> $GITHUB_ENV
- name: GN
run: |
set -x
extra_arguments="${{matrix.extra_gn_arguments}}"
if [ -z ${COBALT_BOOTLOADER+x} ]; then
BUILD_PLATFORM=${{ matrix.target_platform }}
else
BUILD_PLATFORM=${COBALT_BOOTLOADER}
if [ ! -z "${{matrix.bootloader_extra_gn_arguments}}" ]
then
extra_arguments="${{matrix.bootloader_extra_gn_arguments}}"
fi
fi
gn gen $GITHUB_WORKSPACE/out/${BUILD_PLATFORM}_${{matrix.config}} --args="target_platform=\"${BUILD_PLATFORM}\" ${{matrix.sb_api_version}} ${{matrix.target_os}} ${{matrix.target_cpu}} ${extra_arguments} is_internal_build=false build_type=\"${{matrix.config}}\""
gn check $GITHUB_WORKSPACE/out/${BUILD_PLATFORM}_${{ matrix.config }}
shell: bash
101 changes: 101 additions & 0 deletions .github/actions/on_device_tests/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: On Device Test
description: Runs on-device tests.

runs:
using: "composite"
steps:
- name: Install requirements
run: |
pip3 install grpcio==1.38.0 grpcio-tools==1.38.0
shell: bash
- name: Generate gRPC files
run: |
python -m grpc_tools.protoc -Itools/ --python_out=tools/ --grpc_python_out=tools/ tools/on_device_tests_gateway.proto
shell: bash
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- name: Set env vars
env:
WORKFLOW: ${{ github.workflow }}
run: |
echo "PROJECT_NAME=$(gcloud config get-value project)" >> $GITHUB_ENV
echo "GITHUB_RUN_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
echo "WORKFLOW=${WORKFLOW}" >> $GITHUB_ENV
# Boot loader env
if [ "${COBALT_BOOTLOADER}" != "null" ]; then
echo "LOADER_CONFIG=${{ matrix.config }}" >> $GITHUB_ENV
echo "LOADER_PLATFORM=${COBALT_BOOTLOADER}" >> $GITHUB_ENV
fi
# dimension env
if [ "${{ matrix.dimension }}" != "null" ]; then
echo "DIMENSION=${{ matrix.dimension }}" >> $GITHUB_ENV
fi
# Shard env
if [[ "${{matrix.shard}}" == 'black_box_test' || "${{matrix.shard}}" == 'evergreen_test' || "${{matrix.shard}}" == 'unit_test' ]]; then
echo "SHARD_NAME=${{ matrix.shard }}" >> $GITHUB_ENV
echo "TEST_TYPE=${{ matrix.shard }}" >> $GITHUB_ENV
else
echo "SHARD_NAME=unit_test_${{ matrix.shard }}" >> $GITHUB_ENV
echo "TEST_TYPE=unit_test" >> $GITHUB_ENV
echo "USE_SHARDING=1" >> $GITHUB_ENV
fi
shell: bash
- name: trigger ${{ env.SHARD_NAME }} tests on ${{ matrix.platform }} platform
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_TOKEN: ${{ github.token }}
GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }}
GITHUB_ACTOR_ID: ${{ github.actor_id }}
GITHUB_REPO: ${{ github.repository }}
GITHUB_PR_HEAD_USER_LOGIN: ${{ github.event.pull_request.head.user.login }}
GITHUB_PR_HEAD_USER_ID: ${{ github.event.pull_request.head.user.id }}
GITHUB_COMMIT_AUTHOR_USERNAME: ${{ github.event.commits[0].author.username }}
GITHUB_COMMIT_AUTHOR_EMAIL: ${{ github.event.commits[0].author.email }}
run: |
set -uxe
SESSION_ID=$(
python3 tools/on_device_tests_gateway_client.py \
--token ${GITHUB_TOKEN} \
--change_id "${GITHUB_PR_HEAD_SHA:-$GITHUB_SHA}" \
trigger \
--test_type ${{ env.TEST_TYPE }} \
--platform ${{ matrix.target_platform }} \
--config ${{ matrix.config }} \
--tag cobalt_github_${GITHUB_EVENT_NAME} \
--builder_name github_${{ matrix.platform }}_tests \
--build_number ${GITHUB_RUN_NUMBER} \
${LOADER_PLATFORM:+"--loader_config" "$LOADER_CONFIG"} \
${LOADER_PLATFORM:+"--loader_platform" "$LOADER_PLATFORM"} \
${DIMENSION:+"--dimension" "$DIMENSION"} \
${USE_SHARDING:+"--unittest_shard_index" "${{ matrix.shard }}"} \
--archive_path gs://${PROJECT_NAME}-test-artifacts/${WORKFLOW}/${GITHUB_RUN_NUMBER}/${{ matrix.platform }}_${{ matrix.config }}/artifacts.tar \
--label github \
--label ${GITHUB_EVENT_NAME} \
--label ${WORKFLOW} \
--label actor-${GITHUB_ACTOR} \
--label actor_id-${GITHUB_ACTOR_ID} \
--label triggering_actor-${GITHUB_TRIGGERING_ACTOR} \
--label sha-${GITHUB_SHA} \
--label repository-${GITHUB_REPO} \
--label author-${GITHUB_PR_HEAD_USER_LOGIN:-$GITHUB_COMMIT_AUTHOR_USERNAME} \
--label author_id-${GITHUB_PR_HEAD_USER_ID:-$GITHUB_COMMIT_AUTHOR_EMAIL}
)
echo "SESSION_ID=$SESSION_ID" >> $GITHUB_ENV
shell: bash
- name: watch ${{ env.SHARD_NAME }} tests on ${{ matrix.platform }} platform
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_SHA: ${{ github.sha }}
run: |
set -uxe
python3 tools/on_device_tests_gateway_client.py \
--token "${GITHUB_TOKEN}" \
--change_id "${GITHUB_SHA}" \
watch ${{ env.SESSION_ID }}
shell: bash
Loading

0 comments on commit 1d51125

Please sign in to comment.