Skip to content

Commit

Permalink
feat: Perform action
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Aug 24, 2024
1 parent d3e3109 commit 86393ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/automatic-instance-shelving.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
workflow_dispatch:

permissions:
issues: write
contents: read

jobs:
Expand All @@ -14,6 +15,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4 # v1.10.3
id: app-token
with:
app-id: ${{ vars.MORPHOCLOUD_WORKFLOW_APP_ID }}
private-key: ${{ secrets.MORPHOCLOUD_WORKFLOW_APP_PRIVATE_KEY }}

- name: Auto Shelve
run: |
export OS_CLOUD=BIO180006_IU # Select openstack auth settings defined in ".config/openstack/clouds.yaml"
Expand All @@ -35,6 +42,9 @@ jobs:
# Skip because instance status is being updated
continue
fi
# Extract issue number
issue_number=${instance_name##*-}
echo "issue_number [$issue_number]"
# Get instance IP
instance_ip=$(
openstack server show $instance_name -c addresses -f json | \
Expand All @@ -53,7 +63,7 @@ jobs:
exouser@$instance_ip \
'cat /proc/uptime | awk "{print \$1}"')
uptime_hours=$(echo "scale=2; $uptime_seconds / 3600" | bc)
# Check uptime
# Check uptime and define action
if $(python3 -c "valid=($uptime_hours > 3.5 and $uptime_hours <= 4.0); EXIT_SUCCESS=0; EXIT_FAILURE=1; exit(EXIT_SUCCESS if valid else EXIT_FAILURE)"); then
action="notify"
elif $(python3 -c "valid=($uptime_hours > 4.0); EXIT_SUCCESS=0; EXIT_FAILURE=1; exit(EXIT_SUCCESS if valid else EXIT_FAILURE)"); then
Expand All @@ -62,6 +72,18 @@ jobs:
action=""
fi
echo "instance_name [$instance_name], uptime_hours [$uptime_hours] -> action[$action]"
# Perform action
if [[ "$action" == "shelve" ]]; then
gh workflow run control-instance-from-workflow.yml \
-f issue_number=$issue_number \
-f command_name=shelve
gh issue comment $issue_number \
-b "Workflow **control-instance-from-workflow.yml** triggered by *automatic-instance-shelving.yml* for command `shelve`<br>\
<br>\
For details, see https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}_"
fi
done
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_REPO: ${{ github.repository }}
PREFIX: ${{ vars.INSTANCE_NAME_PREFIX }}
2 changes: 1 addition & 1 deletion .github/workflows/control-instance-from-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Control instance
run: |
gh issue comment $ISSUE_NUMBER \
-b "Command `shelve` issued by *control-instance-from-workflow.yml* workflow<br>\
-b "Command `shelve` issued by **control-instance-from-workflow.yml** workflow<br>\
<br>\
For details, see https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}_"
env:
Expand Down

0 comments on commit 86393ee

Please sign in to comment.