blob: 702d89e1fe21f03db650be1ac7fabc9a686349f4 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Playground Examples CI/CD for a given SDK and origin
on:
workflow_call:
inputs:
step:
type: string
required: true
sdk:
type: string
required: true
subdirs:
type: string
required: true
allowlist:
type: string
required: true
origin:
type: string
required: true
env:
BEAM_VERSION: 2.44.0
jobs:
check_has_examples:
name: pre-check
runs-on: ubuntu-latest
outputs:
example_has_changed: ${{ steps.check_has_example.outputs.example_has_changed }}
env:
SDK: ${{ inputs.sdk }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: install deps
run: pip install -r requirements.txt
working-directory: playground/infrastructure
- name: pytest
run: pytest
working-directory: playground/infrastructure
- name: get Difference
id: check_file_changed
run: |
set -xeu
# define the base ref
BASE_REF=$GITHUB_BASE_REF
if [ -z "$BASE_REF" ] || [ "$BASE_REF" == "master" ]; then
BASE_REF=origin/master
fi
DIFF=$(git diff --name-only $BASE_REF $GITHUB_SHA | tr '\n' ' ')
echo "example_diff=$DIFF" >> $GITHUB_OUTPUT
- id: check_has_example
name: has Examples
run: |
# don't quit on errors, check unbound vars, and show commands
set +e -ux
python3 checker.py \
--verbose \
--sdk SDK_${SDK^^} \
--allowlist ${{ inputs.allowlist }} \
--paths ${{ steps.check_file_changed.outputs.example_diff }}
CODE=$?
if [ $CODE -eq 0 ]; then
echo "example_has_changed=True" >> $GITHUB_OUTPUT
elif [ $CODE -eq 11 ]; then
echo "example_has_changed=False" >> $GITHUB_OUTPUT
else
echo "checker is broken"
exit 1
fi
working-directory: playground/infrastructure
env:
BEAM_ROOT_DIR: "../.."
BEAM_EXAMPLE_CATEGORIES: "../categories.yaml"
ci_cd:
name: ${{ inputs.step }} ${{ inputs.sdk }} ${{ inputs.origin }}
needs: [ check_has_examples ]
if: needs.check_has_examples.outputs.example_has_changed == 'True'
runs-on: ubuntu-latest
env:
ORIGIN: ${{ inputs.origin }}
SDK: ${{ inputs.sdk }}
STEP: ${{ inputs.step }}
SUBDIRS: ${{ inputs.subdirs }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- uses: actions/setup-java@v3.8.0
with:
distribution: 'zulu'
java-version: '11'
- name: install deps
run: pip install -r requirements.txt
working-directory: playground/infrastructure
- name: Remove default github maven configuration
# This step is a workaround to avoid a decryption issue
run: rm ~/.m2/settings.xml
- name: Set Docker Tag
run: echo "DOCKERTAG=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Set Docker Tag If Github Tag was trigger
run: echo "DOCKERTAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/')
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
cache-read-only: false
- name: Build an SDK runner base image and set SDK_TAG if needed
run: |
set -uex
# TODO make this a part of playground:backend:containers:python:docker task
if [ "$SDK" == "python" ]; then
# builds apache/beam_python3.10_sdk:$DOCKERTAG image
./gradlew -i :sdks:python:container:py310:docker -Pdocker-tag="$DOCKERTAG" -Pdocker-pull-licenses=true
# and set SDK_TAG to DOCKERTAG so that the next step would find it
echo "SDK_TAG=${DOCKERTAG}" >> $GITHUB_ENV
fi
- name: Build SDK Backend Docker image
run: |
set -ex
opts=" -Pdocker-tag=$DOCKERTAG"
if [ -n "$SDK_TAG" ]; then
opts="$opts -Psdk-tag=$SDK_TAG"
fi
if [ "$SDK" == "java" ]; then
# Java uses a fixed BEAM_VERSION
opts="$opts -Psdk-tag=$BEAM_VERSION"
fi
# by default (w/o -Psdk-tag) runner uses BEAM from local ./sdks
# TODO Java SDK doesn't, it uses 2.44.0, fix this
./gradlew -i playground:backend:containers:$SDK:docker $opts
- name: Set docker image
run: echo "IMAGE_TAG=apache/beam_playground-backend-$SDK:$DOCKERTAG" >> $GITHUB_ENV
- name: Start SDK runner in background
run: |
set -uex
NAME=$(docker run -d --rm -p 8080:8080 -e PROTOCOL_TYPE=TCP $IMAGE_TAG)
echo "NAME=$NAME" >> $GITHUB_ENV
- name: Run ci_cd.py
run: |
python3 ci_cd.py \
--step $STEP \
--sdk SDK_${SDK^^} \
--origin $ORIGIN \
--subdirs $SUBDIRS
working-directory: playground/infrastructure
env:
BEAM_ROOT_DIR: "../../"
SDK_CONFIG: "../../playground/sdks.yaml"
BEAM_EXAMPLE_CATEGORIES: "../categories.yaml"
SERVER_ADDRESS: localhost:8080
BEAM_CONCURRENCY: 4
- name: Get SDK runner logs
if: ${{ always() }}
run: |
[ -n "$NAME" ] && docker logs $NAME
- name: Stop/remove SDK runner
if: ${{ always() }}
run: |
[ -n "$NAME" ] && docker rm -f $NAME
- name: Delete Docker image
if: ${{ always() }}
run: |
docker image rm -f $IMAGE_TAG