-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ci for testing integration builds
- Loading branch information
1 parent
25c269d
commit 83ff254
Showing
3 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
prepare-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.prepare-matrix.outputs.INTEGRATIONS_MATRIX }} | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ secrets.DOCKER_MACHINE_USER }} | ||
password: ${{ secrets.DOCKER_MACHINE_TOKEN }} | ||
- name: Prepare matrix | ||
id: prepare-matrix | ||
run: | | ||
integrations_to_release=() | ||
# Get the list of integrations | ||
files=$(find integrations/*/.port -name "spec.yaml") | ||
for file in $files; do | ||
folder=$(dirname "$file") | ||
type=$(grep -E '^name = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2) | ||
# Get the version from pyproject.toml | ||
version=$(grep -E '^version = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2) | ||
# Check if the version exists in the ghcr.io registry | ||
rc=0 | ||
docker manifest inspect ghcr.io/port-labs/port-ocean-$type:$version > /dev/null 2>&1 || rc=$? | ||
if [ $rc -eq 0 ]; then | ||
echo "Image already exists in $repository: port-ocean-$type:$version" | ||
else | ||
integrations_to_release+=($file) | ||
fi | ||
done | ||
echo $(echo ${integrations_to_release[@]} | jq -R -c 'split(" ")') | ||
echo "INTEGRATIONS_MATRIX=$(echo ${integrations_to_release[@]} | jq -R -c 'split(" ")')" >> $GITHUB_OUTPUT | ||
build-integration: | ||
runs-on: ubuntu-latest | ||
if: needs.prepare-matrix.outputs.matrix != '[]' | ||
outputs: | ||
is_dev_version: ${{ steps.prepare_tags.outputs.is_dev_version }} | ||
permissions: | ||
contents: read | ||
needs: [prepare-matrix] | ||
strategy: | ||
matrix: | ||
integration: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ secrets.DOCKER_MACHINE_USER }} | ||
password: ${{ secrets.DOCKER_MACHINE_TOKEN }} | ||
- name: Prepare Docker images tags | ||
id: prepare_tags | ||
run: | | ||
current_integration_spec=${{ matrix.integration }} | ||
folder=$(dirname "$current_integration_spec") | ||
context_dir=$(dirname "$folder") | ||
echo "context_dir=$context_dir" >> $GITHUB_OUTPUT | ||
version=$(grep -E '^version = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2) | ||
type=$(grep -E '^name = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2) | ||
echo "version=$version" >> $GITHUB_OUTPUT | ||
dockerfile_path=integrations/_infra/Dockerfile | ||
if test -e $folder/../Dockerfile; then | ||
dockerfile_path=$folder/../Dockerfile | ||
fi | ||
echo "dockerfile_path=$dockerfile_path" >> $GITHUB_OUTPUT | ||
# Check if the 'version' variable contains any character other than digits and "." | ||
if [[ ! "$version" =~ ^[0-9.]+$ ]]; then | ||
# If 'version' contains non-numeric and non-dot characters, skip building 'latest' tag | ||
tags="ghcr.io/port-labs/port-ocean-$type:$version" | ||
echo "tags=$tags" >> $GITHUB_OUTPUT | ||
echo "is_dev_version=true" >> $GITHUB_OUTPUT | ||
echo "Version contains non-numeric characters. Building without 'latest' tag." | ||
else | ||
# If 'version' contains only digits and dots, build with both 'latest' and version tags | ||
tags="ghcr.io/port-labs/port-ocean-$type:$version,ghcr.io/port-labs/port-ocean-$type:latest" | ||
echo "tags=$tags" >> $GITHUB_OUTPUT | ||
echo "is_dev_version=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Build | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ${{ steps.prepare_tags.outputs.dockerfile_path }} | ||
platforms: linux/amd64,linux/arm64 | ||
push: false | ||
tags: ${{ steps.prepare_tags.outputs.tags }} | ||
build-args: | | ||
BUILD_CONTEXT=${{ steps.prepare_tags.outputs.context_dir }} | ||
INTEGRATION_VERSION=${{ steps.prepare_tags.outputs.version }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Apply release | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
create_branch_and_open_pr: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
|
||
- name: Upgrade integrations | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
./scripts/upgrade-integrations.sh | ||
- name: Open pull request | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.MACHINE_USER_TOKEN }} | ||
title: ${{ steps.version.outputs.pr_name }} | ||
branch: ${{ steps.version.outputs.branch_name }} | ||
base: main | ||
body: | | ||
This PR was automatically created by a GitHub Action. | ||
## What does this PR do? | ||
Upgrade dependencies for all integrations | ||
## How should this be manually tested? | ||
./scripts/upgrade-integrations.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
# Loop through each folder in the 'integrations' directory | ||
for folder in "$(pwd)"/integrations/*; do | ||
if [ -d "$folder" ]; then | ||
if [ ! -f "$folder"/pyproject.toml ]; then | ||
continue | ||
fi | ||
|
||
echo "============================" | ||
echo "Upgrading integration $folder" | ||
echo "============================" | ||
|
||
( | ||
cd "$folder" || exit | ||
|
||
echo "Run 'make install'" | ||
(cd "$folder" && make install) | ||
|
||
|
||
# Activate virtual environment if it exists | ||
if [ -f .venv/bin/activate ]; then | ||
source .venv/bin/activate | ||
else | ||
echo "No virtual environment found in $folder" | ||
continue | ||
fi | ||
|
||
# Upgrade dependencies using Poetry | ||
echo "Running 'poetry update'" | ||
if ! poetry update; then | ||
echo "Failed to update dependencies in $folder" | ||
continue | ||
fi | ||
|
||
# Get current version and increment patch version | ||
current_version=$(poetry version --short) | ||
echo "Current version: $current_version, updating patch version" | ||
|
||
IFS='.' read -ra version_components <<< "$current_version" | ||
major_version="${version_components[0]}" | ||
minor_version="${version_components[1]}" | ||
patch_version="${version_components[2]}" | ||
((patch_version++)) | ||
new_version="$major_version.$minor_version.$patch_version" | ||
|
||
# Update to new version | ||
echo "Set new version: $new_version" | ||
poetry version "$new_version" | ||
|
||
# Create changelog entry | ||
echo "Creating changelog entry with Towncrier" | ||
towncrier create --content "Upgraded integration dependencies" 1.improvement.md | ||
|
||
# Build changelog | ||
echo "Building changelog" | ||
towncrier build --yes --version $new_version | ||
|
||
# Remove temporary changelog file | ||
rm changelog/1.improvement.md | ||
|
||
# Add changes to git and commit | ||
git add . | ||
git commit -m "Upgraded dependencies and bumped version to $new_version for $(basename "$folder")" | ||
|
||
# Deactivate virtual environment | ||
deactivate | ||
) | ||
fi | ||
done |