Skip to content

Commit

Permalink
Refactor DevContainer command execution to use a temporary script file
Browse files Browse the repository at this point in the history
- Updated the action to create a temporary script file for the command execution, ensuring the script name is in lowercase.
- Changed the command execution from directly passing the command to using the generated script file.
- Cleaned up the temporary script file after execution.
- Updated workflow files to use a multiline string for the COMMAND input, improving readability.

This change enhances the handling of commands in the DevContainer action and maintains a cleaner environment post-execution.
  • Loading branch information
guybartal committed Dec 12, 2024
1 parent 43cab59 commit 3d33ebb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 13 additions & 1 deletion .github/actions/devcontainer_run_command/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ runs:
- name: Run command in DevContainer
shell: bash
run: |
# Write command to a temporary script file with lowercase name
SCRIPT_FILE=$(mktemp)
mv "${SCRIPT_FILE}" "${SCRIPT_FILE,,}"
SCRIPT_FILE="${SCRIPT_FILE,,}"
cat << 'EOF' > "${SCRIPT_FILE}"
${{ inputs.COMMAND }}
EOF
chmod +x "${SCRIPT_FILE}"
docker run --rm --mount \
"type=bind,src=${{ github.workspace }},dst=/workspaces/tre" \
-v /var/run/docker.sock:/var/run/docker.sock \
Expand Down Expand Up @@ -246,4 +255,7 @@ runs:
-e TF_VAR_app_gateway_sku=${{ inputs.APP_GATEWAY_SKU }} \
-e E2E_TESTS_NUMBER_PROCESSES="${{ inputs.E2E_TESTS_NUMBER_PROCESSES }}" \
'${{ inputs.CI_CACHE_ACR_NAME }}${{ env.ACR_DOMAIN_SUFFIX }}/tredev:${{ inputs.DEVCONTAINER_TAG }}' \
bash -c "${{ inputs.COMMAND }}"
bash -c "./command.sh"
# Clean up temporary script file
rm "${SCRIPT_FILE}"
10 changes: 5 additions & 5 deletions .github/workflows/deploy_tre_reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ jobs:
uses: ./.github/actions/devcontainer_run_command
with:
# Although porter publish will build automatically, our makefile build target includes logic that should run
COMMAND: >-
COMMAND: |
for i in {1..3}; do make bundle-build bundle-publish DIR=${{ matrix.BUNDLE_DIR }}
&& ec=0 && break || ec=\$? && sleep 30; done; (exit \$ec)
DEVCONTAINER_TAG: ${{ inputs.DEVCONTAINER_TAG }}
Expand Down Expand Up @@ -470,7 +470,7 @@ jobs:
uses: ./.github/actions/devcontainer_run_command
with:
# Although porter publish will build automatically, our makefile build target includes logic that should run
COMMAND: >-
COMMAND: |
for i in {1..3}; do make bundle-build bundle-publish DIR=${{ matrix.BUNDLE_DIR }}
&& ec=0 && break || ec=\$? && sleep 30; done; (exit \$ec)
DEVCONTAINER_TAG: ${{ inputs.DEVCONTAINER_TAG }}
Expand Down Expand Up @@ -514,7 +514,7 @@ jobs:
- name: Register bundle
uses: ./.github/actions/devcontainer_run_command
with:
COMMAND: >-
COMMAND: |
for i in {1..3}; do make bundle-register DIR=${{ matrix.BUNDLE_DIR }}
&& ec=0 && break || ec=\$? && sleep 10; done; (exit \$ec)
DEVCONTAINER_TAG: ${{ inputs.DEVCONTAINER_TAG }}
Expand Down Expand Up @@ -574,7 +574,7 @@ jobs:
- name: Register bundle
uses: ./.github/actions/devcontainer_run_command
with:
COMMAND: >-
COMMAND: |
for i in {1..3}; do make bundle-register DIR=${{ matrix.BUNDLE_DIR }}
&& ec=0 && break || ec=\$? && sleep 10; done; (exit \$ec)
DEVCONTAINER_TAG: ${{ inputs.DEVCONTAINER_TAG }}
Expand Down Expand Up @@ -623,7 +623,7 @@ jobs:
- name: Register bundle
uses: ./.github/actions/devcontainer_run_command
with:
COMMAND: >-
COMMAND: |
for i in {1..3}; do make bundle-register DIR=${{ matrix.BUNDLE_DIR }}
&& ec=0 && break || ec=\$? && sleep 10; done; (exit \$ec)
DEVCONTAINER_TAG: ${{ inputs.DEVCONTAINER_TAG }}
Expand Down

0 comments on commit 3d33ebb

Please sign in to comment.