From be836b29d5b01c17b071e3bf7a13e52619603df3 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sun, 15 Dec 2024 23:36:52 -0500 Subject: [PATCH] fix: Update to MorphoCloud/MorphoCloudWorkflow@5260162 List of MorphoCloudWorkflow changes: ``` $ git shortlog a644d53..5260162 --no-merges Jean-Christophe Fillion-Robin (2): fix(cloud-config): Update to MorphoCloud/exosphere@e9d099b0c fix(create-instance): Reboot to ensure correct torch version is installed ``` See https://github.com/MorphoCloud/MorphoCloudWorkflow/compare/a644d53...5260162 --- .github/actions/update-issue/action.yml | 175 ++++++++++++++++++++++++ .github/workflows/create-instance.yml | 58 ++++++++ cloud-config | 2 +- 3 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 .github/actions/update-issue/action.yml diff --git a/.github/actions/update-issue/action.yml b/.github/actions/update-issue/action.yml new file mode 100644 index 00000000..f8a1e02a --- /dev/null +++ b/.github/actions/update-issue/action.yml @@ -0,0 +1,175 @@ +name: "Update Issue Description" +description: "Update Issue Description" +inputs: + issue_number: + description: "Issue number" + required: true + command_name: + description: "Name of the command to execute: encode_email, decode_email" + required: true + token: + description: "GITHUB_TOKEN or repo scoped PAT" + required: true + string_encryption_key: + description: "Encryption key to encode and decode the email address" + required: true +runs: + using: "composite" + steps: + - name: Validate command + shell: bash + run: | + if [[ ! $COMMAND_NAME =~ ^encode_email|decode_email$ ]]; then + echo "::error ::Unknown command name 'COMMAND_NAME'. Valid commands are 'encode_email' or 'decode_email'." + exit 1 + fi + env: + COMMAND_NAME: ${{ inputs.command_name }} + + - name: Extract fields + id: extract + uses: ./.github/actions/extract-issue-fields + with: + token: ${{ inputs.token }} + repository: ${{ github.repository }} + issue_number: ${{ inputs.issue_number }} + + - name: Check if email is encoded + id: check_email_encryption + shell: bash + run: | + if [[ "$EMAIL" != *"@"* ]]; then + encoded="true" + else + encoded="false" + fi + echo "encoded=$encoded" >> $GITHUB_OUTPUT + env: + EMAIL: ${{ steps.extract.outputs.email }} + + - name: Encode email + id: encode_email + if: ${{ inputs.command_name == 'encode_email' }} + uses: ./.github/actions/encode-decode-string + with: + input_string: ${{ steps.extract.outputs.email }} + encryption_key: ${{ inputs.string_encryption_key }} + operation: "encode" + skip: ${{ steps.check_email_encryption.outputs.encoded == 'true' }} + + - name: Decode email + id: decode_email + if: ${{ inputs.command_name == 'decode_email' }} + uses: ./.github/actions/encode-decode-string + with: + input_string: ${{ steps.extract.outputs.email }} + encryption_key: ${{ inputs.string_encryption_key }} + operation: "decode" + skip: ${{ steps.check_email_encryption.outputs.encoded == 'false' }} + + - name: Check if confirm email is encoded + id: check_confirm_email_encryption + shell: bash + run: | + if [[ "$EMAIL" != *"@"* ]]; then + encoded="true" + else + encoded="false" + fi + echo "encoded=$encoded" >> $GITHUB_OUTPUT + env: + CONFIRM_EMAIL: ${{ steps.extract.outputs.confirm_email }} + + - name: Encode confirm email + id: encode_confirm_email + if: ${{ inputs.command_name == 'encode_email' }} + uses: ./.github/actions/encode-decode-string + with: + input_string: ${{ steps.extract.outputs.confirm_email }} + encryption_key: ${{ inputs.string_encryption_key }} + operation: "encode" + skip: + ${{ steps.check_confirm_email_encryption.outputs.encoded == 'true' }} + + - name: Decode confirm email + id: decode_confirm_email + if: ${{ inputs.command_name == 'decode_email' }} + uses: ./.github/actions/encode-decode-string + with: + input_string: ${{ steps.extract.outputs.confirm_email }} + encryption_key: ${{ inputs.string_encryption_key }} + operation: "decode" + skip: + ${{ steps.check_confirm_email_encryption.outputs.encoded == 'false' }} + + - name: Set updated email + id: set_updated_email + shell: bash + run: | + updated_email="" + updated_confirm_email="" + if [[ "$COMMAND_NAME" == "encode_email" ]]; then + updated_email="$ENCODED_EMAIL" + updated_confirm_email="$ENCODED_CONFIRM_EMAIL" + elif [[ "$COMMAND_NAME" == "decode_email" ]]; then + updated_email="$DECODED_EMAIL" + updated_confirm_email="$DECODED_CONFIRM_EMAIL" + fi + echo "updated_email=$updated_email" >> $GITHUB_OUTPUT + echo "updated_confirm_email=$updated_confirm_email" >> $GITHUB_OUTPUT + env: + COMMAND_NAME: ${{ inputs.command_name }} + ENCODED_EMAIL: ${{ steps.encode_email.outputs.output_string }} + ENCODED_CONFIRM_EMAIL: + ${{ steps.encode_confirm_email.outputs.output_string }} + DECODED_EMAIL: ${{ steps.decode_email.outputs.output_string }} + DECODED_CONFIRM_EMAIL: + ${{ steps.decode_confirm_email.outputs.output_string }} + + - name: Update issue body + id: update_issue_body + shell: bash + run: | + gh issue view $ISSUE_NUMBER \ + --repo $GH_REPO \ + --json body \ + --jq .body > ./body.md + + # Replace email and confirm emails + sed \ + -e "s#$OLD_EMAIL#$NEW_EMAIL#" \ + -e "s#$OLD_CONFIRM_EMAIL#$NEW_CONFIRM_EMAIL#" \ + ./body.md > ./updated_body.md + + gh issue edit $ISSUE_NUMBER \ + --repo $GH_REPO \ + --body-file ./updated_body.md + env: + GITHUB_TOKEN: ${{ inputs.token }} + GH_REPO: ${{ github.repository }} + ISSUE_NUMBER: ${{ inputs.issue_number }} + OLD_EMAIL: ${{ steps.extract.outputs.email }} + NEW_EMAIL: ${{ steps.set_updated_email.outputs.updated_email }} + OLD_CONFIRM_EMAIL: ${{ steps.extract.outputs.confirm_email }} + NEW_CONFIRM_EMAIL: + ${{ steps.set_updated_email.outputs.updated_confirm_email }} + + - name: command results comment (success) + if: ${{ success() }} + uses: peter-evans/create-or-update-comment@v4.0.0 + with: + issue-number: ${{ inputs.issue_number }} + body: | + `${{ inputs.command_name }}` command successfully applied to this issue ✅ + + - name: command results comment (failure) + if: ${{ failure() }} + uses: peter-evans/create-or-update-comment@v4.0.0 + with: + issue-number: ${{ inputs.issue_number }} + body: | + ### Command Results ❌ + + `${{ inputs.command_name }}` command failed to be applied to this issue. + + See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/.github/workflows/create-instance.yml b/.github/workflows/create-instance.yml index ce531511..1b73a68e 100644 --- a/.github/workflows/create-instance.yml +++ b/.github/workflows/create-instance.yml @@ -515,6 +515,64 @@ jobs: See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Reboot instance + id: reboot_instance + run: | + set +e + + ssh \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + -o LogLevel=ERROR \ + exouser@$INSTANCE_IP \ + 'sudo shutdown -r now' + + sleep 10 + function check_instance_ready { + ssh \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + -o LogLevel=ERROR \ + exouser@$INSTANCE_IP \ + 'true' + } + + max_attempts=3 + instance_ready=false + for attempt in $(seq 1 $max_attempts); do + echo "Checking if instance is ready ($attempt/$max_attempts)" + if check_instance_ready; then + instance_ready=true + echo "Instance '$INSTANCE_NAME' is ready." + break + else + echo "Instance '$INSTANCE_NAME' is not ready. Retrying in 5 seconds..." + sleep 10 + fi + done + if ! $instance_ready; then + echo "::error ::Instance '$INSTANCE_NAME' is not ready after $max_attempts attempts to connect." + exit 1 + fi + set -e + env: + INSTANCE_IP: ${{ steps.ip_create.outputs.floating_ip_address }} + INSTANCE_NAME: ${{ steps.define.outputs.instance_name }} + + - name: comment (failed to install Slicer extension dependencies) + if: + ${{ steps.slicer_install_extension_dependencies.outcome == 'failure' + && failure() }} + uses: peter-evans/create-or-update-comment@v4.0.0 + with: + issue-number: ${{ github.event.issue.number }} + body: | + ### Instance Creation Results ❌ + + Failed to install Slicer extension dependencies on instance **${{ steps.define.outputs.instance_name }}**. + + See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Update Request Status Label id: update-request-status-label uses: ./.github/actions/update-request-status-label diff --git a/cloud-config b/cloud-config index 7f289a0e..8aa48afe 100644 --- a/cloud-config +++ b/cloud-config @@ -36,7 +36,7 @@ runcmd: # --checkout "{instance-config-mgt-repo-checkout}" # -e "{ansible-extra-vars}" rm -rf /opt/instance-config-mgt - exosphere_sha="4546a412ab3b5fd540e5c3c2d9fe57500480fe4f" # morpho-cloud-portal-2024.07.17-78a7e2d93 + exosphere_sha="e9d099b0caa480533b6654db81e84c49db302b7b" # morpho-cloud-portal-2024.07.17-78a7e2d93 ansible-pull \ --url "https://github.com/MorphoCloud/exosphere.git" \ --checkout "$exosphere_sha" \