Skip to content

Branch Build (1.120) - main #120

Branch Build (1.120) - main

Branch Build (1.120) - main #120

Workflow file for this run

name: Build
run-name: "Branch Build (${{ github.run_attempt }}.${{ github.run_number }}) - ${{ github.ref_name }}"
on:
pull_request:
branches:
- "main"
workflow_dispatch:
inputs:
howso-engine-version:
description: The version of howso-engine-py to use for the build
required: true
type: string
build-type:
description: If you are not a bot, you do not need to change this input
required: false
type: string
defaults:
run:
shell: bash
env:
REGISTRY: ghcr.io
IMAGE_NAME: howsoai/howso
jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
strategy:
matrix:
python-ver: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up QEMU
if: inputs.build-type == 'release'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: inputs.build-type == 'release'
id: buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
if: inputs.build-type == 'release'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ inputs.howso-engine-version }}-python${{ matrix.python-ver }}
type=raw,value=python${{ matrix.python-ver }}
type=raw,value=latest,enable=${{ matrix.python-ver == '3.11' }}
- name: Login to container registry
if: inputs.build-type == 'release'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Get latest howso-engine-py version
if: inputs.build-type != 'release'
id: get-hse-py-version
run: |
latest=$(pip index versions howso-engine | grep -oP '(\d+\.)?(\d+\.)?(\*|\d+)' | sort -V | tail -n1)
echo "latest_version=$latest" >> $GITHUB_OUTPUT
- name: Build Docker Image (no push)
if: inputs.build-type != 'release'
uses: docker/build-push-action@v5
with:
context: .
build-args: |
PY_VERSION=${{ matrix.python-ver }}
HOWSO_ENGINE_VERSION=${{ steps.get-hse-py-version.outputs.latest_version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Wait for PyPi
if: inputs.build-type == 'release'
run: |
# When this workflow is triggered automatically by howso-engine-py releases,
# it sometimes tries to pull in the new howso-engine from PyPi before it is available.
sleep 30
- name: Build & Push Docker image
if: inputs.build-type == 'release'
uses: docker/build-push-action@v5
with:
context: .
build-args: |
PY_VERSION=${{ matrix.python-ver }}
HOWSO_ENGINE_VERSION=${{ inputs.howso-engine-version }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.title=Howso Dev Container for Python ${{ matrix.python-ver }},annotation.org.opencontainers.image.authors=Howso <support@howso.com>,annotation.org.opencontainers.image.licenses=AGPL-3.0-or-later,annotation.org.opencontainers.image.description=Containerized environment for using Howso Engine from VSCode,annotation.org.opencontainers.image.source=https://github.com/howsoai/howso-devcontainers
gen-branch-name:
if: inputs.build-type == 'release'
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
branch: ${{ steps.gen-branch-name.outputs.branch }}
steps:
- name: Generate branch name
id: gen-branch-name
run: |
NOW=$(date +'%Y-%m-%dT%Hh%Mm%Ss')
BRANCH="update-devcontainers-$NOW"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
create-branch:
if: inputs.build-type == 'release'
needs: ['build', 'gen-branch-name']
uses: "howsoai/.github/.github/workflows/create-branch.yml@main"
secrets: inherit
with:
branch: ${{ needs.gen-branch-name.outputs.branch }}
repo: 'howsoai/howso-engine-recipes'
update-engine-recipes:
if: inputs.build-type == 'release'
needs: ['build', 'gen-branch-name', 'create-branch']
runs-on: ubuntu-latest
permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.HOWSOAI_WORKFLOW_AUTOMATION_TOKEN }}
ref: ${{ needs.gen-branch-name.outputs.branch }}
repository: 'howsoai/howso-engine-recipes'
- name: Update devcontainer files
run: |
# Remove all existing .devcontainer files and subdirectories
rm -rf .devcontainer
mkdir .devcontainer
ENGINE_VERSION="${{ inputs.howso-engine-version }}"
declare -a arr=("3.9" "3.10" "3.11" "3.12")
for PY_VERSION in "${arr[@]}"; do
echo "Setting up .devcontainer for Python$PY_VERSION"
mkdir .devcontainer/$ENGINE_VERSION-python$PY_VERSION
cp .github/templates/devcontainer.json .devcontainer/$ENGINE_VERSION-python$PY_VERSION/devcontainer.json
sed -i "s|{HOWSO_ENGINE_VERSION}|$ENGINE_VERSION|g" .devcontainer/$ENGINE_VERSION-python$PY_VERSION/devcontainer.json
sed -i "s|{PYTHON_VERSION}|$PY_VERSION|g" .devcontainer/$ENGINE_VERSION-python$PY_VERSION/devcontainer.json
# If the current Python version is 3.11, also set it as the default devcontainer file
if [[ "$PY_VERSION" == "3.11" ]]; then
cp .devcontainer/$ENGINE_VERSION-python$PY_VERSION/devcontainer.json .devcontainer/devcontainer.json
fi
done
- name: Commit and push changes
run: |
git pull
if [ -n "$(git status --porcelain)" ]; then
git config user.name "howso-automation"
git config user.email "support@howso.com"
git add --all :/
git commit -m "Automated update to .devcontainer"
git push
else
echo "No changes detected in the repository."
exit 1
fi
create-pr:
if: inputs.build-type == 'release'
needs: ['gen-branch-name', 'update-engine-recipes']
uses: "howsoai/.github/.github/workflows/create-pr.yml@main"
secrets: inherit
permissions:
contents: write
pull-requests: write
with:
branch: ${{ needs.gen-branch-name.outputs.branch }}
repo: 'howsoai/howso-engine-recipes'
title: 'Automated update to .devcontainer'
body: 'This action was performed by a bot. Please review carefully.'
release:
if: inputs.build-type == 'release'
needs: ['create-pr', 'build']
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: ${{ inputs.howso-engine-version }} # The .devcontainers version should be tied to the howso-engine version
commit: ${{ github.sha }}
name: "Howso Dev Containers ${{ inputs.howso-engine-version }}"
artifactErrorsFailBuild: true
generateReleaseNotes: true
makeLatest: legacy
# This job is here to have only one final step to add for "Status Checks"
# in GitHub, instead of adding every leaf test from 'build-test-package'
final-check:
needs: ['build']
if: always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled'))
runs-on: ubuntu-latest
steps:
- run: exit 1