-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Add initial support for /start and /stop command
- Loading branch information
Showing
1 changed file
with
92 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,77 +8,107 @@ concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
# Permissions needed for reacting to IssueOps commands on issues | ||
permissions: | ||
issues: write | ||
checks: read | ||
|
||
jobs: | ||
start: | ||
runs-on: self-hosted | ||
if: | ||
${{ !github.event.issue.pull_request && | ||
contains(github.event.comment.body, '/start') }} | ||
${{ !github.event.issue.pull_request && ( | ||
contains(github.event.comment.body, '/start') || | ||
contains(github.event.comment.body, '/stop') ) }} | ||
steps: | ||
- run: | | ||
echo Starting instance associated with issue $NUMBER | ||
- name: start command | ||
id: start_command | ||
uses: github/[email protected] | ||
with: | ||
command: "/start" | ||
reaction: "rocket" | ||
|
||
- name: stop command | ||
id: stop_command | ||
uses: github/[email protected] | ||
with: | ||
command: "/stop" | ||
reaction: "rocket" | ||
|
||
- name: Define instance name | ||
id: define | ||
run: | | ||
instance_name="morpho-cloud-portal_instance-$ISSUE_NUMBER" | ||
echo "instance_name=$instance_name" >> $GITHUB_OUTPUT | ||
env: | ||
NUMBER: ${{ github.event.issue.number }} | ||
ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
|
||
- name: Extract email | ||
id: extract | ||
- name: Check instance exists | ||
id: check_instance | ||
run: | | ||
email=$( | ||
echo ${{ toJSON(steps.parse.outputs.data) }} | | ||
jq -r ".email.text" | ||
) | ||
echo "email=$email" >> $GITHUB_OUTPUT | ||
- name: Send mail | ||
uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 | ||
with: | ||
server_address: smtp.gmail.com | ||
server_port: 465 | ||
secure: true | ||
username: ${{secrets.MAIL_USERNAME}} | ||
password: ${{secrets.MAIL_PASSWORD}} | ||
from: MorphoCloudPortal | ||
to: ${{ steps.extract.outputs.email }} | ||
subject: | ||
"[MorphoCloudPortal] Instance ${{ github.event.issue.number }} | ||
started" | ||
body: Instance ${{ github.event.issue.number }} started | ||
|
||
stop: | ||
runs-on: self-hosted | ||
if: | ||
${{ !github.event.issue.pull_request && | ||
contains(github.event.comment.body, '/stop') }} | ||
steps: | ||
- run: | | ||
echo Stopping instance associated with issue $NUMBER | ||
export OS_CLOUD=BIO180006_IU # Select openstack auth settings defined in ".config/openstack/clouds.yaml" | ||
source ~/venv/bin/activate | ||
instance=$(openstack server list -f json | \ | ||
jq \ | ||
--arg instance_name "$INSTANCE_NAME" \ | ||
-c '.[] | select(.Name | contains($instance_name))' | \ | ||
jq -r '.Name') | ||
[[ $instance == "$INSTANCE_NAME" ]] && exists="true" || exists="false" | ||
echo "exists [$exists]" | ||
echo "exists=$exists" >> $GITHUB_OUTPUT | ||
env: | ||
NUMBER: ${{ github.event.issue.number }} | ||
INSTANCE_NAME: ${{ steps.define.outputs.instance_name }} | ||
|
||
- name: start | ||
if: | ||
${{ steps.start_command.outputs.continue == 'true' && | ||
steps.check_instance.outputs.exists == 'true' }} | ||
run: | | ||
export OS_CLOUD=BIO180006_IU # Select openstack auth settings defined in ".config/openstack/clouds.yaml" | ||
source ~/venv/bin/activate | ||
- name: Issue Forms Body Parser | ||
id: parse | ||
uses: zentered/[email protected] | ||
OS_CLOUD=BIO180006_IU openstack server start | ||
- name: Extract email | ||
id: extract | ||
- name: stop | ||
if: | ||
${{ steps.stop_command.outputs.continue == 'true' && | ||
steps.check_instance.outputs.exists == 'true' }} | ||
run: | | ||
email=$( | ||
echo ${{ toJSON(steps.parse.outputs.data) }} | | ||
jq -r ".email.text" | ||
) | ||
echo "email=$email" >> $GITHUB_OUTPUT | ||
- name: Send mail | ||
uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 | ||
with: | ||
server_address: smtp.gmail.com | ||
server_port: 465 | ||
secure: true | ||
username: ${{secrets.MAIL_USERNAME}} | ||
password: ${{secrets.MAIL_PASSWORD}} | ||
from: MorphoCloudPortal | ||
to: ${{ steps.extract.outputs.email }} | ||
subject: | ||
"[MorphoCloudPortal] Instance ${{ github.event.issue.number }} | ||
stopped" | ||
body: Instance ${{ github.event.issue.number }} stopped | ||
export OS_CLOUD=BIO180006_IU # Select openstack auth settings defined in ".config/openstack/clouds.yaml" | ||
source ~/venv/bin/activate | ||
OS_CLOUD=BIO180006_IU openstack server stop | ||
# - name: Issue Forms Body Parser | ||
# id: parse | ||
# uses: zentered/[email protected] | ||
|
||
# - name: Extract email | ||
# id: extract | ||
# run: | | ||
# email=$( | ||
# echo ${{ toJSON(steps.parse.outputs.data) }} | | ||
# jq -r ".email.text" | ||
# ) | ||
# echo "email=$email" >> $GITHUB_OUTPUT | ||
|
||
# - name: Send mail | ||
# uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0 | ||
# with: | ||
# server_address: smtp.gmail.com | ||
# server_port: 465 | ||
# secure: true | ||
# username: ${{secrets.MAIL_USERNAME}} | ||
# password: ${{secrets.MAIL_PASSWORD}} | ||
# from: MorphoCloudPortal | ||
# to: ${{ steps.extract.outputs.email }} | ||
# subject: | ||
# "[MorphoCloudPortal] Instance ${{ github.event.issue.number }} | ||
# started" | ||
# body: Instance ${{ github.event.issue.number }} started |