-
Notifications
You must be signed in to change notification settings - Fork 268
170 lines (148 loc) · 6.96 KB
/
rit.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Rootstock Integration Tests
on:
schedule:
- cron: '0 0 * * *'
pull_request:
types: [ opened, synchronize, reopened ]
branches: ["master", "*-rc"]
workflow_dispatch:
inputs:
rit-branch:
description: 'Branch for Rootstock Integration Tests'
required: false
default: 'main'
powpeg-branch:
description: 'Branch for PowPeg Node'
required: false
default: 'master'
# Declare default permissions as read only.
permissions: read-all
jobs:
rootstock-integration-tests:
name: Rootstock Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout Repository # Step needed to access the PR description using github CLI
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 #v4.2.1
- name: Set Branch Variables
id: set-branch-variables
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_event_inputs_powpeg_branch: ${{ github.event.inputs.powpeg-branch }}
github_event_inputs_rit_branch: ${{ github.event.inputs.rit-branch }}
github_event_name: ${{ github.event_name }}
github_event_pull_request_number: ${{ github.event.pull_request.number }}
github_head_ref: ${{ github.head_ref }}
github_ref_name: ${{ github.ref_name }}
github_event_pull_request_head_repo_owner_login: ${{ github.event.pull_request.head.repo.owner.login }}
github_repository_owner: ${{ github.repository_owner }}
run: |
PR_DESCRIPTION=pr-description.txt
ALLOWED_BRANCH_CHARACTERS='[-+./0-9A-Z_a-z]'
default_rskj_branch=master
default_powpeg_branch=master
default_rit_branch=main
get_branch_from_description()
{
_prefix=$1
# On lines matching "`$_prefix:...`", replace the lines with the
# thing in ... and print the result.
_search_re='\@`'$_prefix:$ALLOWED_BRANCH_CHARACTERS'\{1,\}`@'
_replace_re='s@.*`'$_prefix:'\('$ALLOWED_BRANCH_CHARACTERS'\{1,\}\)`.*@\1@p'
_branch=$(sed -n "$_search_re $_replace_re" "$PR_DESCRIPTION")
echo "$_branch"
}
is_valid_branch_name()
{
echo "$1" | grep -qx "$ALLOWED_BRANCH_CHARACTERS\\{1,\\}"
}
if [ "$github_event_name" = workflow_dispatch ]; then
RSKJ_BRANCH=$github_ref_name
POWPEG_BRANCH=${github_event_inputs_powpeg_branch:-$default_powpeg_branch}
RIT_BRANCH=${github_event_inputs_rit_branch:-$default_rit_branch}
elif [ "$github_event_name" = pull_request ]; then
gh pr view "$github_event_pull_request_number" --json body -q .body >"$PR_DESCRIPTION"
RSKJ_BRANCH=$(get_branch_from_description rskj)
: ${RSKJ_BRANCH:=${github_head_ref:-$default_rskj_branch}}
POWPEG_BRANCH=$(get_branch_from_description fed)
: ${POWPEG_BRANCH:=$default_powpeg_branch}
RIT_BRANCH=$(get_branch_from_description rit)
: ${RIT_BRANCH:=$default_rit_branch}
else
RSKJ_BRANCH=$default_rskj_branch
POWPEG_BRANCH=$default_powpeg_branch
RIT_BRANCH=$default_rit_branch
fi
if ! is_valid_branch_name "$RSKJ_BRANCH"; then
echo "rskj: invalid branch name: $RSKJ_BRANCH" >&2
exit 1
fi
if ! is_valid_branch_name "$POWPEG_BRANCH"; then
echo "fed: invalid branch name: $POWPEG_BRANCH" >&2
exit 1
fi
if ! is_valid_branch_name "$RIT_BRANCH"; then
echo "rit: invalid branch name: $RIT_BRANCH" >&2
exit 1
fi
# Set the Repo Owner
REPO_OWNER="${github_event_pull_request_head_repo_owner_login:-$github_repository_owner}"
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
echo "RSKJ_BRANCH=$RSKJ_BRANCH" >> $GITHUB_ENV
echo "RIT_BRANCH=$RIT_BRANCH" >> $GITHUB_ENV
echo "POWPEG_BRANCH=$POWPEG_BRANCH" >> $GITHUB_ENV
- name: Set Build URL
id: set-build-url
run: |
BUILD_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "BUILD_URL=$BUILD_URL" >> $GITHUB_ENV
- name: Sanitize Github Variables
id: sanitize-github-variables
env:
GITHUB_EVENT_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
run: |
# Delete non-alphanumeric characters and limit to 75 chars which is the branch title limit in GitHub
SAFE_PULL_REQUEST_TITLE=$(echo "${GITHUB_EVENT_PULL_REQUEST_TITLE}" | tr -cd '[:alnum:]_ -' | cut -c1-75)
echo "SAFE_PULL_REQUEST_TITLE=$SAFE_PULL_REQUEST_TITLE" >> $GITHUB_ENV
- name: Run Rootstock Integration Tests
uses: rsksmart/rootstock-integration-tests@e86332474179a63f027d0fe969687d3d24f34c29 #v1
with:
rskj-branch: ${{ env.RSKJ_BRANCH }}
powpeg-node-branch: ${{ env.POWPEG_BRANCH }}
rit-branch: ${{ env.RIT_BRANCH }}
repo-owner: ${{ env.REPO_OWNER }}
- name: Send Slack Notification on Success
if: success() && github.event.pull_request.head.repo.owner.login == 'rsksmart'
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
env:
SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }}
GITHUB_EVENT_PULL_REQUEST_HTML_URL: ${{ github.event.pull_request.html_url }}
with:
channel-id: ${{ vars.GHA_SLACK_NOTIFICATION_CHANNEL }}
payload: |
{
"attachments": [
{
"color": "good",
"text": "*PASSED*: :white_check_mark: - *${{ env.SAFE_PULL_REQUEST_TITLE }}* \n*Pull request*: ${{ env.GITHUB_EVENT_PULL_REQUEST_HTML_URL }} \n*Pipeline*: ${{ env.BUILD_URL }} \n*Branches used*: [ rskj:`${{ env.RSKJ_BRANCH }}` ] [ fed:`${{ env.POWPEG_BRANCH }}` ] [ rit:`${{ env.RIT_BRANCH }}` ]"
}
]
}
- name: Send Slack Notification on Failure
if: failure() && github.event.pull_request.head.repo.owner.login == 'rsksmart'
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
env:
SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }}
GITHUB_EVENT_PULL_REQUEST_HTML_URL: ${{ github.event.pull_request.html_url }}
with:
channel-id: ${{ vars.GHA_SLACK_NOTIFICATION_CHANNEL }}
payload: |
{
"attachments": [
{
"color": "danger",
"text": "*FAILED*: :x: - *${{ env.SAFE_PULL_REQUEST_TITLE }}* \n*Pull request*: ${{ env.GITHUB_EVENT_PULL_REQUEST_HTML_URL }} \n*Pipeline*: ${{ env.BUILD_URL }} \n*Branches used*: [ rskj:`${{ env.RSKJ_BRANCH }}` ] [ fed:`${{ env.POWPEG_BRANCH }}` ] [ rit:`${{ env.RIT_BRANCH }}` ]"
}
]
}