Skip to content

Create test environment from PR comment #31

Create test environment from PR comment

Create test environment from PR comment #31

---
name: Create test environment from PR comment
on:
issue_comment:
types: [created]
jobs:
execute_script:
runs-on: ubuntu-latest
environment: DEV
timeout-minutes: 10
steps:
- name: Check if comment contains 'create testenv'
run: |
if [[ ! "${{ github.event.comment.body }}" =~ "create testenv" ]]; then
echo "The comment does not contain 'create testenv'. Exiting..."
exit 0
fi
- name: Extract and set branch variable from PR
run: |
echo "branch=$(echo '${{ github.event.pull_request.head.ref }}')" >> $GITHUB_ENV
- name: Execute Script on Remote Server
if: ${{ env.branch != '' }}
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_ENV_SSH_HOST }}
username: ${{ secrets.TEST_ENV_SSH_USER }}
key: ${{ secrets.TEST_ENV_SSH_KEY }}
script: |
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/actions_keys/actions@assek
export TERM=xterm-256color
BRANCH=${{ env.branch }}
SUDO_PWD=${{ secrets.TEST_ENV_SUDO_PWD }}
echo $SUDO_PWD | sudo -S -E /srv/anet_testing/odoo/tools/test_environment/deploy.sh create $BRANCH | tee script_output.log
- name: Extract last 5 lines of output
run: |
if [ -f script_output.log ]; then
tail -n 5 script_output.log > last_lines.txt
echo "LAST_LINES=$(cat last_lines.txt)" >> $GITHUB_ENV
fi
- name: Comment on the PR
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-d '{"body": "Action completed successfully. Here are the last 5 lines of output:\n```\n'${LAST_LINES}'\n```"}' \
${{ github.event.issue.url }}/comments