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

Automate publishing various artifacts on project version change #206

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
95 changes: 85 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,106 @@ jobs:
lfs: true
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss/tests -m 'integration'
- run: poetry run pytest truss/tests -m 'integration'

trigger_release_if_version_changed:
git_tag_if_version_changed:
needs: [integration_tests]
runs-on: ubuntu-20.04
outputs:
version_changed: ${{ steps.versions.outputs.version_changed }}
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}}
lfs: true
fetch-depth: 2
- uses: ./.github/actions/setup-python/
- run: curl -sSL https://install.python-poetry.org | python3 -
shell: bash
- id: versions
run: |
NEW_VERSION=$(poetry version)
echo "::set-output name=new-version::$NEW_VERSION\n"
NEW_VERSION=$(poetry version | awk '{print $2}')

git checkout HEAD^1 -- pyproject.toml
OLD_VERSION=$(poetry version)
echo "::set-output name=old-version::$OLD_VERSION\n"
OLD_VERSION=$(poetry version | awk '{print $2}')

# Put back things into place
git checkout HEAD -- pyproject.toml
- if: steps.versions.old-version != steps.versions.new-version

echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT

if [[ "$NEW_VERSION" != "$OLD_VERSION" ]]; then
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

- if: steps.versions.outputs.version_changed == 'true'
run: |
git tag -a v${{ steps.versions.new-version }} -m "Release v${{ steps.versions.new-version }}"
git push origin v${{ steps.versions.new-version }}
NEW_VERSION=v${{ steps.versions.outputs.new_version }}
git config --global user.name "Github action"
git config --global user.email "github.action@baseten.co"

git tag -a $NEW_VERSION -m "Release $NEW_VERSION"
git push origin $NEW_VERSION

build-n-push-image:
needs: [git_tag_if_version_changed]
if: needs.git_tag_if_version_changed.outputs.version_changed == 'true'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- run: curl -sSL https://install.python-poetry.org | python3 -
shell: bash

- 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 }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: baseten/truss-context-builder

- name: Prep version
id: prep_version
run: |
version=$(poetry version | awk '{print $2}')
echo ::set-output name=version::$version

- name: Docker Build
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./context_builder.Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: baseten/truss-context-builder:v${{steps.prep_version.outputs.version}}dev11
labels: ${{ steps.meta.outputs.labels }}

publish-to-pypi:
needs: [git_tag_if_version_changed]
if: needs.git_tag_if_version_changed.outputs.version_changed == 'true'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-python/

- name: Install poetry packages
run: poetry install --no-dev

- name: Build
run: poetry build

- name: Publish to PyPI
if: ${{ github.event_name != 'pull_request' }}
run: poetry publish -u "${{ secrets.PYPI_USERNAME }}" -p "${{ secrets.PYPI_PASSWORD }}"
69 changes: 0 additions & 69 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "truss"
version = "0.3.2"
version = "0.3.3rc1"
description = "A seamless bridge from model development to model delivery"
license = "MIT"
readme = "README.md"
Expand Down