Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply integration and release workflows #505

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/actions/detect-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Detect Versions
description: Detect truss versions
outputs:
version_changed:
description: Did the version change
value: ${{ steps.versions.outputs.version_changed }}
new_version:
description: Value of new version
value: ${{ steps.versions.outputs.new_version }}
new_base_image_version:
description: new base image version
value: ${{ steps.versions.outputs.new_base_image_version }}
build_base_images:
description: should build base images
value: ${{ steps.versions.outputs.build_base_images }}
release_version:
description: should release version
value: ${{ steps.versions.outputs.release_version }}
is_prerelease_version:
description: is it a prerelease version
value: ${{ steps.versions.outputs.is_prerelease_version }}
runs:
using: "composite"
steps:
- run: curl -sSL https://install.python-poetry.org | python3 -
shell: bash
- id: versions
shell: bash
run: |
NEW_VERSION=$(poetry version | awk '{print $2}')
NEW_BASE_IMAGE_VERSION=$(grep TRUSS_BASE_IMAGE_VERSION_TAG truss/contexts/image_builder/util.py | cut -d'=' -f2 | cut -d'"' -f2)

git checkout HEAD^1 -- pyproject.toml truss/contexts/image_builder/util.py
OLD_VERSION=$(poetry version | awk '{print $2}')
OLD_BASE_IMAGE_VERSION=$(grep TRUSS_BASE_IMAGE_VERSION_TAG truss/contexts/image_builder/util.py | cut -d'=' -f2 | cut -d'"' -f2)

# Put back things into place
git checkout HEAD -- pyproject.toml truss/contexts/image_builder/util.py

echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "new_base_image_version=$NEW_BASE_IMAGE_VERSION" >> $GITHUB_OUTPUT

if [[ "$NEW_VERSION" != "$OLD_VERSION" ]]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
if [[ "$NEW_VERSION" == *"dev"* ]]; then
echo "release_version=false" >> $GITHUB_OUTPUT
else
echo "release_version=true" >> $GITHUB_OUTPUT
if [[ "$NEW_VERSION" == *"rc"* ]]; then
echo "is_prerelease_version=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease_version=false" >> $GITHUB_OUTPUT
fi
fi
else
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

if [[ "$NEW_BASE_IMAGE_VERSION" != "$OLD_BASE_IMAGE_VERSION" ]]; then
echo "build_base_images=true" >> $GITHUB_OUTPUT
else
echo "build_base_images=false" >> $GITHUB_OUTPUT
fi
56 changes: 52 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,64 @@ concurrency:
cancel-in-progress: false

jobs:
integration_tests:
detect-version-changed:
runs-on: ubuntu-20.04
outputs:
version_changed: ${{ steps.versions.outputs.version_changed }}
new_version: ${{ steps.versions.outputs.new_version }}
new_base_image_version: ${{ steps.versions.outputs.new_base_image_version }}
build_base_images: ${{ steps.versions.outputs.build_base_images }}
release_version: ${{ steps.versions.outputs.release_version }}
is_prerelease_version: ${{ steps.versions.outputs.is_prerelease_version }}
steps:
- uses: actions/checkout@v3
with:
# We need to use a different github token because GITHUB_TOKEN cannot trigger a workflow from another
token: ${{secrets.BASETENBOT_GITHUB_TOKEN}}
fetch-depth: 2
- uses: ./.github/actions/detect-versions/
id: versions
build-and-push-truss-base-images-if-needed:
needs: [detect-version-changed]
if: needs.detect-version-changed.outputs.build_base_images == 'true'
runs-on: ubuntu-20.04
strategy:
matrix:
python_version: ["3.8", "3.9", "3.10", "3.11"]
use_gpu: ["y", "n"]
job_type: ["server", "training"]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python/
- run: poetry install
- shell: bash
run: |
poetry run bin/generate_base_images.py \
--use-gpu ${{ matrix.use_gpu }} \
--python-version ${{ matrix.python_version }} \
--job-type ${{ matrix.job_type }} \
--version-tag ${{ needs.detect-version-changed.outputs.new_base_image_version }} \
--skip-login --push

integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
split_group: ["1", "2", "3", "4", "5"]
steps:
- uses: actions/checkout@v3
with:
lfs: true
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss/tests -m 'integration' --splits 5 --group ${{ matrix.split_group }}
- run: poetry run pytest truss/tests -m 'integration' --splits 5 --group ${{ matrix.split_group }}
102 changes: 11 additions & 91 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,97 +20,17 @@ jobs:
release_version: ${{ steps.versions.outputs.release_version }}
is_prerelease_version: ${{ steps.versions.outputs.is_prerelease_version }}
steps:
- uses: actions/checkout@v3
with:
# We need to use a different github token because GITHUB_TOKEN cannot trigger a workflow from another
token: ${{secrets.BASETENBOT_GITHUB_TOKEN}}
fetch-depth: 2
- run: curl -sSL https://install.python-poetry.org | python3 -
shell: bash
- id: versions
run: |
NEW_VERSION=$(poetry version | awk '{print $2}')
NEW_BASE_IMAGE_VERSION=$(grep TRUSS_BASE_IMAGE_VERSION_TAG truss/contexts/image_builder/util.py | cut -d'=' -f2 | cut -d'"' -f2)

git checkout HEAD^1 -- pyproject.toml truss/contexts/image_builder/util.py
OLD_VERSION=$(poetry version | awk '{print $2}')
OLD_BASE_IMAGE_VERSION=$(grep TRUSS_BASE_IMAGE_VERSION_TAG truss/contexts/image_builder/util.py | cut -d'=' -f2 | cut -d'"' -f2)

# Put back things into place
git checkout HEAD -- pyproject.toml truss/contexts/image_builder/util.py

echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "new_base_image_version=$NEW_BASE_IMAGE_VERSION" >> $GITHUB_OUTPUT

if [[ "$NEW_VERSION" != "$OLD_VERSION" ]]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
if [[ "$NEW_VERSION" == *"dev"* ]]; then
echo "release_version=false" >> $GITHUB_OUTPUT
else
echo "release_version=true" >> $GITHUB_OUTPUT
if [[ "$NEW_VERSION" == *"rc"* ]]; then
echo "is_prerelease_version=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease_version=false" >> $GITHUB_OUTPUT
fi
fi
else
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

if [[ "$NEW_BASE_IMAGE_VERSION" != "$OLD_BASE_IMAGE_VERSION" ]]; then
echo "build_base_images=true" >> $GITHUB_OUTPUT
else
echo "build_base_images=false" >> $GITHUB_OUTPUT
fi
build-and-push-truss-base-images-if-needed:
needs: [detect-version-changed]
if: needs.detect-version-changed.outputs.build_base_images == 'true'
runs-on: ubuntu-20.04
strategy:
matrix:
python_version: ["3.8", "3.9", "3.10", "3.11"]
use_gpu: ["y", "n"]
job_type: ["server", "training"]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python/
- run: poetry install
- shell: bash
run: |
poetry run bin/generate_base_images.py \
--use-gpu ${{ matrix.use_gpu }} \
--python-version ${{ matrix.python_version }} \
--job-type ${{ matrix.job_type }} \
--version-tag ${{ needs.detect-version-changed.outputs.new_base_image_version }} \
--skip-login --push

integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
split_group: ["1", "2", "3", "4", "5"]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss/tests -m 'integration' --splits 5 --group ${{ matrix.split_group }}
- uses: actions/checkout@v3
with:
# We need to use a different github token because GITHUB_TOKEN cannot trigger a workflow from another
token: ${{secrets.BASETENBOT_GITHUB_TOKEN}}
fetch-depth: 2
- uses: ./.github/actions/detect-versions/
id: versions

build-n-push-context-builder-image:
needs: [integration-tests, detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' && (needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped') }}
needs: [detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -141,8 +61,8 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

publish-to-pypi:
needs: [integration-tests, detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' && (needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped') }}
needs: [detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' }}
runs-on: ubuntu-20.04
steps:
- name: "Git tag release"
Expand Down