Skip to content

Commit

Permalink
Change build-pipeline to use Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanRubin committed Jul 21, 2024
1 parent 80d7b6c commit 0741305
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 161 deletions.
55 changes: 21 additions & 34 deletions .github/workflows/build-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
# Based on https://github.com/ml-tooling/universal-build/blob/v0.6.18/workflows/build-pipeline.yml
name: build-pipeline
# This workflow will install dependencies, build st-pydantic, run tests (+coverage) and lint

name: build

on:
workflow_dispatch:
inputs:
build_args:
description: "Arguments passed to build script"
required: false
working_directory:
description: "Working directory from where the build command is run"
required: false
push:
pull_request:
workflow_dispatch:

env:
BUILD_ARGS: ${{ secrets.BUILD_ARGS }}
WORKING_DIRECTORY: ${{ secrets.WORKING_DIRECTORY }}

jobs:
build:
runs-on: ubuntu-latest
run_image:
runs-on: [ubuntu-latest]
container:
image: matanrubin/python-poetry:3.10-1.6.1
steps:
- name: set-input-build-args
if: ${{ github.event.inputs != null && github.event.inputs.build_args != null}}
run: echo "BUILD_ARGS=${{ github.event.inputs.build_args }}" >> $GITHUB_ENV
# new syntax: run: echo "BUILD_ARGS=${{ github.event.inputs.build_args }}" >> "$GITHUB_ENV"
- name: set-input-working-directory
if: ${{ github.event.inputs != null && github.event.inputs.working_directory != null}}
run: echo "WORKING_DIRECTORY=${{ github.event.inputs.working_directory }}" >> $GITHUB_ENV
# new syntax: run: echo "WORKING_DIRECTORY=${{ github.event.inputs.working_directory }}" >> "$GITHUB_ENV"
# Set host ip to env variable to be uside within container actions
- name: set-host-ip
run: echo "_HOST_IP=$(hostname -I | cut -d ' ' -f 1)" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: run-build-scripts
uses: ./.github/actions/build-environment
with:
build_args: ${{ env.BUILD_ARGS }}
working_directory: ${{ env.WORKING_DIRECTORY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- run: make bootstrap
- run: poetry build -vvv
- run: make coverage
- run: make check
- run: make coverage

# Upload coverage files to codecov
# - uses: actions/upload-artifact@v2
# with:
# name: htmlcov.zip
# path: htmlcov/
# - uses: codecov/codecov-action@v1
142 changes: 15 additions & 127 deletions .github/workflows/release-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,132 +1,20 @@
# Based on https://github.com/ml-tooling/universal-build/blob/v0.6.18/workflows/build-pipeline.yml
name: release-pipeline
# This workflow will build st-pydantic, and publish it to pypi.org

on:
workflow_dispatch:
inputs:
version:
description: "Version of this release"
required: true
milestone:
types: [closed]
name: publish

env:
VERSION: ${{ secrets.VERSION }}
BRANCH_PREFIX: "release/v"
DEFAULT_BRANCH: main
on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
run_image:
runs-on: [ubuntu-latest]
container:
image: matanrubin/python-poetry:3.10-1.6.1

steps:
- if: ${{ github.event.milestone != null && github.event.milestone.title != null }}
name: set-milestone-version
run: |
echo "VERSION=$(sed "s/^v//" <<< "${{ github.event.milestone.title }}")" >> $GITHUB_ENV
echo "PR_MILESTONE_LINK=-M ${{ github.event.milestone.title }}" >> $GITHUB_ENV
- if: ${{ github.event.inputs != null && github.event.inputs.version != null }}
name: set-input-version
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: check-version
run: 'if [[ ! "${{ env.VERSION }}" =~ ^([0-9]+\.[0-9]+\.[0-9]+.*)$ ]]; then echo "The version is not valid: ${{ env.VERSION }}"; exit 1; fi'
- name: set-github-token
run: echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
# Set host ip to env variable to be uside within container actions
- name: set-host-ip
run: echo "_HOST_IP=$(hostname -I | cut -d ' ' -f 1)" >> $GITHUB_ENV
# Fix git version for act if github token is provided
- if: ${{ env.GITHUB_ACTOR == 'nektos/act' && env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: install-latest-git
run: |
# Required for local checkout
apt-get update
apt-get install -y git
- if: ${{ env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: create-release-branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "${{ env.BRANCH_PREFIX }}${{ env.VERSION }}"
- if: ${{ ! (env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '') }}
uses: actions/checkout@v2
- if: ${{ env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ env.BRANCH_PREFIX }}${{ env.VERSION }}
token: ${{ env.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: run-component-builds
uses: ./.github/actions/build-environment
with:
build_args: --make --force --version=${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: run-linting-and-style-checks
uses: ./.github/actions/build-environment
with:
build_args: --check --force --version=${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: run-component-tests
uses: ./.github/actions/build-environment
with:
build_args: --test --force --test-marker=slow --version=${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: release-components
uses: ./.github/actions/build-environment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
PYPI_REPOSITORY: ${{ secrets.PYPI_REPOSITORY }}
with:
build_args: --release --force --version=${{ env.VERSION }}
container_registry_url: ${{ secrets.CONTAINER_REGISTRY_URL }}
container_registry_username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
container_registry_password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- if: ${{ env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: push-changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ env.BRANCH_PREFIX }}${{ env.VERSION }}
commit_user_name: Release Bot
commit_user_email: [email protected]
commit_message: Apply automatic release changes for v${{ env.VERSION }}
tagging_message: v${{ env.VERSION }}
skip_dirty_check: true
commit_options: "--allow-empty"
- if: ${{ env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: create-pull-request
shell: bash
run: |
# Stops script execution if a command has an error
set -e
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.2
# TODO: Milestone link currently does not work with closed milestones: ${{ env.PR_MILESTONE_LINK }} (problem with hub cli)
bin/hub pull-request -b ${{ env.DEFAULT_BRANCH }} -h ${{ env.BRANCH_PREFIX }}${{ env.VERSION }} --no-edit -m "Finalize release for version ${{ env.VERSION }}" -m "Automated pull request for release version ${{ env.VERSION }}" -l "skip changelog" || true
rm bin/hub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Fix of release drafter to allow different events to trigger the release
# TODO: currently does not work with act
- if: ${{ env.GITHUB_ACTOR == 'nektos/act' && env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: no-relese-drafter-support
run: echo "The release drafter currently does not work with act, please create the release from the Github UI."
- if: ${{ env.GITHUB_ACTOR != 'nektos/act' && env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: checkout-fixed-release-drafter
uses: actions/checkout@v2
with:
repository: ml-tooling/release-drafter
path: ./.git/cloned-actions/release-drafter
- if: ${{ env.GITHUB_ACTOR != 'nektos/act' && env.GITHUB_TOKEN != null && env.GITHUB_TOKEN != '' }}
name: create-release-draft
uses: ./.git/cloned-actions/release-drafter
with:
version: ${{ env.VERSION }}
tag: v${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optional: upload release assets via actions/upload-release-asset@v1 and via upload_url from release drafter
- uses: actions/checkout@v4
- run: make bootstrap
- run: poetry update -vvv
- run: poetry build -vvv
- run: poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}

0 comments on commit 0741305

Please sign in to comment.