Skip to content

Commit

Permalink
Refactor start into a reusable workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Jun 6, 2024
1 parent cee7447 commit 6ae3a12
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 59 deletions.
File renamed without changes.
62 changes: 62 additions & 0 deletions .github/workflows/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --python-version 3.9 --python-platform linux --no-build
certifi==2024.6.2
# via requests
cffi==1.16.0
# via cryptography
charset-normalizer==3.3.2
# via requests
cryptography==42.0.8
# via openstacksdk
decorator==5.1.1
# via
# dogpile-cache
# openstacksdk
dogpile-cache==1.3.3
# via openstacksdk
idna==3.7
# via requests
iso8601==2.1.0
# via
# keystoneauth1
# openstacksdk
jmespath==1.0.1
# via openstacksdk
jsonpatch==1.33
# via openstacksdk
jsonpointer==2.4
# via jsonpatch
keystoneauth1==5.6.0
# via openstacksdk
netifaces==0.11.0
# via openstacksdk
openstacksdk==3.1.0
# via -r requirements.in
os-service-types==1.7.0
# via
# keystoneauth1
# openstacksdk
pbr==6.0.0
# via
# keystoneauth1
# openstacksdk
# os-service-types
# stevedore
platformdirs==4.2.2
# via openstacksdk
pycparser==2.22
# via cffi
pyyaml==6.0.1
# via openstacksdk
requests==2.32.3
# via keystoneauth1
requestsexceptions==1.4.0
# via openstacksdk
stevedore==5.2.0
# via
# dogpile-cache
# keystoneauth1
typing-extensions==4.12.1
# via dogpile-cache
urllib3==2.2.1
# via requests
56 changes: 56 additions & 0 deletions .github/workflows/start.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Start

on:
workflow_call:
inputs:
number:
description: 'Number of runners to start.'
required: false
default: -1
type: number

secrets:
OS_APPLICATION_CREDENTIAL_ID:
required: true
OS_APPLICATION_CREDENTIAL_SECRET:
required: true

outputs:
exit_code:
description: "The exit code from start.py"
value: ${{ jobs.action_runners.outputs.exit_code }}

jobs:
action_runners:
name: action runners
runs-on: ubuntu-latest
outputs:
exit_code: ${{ steps.start.outputs.exit_code }}
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
repository: glotzerlab/jetstream2-admin
ref: ${{ github.workflow_sha }}
# Python 3.9 is the latest possible because netifaces has no new releases
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.9"
- name: Install openstack
uses: glotzerlab/workflows/setup-uv@5cfac9da9cb78e16ae97a9119b6fd13c1c2d6f5e # 0.1.0
with:
lockfile: ".github/workflows/requirements.txt"
- id: start
name: Start action runners
continue-on-error: true
run: |
python3 start/start-action-runners.py ${{ inputs.number }} || echo "exit_code=$?" >> $GITHUB_OUTPUT
env:
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
OS_AUTH_TYPE: v3applicationcredential
OS_AUTH_URL: https://js2.jetstream-cloud.org:5000/v3/
OS_IDENTITY_API_VERSION: 3
OS_REGION_NAME: "IU"
OS_INTERFACE: public
19 changes: 0 additions & 19 deletions .github/workflows/start.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
pull_request:

workflow_dispatch:

jobs:
start_workflow:
name: Start
uses: ./.github/workflows/start.yaml
secrets: inherit

check_output:
name: Check output
needs: start_workflow
# runs-on: ubuntu-latest
runs-on: ${{ needs.start_workflow.outputs.exit_code == 3 && 'ubuntu-20.04' || 'ubuntu-24.04' }}

steps:
- run: "echo Exit code: ${{ needs.start_workflow.outputs.exit_code }}"
36 changes: 0 additions & 36 deletions start/action.yml

This file was deleted.

15 changes: 11 additions & 4 deletions start/start-action-runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def bring_runners_online(connection, N):

sys.stdout.flush()

return total_runners == active_runners
return (total_runners == active_runners, active_runners)


if __name__ == '__main__':
Expand All @@ -87,13 +87,20 @@ def bring_runners_online(connection, N):
connection = openstack.connect()
except Exception as e:
print('::warning:: Failed to connect to cloud:', str(e))
sys.exit(0)
sys.exit(1)

# attempt to bring the servers online several times before returning
attempts = 0
while (not bring_runners_online(connection, args.N)
and attempts < NUM_ATTEMPTS):
done, active_runners = bring_runners_online(connection, args.N)
while (not done and attempts < NUM_ATTEMPTS):
attempts += 1
print(f'Waiting {TIME_BETWEEN_ATTEMPTS} seconds...', flush=True)
time.sleep(TIME_BETWEEN_ATTEMPTS)
print('', flush=True)
done, active_runners = bring_runners_online(connection, args.N)

if active_runners == 0:
sys.exit(2)

# testing
sys.exit(3)

0 comments on commit 6ae3a12

Please sign in to comment.