Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

CI

CI #440

Workflow file for this run

name: CI
on:
push: {branches: [main], tags: ['v**']}
pull_request_target: {paths: ['*-*/**']}
schedule: [{cron: '0 11 * * 6'}] # M H d m w (Sat 11:00)
jobs:
setup:
environment: ${{ github.event_name == 'pull_request_target' && ! contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association) && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- id: list
name: List modified models
run: |
if test "${{ github.event_name }}" = schedule; then
echo "debug: collecting all models"
MODELS=$(ls -d *-* | sort | jq -Rsc 'split("\n")[:-1]')
else
if [[ "${{ github.event_name }}" == pull_request* ]]; then
git fetch origin --depth=2 "${{ github.base_ref }}"
BASE=FETCH_HEAD
else
BASE=HEAD~1
fi
echo "debug: base: $BASE"
git diff --stat $BASE
echo "debug: collecting changed models"
MODELS=$(
for model in $(ls -d *-*); do
git diff --quiet $BASE -- $model || echo $model
done | sort | jq -Rsc 'split("\n")[:-1]'
)
fi
echo "modified=$MODELS" >> $GITHUB_OUTPUT
echo "debug: collecting binary builds"
echo "modified_aarch64_macos=$(
for model in $(echo "$MODELS" | jq -r .[]); do
test -f $model/build-aarch64-apple-darwin.sh && echo $model || :
done | sort | jq -Rsc 'split("\n")[:-1]'
)" >> $GITHUB_OUTPUT
- name: Launch self-hosted runners
if: steps.list.outputs.modified != '[]'
run: |
curl -sSL -X POST -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/$MACHINE/start
while test $(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .state) != ready; do
sleep 5
done
IP=$(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .publicIpAddress)
echo "$SSH_KEY" > key; chmod 600 key
ssh -o "StrictHostKeyChecking no" -i key paperspace@$IP 'touch "gha-run-${{ github.run_id }}.lock"'
env:
SSH_KEY: ${{ secrets.PAPERSPACE_SSH_KEY }}
API_KEY: ${{ secrets.PAPERSPACE_API_KEY }}
MACHINE: ${{ secrets.PAPERSPACE_MACHINE }}
outputs:
models: ${{ steps.list.outputs.modified }}
models_macos-latest-xlarge: ${{ steps.list.outputs.modified_aarch64_macos }}
docker-build-test-push:
concurrency: # terminate on new commits to PRs
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ matrix.model }}
cancel-in-progress: true
needs: setup
runs-on: [self-hosted, gpu]
strategy:
fail-fast: false
matrix:
model: ${{ fromJson(needs.setup.outputs.models) }}
# if nothing to do, skip without failing
if: needs.setup.outputs.models != '[]'
env:
VERSION: '1.0.0'
DOCKER_BUILDKIT: 1
DOCKER_CLI_EXPERIMENTAL: enabled
COMPOSE_DOCKER_CLI_BUILD: 1
permissions:
packages: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- run: ./build.sh ${{ github.event_name == 'push' && '--push' || '--load' }}
working-directory: ${{ matrix.model }}
env:
# can't load cross-CPU-platform
BUILDX_PLATFORM: ${{ github.event_name == 'push' && 'linux/arm64,linux/amd64' || 'linux/amd64' }}
# can't test cross-CPU-platform
TESTS_SKIP_CPU: ${{ github.event_name == 'push' && '1' || '' }}
# avoid OoM errors (TODO: remove when using larger GPU)
TESTS_SKIP_GPU: ${{ contains(fromJSON('["a2t-whisper","cht-dolly-v2","cht-gorilla","cht-llama-v2","cht-mpt","cht-xgen","dfs-dalle","dfs-diffusers"]'), matrix.model) && '1' || '' }}
macos-aarch64-build-release:
concurrency: # terminate on new commits to PRs
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ matrix.model }}-bin
cancel-in-progress: true
needs: setup
runs-on: macos-latest-xlarge
strategy:
fail-fast: false
matrix:
model: ${{ fromJson(needs.setup.outputs.models_macos-latest-xlarge) }}
# if nothing to do, skip without failing
if: needs.setup.outputs.models_macos-latest-xlarge != '[]'
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- uses: actions/setup-python@v4
with: {python-version: 3.11}
- id: dist
name: build
run: ./build-aarch64-apple-darwin.sh
working-directory: ${{ matrix.model }}
- uses: actions/upload-artifact@v3
with:
path: ${{ matrix.model }}/dist/*
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
name: Update release assets
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release upload --clobber "${tag%%.*}" ${{ matrix.model }}/dist/*
env:
GH_TOKEN: ${{ github.token }}
pass: # convenient single job to apply branch protection to
needs: [docker-build-test-push, macos-aarch64-build-release]
runs-on: ubuntu-latest
steps:
- run: echo success
teardown:
environment: ${{ github.event_name == 'pull_request_target' && ! contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association) && 'external' || 'internal' }}
needs: docker-build-test-push
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Stop self-hosted runners
run: |
IP=$(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .publicIpAddress)
echo "$SSH_KEY" > key; chmod 600 key
ssh -o "StrictHostKeyChecking no" -i key paperspace@$IP \
'rm -f "gha-run-${{ github.run_id }}.lock"; sleep 10; ls gha-run-*.lock' || \
curl -sSL -X POST -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/$MACHINE/stop
env:
SSH_KEY: ${{ secrets.PAPERSPACE_SSH_KEY }}
API_KEY: ${{ secrets.PAPERSPACE_API_KEY }}
MACHINE: ${{ secrets.PAPERSPACE_MACHINE }}