-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (73 loc) · 2.93 KB
/
create_test_env.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
name: Create test environment from PR comment
on:
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
jobs:
execute_script:
runs-on: ubuntu-latest
environment: DEV
timeout-minutes: 10
steps:
- name: Check if comment contains 'create testenv' anywhere
run: |
if ! echo "${{ github.event.comment.body }}" | grep -q "create testenv"; then
echo "The comment does not contain 'create testenv'. Exiting..."
exit 0
fi
- name: Extract and set branch variable from PR
run: |
# Extract the pull request URL
PR_URL="${{ github.event.issue.pull_request.url }}"
# Use GitHub API to get the pull request details
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$PR_URL")
# Extract the branch name from the pull request data
BRANCH_NAME=$(echo "$PR_DATA" | jq -r '.head.ref')
if [ -z "$BRANCH_NAME" ]; then
echo "Branch extraction failed. Exiting..."
exit 1
fi
echo "branch=$BRANCH_NAME" >> $GITHUB_ENV
echo "Extracted branch: $BRANCH_NAME"
- name: Comment "on going" on the PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-d '{"body": "The environment setup is in progress..."}' \
${{ github.event.issue.url }}/comments
- 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
if: ${{ env.branch != '' }}
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
else
echo "No script_output.log found. Setting LAST_LINES to empty."
echo "LAST_LINES=" >> $GITHUB_ENV
fi
- name: Comment on the PR
if: ${{ env.branch != '' }} && 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