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 9283fe3 commit 79edfda
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 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,16 @@ jobs:
action=""
fi
echo "instance_name [$instance_name], uptime_hours [$uptime_hours] -> action[$action]"
# Perform action
if [[ "$action" == "shelve" ]]; then
gh issue comment $issue_number \
-b "/shelve<br>\
<br>\
_Command issues by *automatic-instance-shelving.yml* workflow. \
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.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
reaction: "rocket"
allowed_contexts: "issue"
permissions: "read,triage,write,maintain,admin"
allowlist: "jcfr,muratmaga,${{ github.event.issue.user.login }}"
allowlist: "jcfr,muratmaga,morphocloud-workflow-app[bot],${{ github.event.issue.user.login }}"

- name: delete command
id: delete_command
Expand Down

0 comments on commit 79edfda

Please sign in to comment.