This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
ci: machine start fix #242
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: {branches: [main]} | |
pull_request_target: | |
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: 0 | |
- id: list | |
name: List modified models | |
run: | | |
git diff --stat HEAD~1 | |
echo "modified=$( | |
for model in $(ls -d *-*); do | |
git diff --quiet HEAD~1 -- $model || echo $model | |
done | sort | jq -Rsc 'split("\n")[:-1]' | |
)" >> $GITHUB_OUTPUT | |
- name: Launch self-hosted runners | |
if: steps.list.outputs.modified != 'modified=[]' | |
run: | | |
echo starting | |
curl -sSL -X POST -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/$MACHINE/start | |
echo started | |
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 | |
echo sleeping | |
sleep 5 | |
done | |
echo ready | |
IP=$(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE_ID | jq -r .publicIpAddress) | |
echo $IP | |
echo "$SSH_KEY" > 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 }} | |
build-test-push: | |
concurrency: # terminate on new commits to PRs | |
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
needs: setup | |
runs-on: [self-hosted, gpu] | |
strategy: | |
fail-fast: false # TODO: remove | |
matrix: | |
model: ${{ fromJson(needs.setup.outputs.models) }} | |
env: | |
VERSION: '1.0.0' | |
DOCKER_BUILDKIT: 1 | |
DOCKER_CLI_EXPERIMENTAL: enabled | |
COMPOSE_DOCKER_CLI_BUILD: 1 | |
steps: | |
- uses: actions/checkout@v3 | |
- 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' || '' }} | |
pass: # convenient single job to apply branch protection to | |
needs: build-test-push | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo success | |
teardown: | |
needs: 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_ID | jq -r .publicIpAddress) | |
echo "$SSH_KEY" > 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 }} |