Skip to content

Integration Test Support #21

Integration Test Support

Integration Test Support #21

name: Flyte Integration Suite
on:
pull_request:
branches:
- main
jobs:
build_images:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.FLYTE_BOT_USERNAME }}
password: ${{ secrets.FLYTE_BOT_PAT }}
- name: Iterate through top level directories and build Docker images
run: |
# Get the SHA of the base commit of the PR
base_sha=${{ github.event.pull_request.base.sha }}
special_tag=build-success-${{github.event.pull_request.number}}
# Get the list of changed files between the last commit and the current one
latest_tag=$(git tag -l 'build-success-${special_tag}' | sort -V | tail -n 1)
if [ -z "$latest_tag" ]; then
echo "no previous successful build tag exists"
# If no previous successful build tag exists, check all commits
changed_files=$(git diff --name-only $base_sha HEAD)
else
# Otherwise, check only the commits since the last successful build
echo "previous successful build tag exists"
changed_files=$(git diff --name-only $latest_tag HEAD)
fi
echo "Changed files: $changed_files"
for dir in *; do
if [ -f "$dir/{{cookiecutter.project_name}}/Dockerfile" ]; then
# Check if any of the changed files are in the current directory
if echo "$changed_files" | grep -q "^$dir/"; then
echo "Building and pushing Docker image for $dir"
docker build -f $dir/{{cookiecutter.project_name}}/Dockerfile -t ghcr.io/${{ github.repository }}:${dir}-pr-${{github.event.pull_request.number}} $dir/{{cookiecutter.project_name}}
docker push ghcr.io/${{ github.repository }}:${dir}-pr-${{github.event.pull_request.number}}
else
echo "Skipping $dir as it does not contain changes"
fi
else
echo "Skipping $dir as it does not contain a Dockerfile"
fi
if [ -z $"latest_tag" ]; then
echo "Deleting last tag and replacing it with this one, since it was successful"
git tag -d $latest_tag
git push origin :refs/tags/$latest_tag
else
echo "No previous successful build tag exists, so no need to delete it"
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag build-success-${{ github.event.pull_request.number }} HEAD
git push origin build-success-${{ github.event.pull_request.number }}
done
integration_tests:
needs: build_images
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Run integration tests
env:
host: ${{ secrets.FLYTE_HOST }}
client_id: ${{ secrets.FLYTE_CLIENT_ID }}
client_secret: ${{ secrets.FLYTE_CLIENT_SECRET }}
run: |
pip install -r requirements.txt
python integration.py --host $host --client_id $client_id --client_secret $client_secret
exit 0
teardown_images:
needs: integration_tests
if: always()
runs-on: ubuntu-latest
steps:
- name: Delete image from ghcr.io
uses: bots-house/ghcr-delete-image-action@v1.1.0
with:
# NOTE: at now only orgs is supported
owner: ${{ github.repository_owner }}
name: ${{ github.repository }}
# NOTE: using Personal Access Token
token: ${{ secrets.FLYTE_BOT_PAT }}
tag: pr-${{ github.event.pull_request.number }}