Skip to content

Commit 389241a

Browse files
committed
Add test command
1 parent b5da5ba commit 389241a

4 files changed

Lines changed: 239 additions & 1 deletion

File tree

.github/workflows/build-command.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO: Don't build if the PR is not based on master's HEAD
2+
# TODO: Only build the container if specific directories/files have changed, unless forced: https://coderwall.com/p/lz0uva/find-all-files-modified-between-commits-in-git
23
name: build-command
34
on:
45
repository_dispatch:

.github/workflows/command-dispatch.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Slash Command Dispatch
1010
uses: peter-evans/slash-command-dispatch@v1
1111
with:
12-
token: ${{ secrets.TOKEN }}
12+
token: ${{ secrets.EMBERIO_ACCESS_TOKEN }}
1313
issue-type: pull-request
1414
reactions: true
1515
# commands: help, build
@@ -26,5 +26,10 @@ jobs:
2626
"command": "build",
2727
"permission": "write",
2828
"issue_type": "pull-request"
29+
},
30+
{
31+
"command": "test",
32+
"permission": "write",
33+
"issue_type": "pull-request"
2934
}
3035
]

.github/workflows/test-command.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# TODO: Don't build if the PR is not based on master's HEAD
2+
# TODO: Only build the container if specific directories/files have changed, unless forced: https://coderwall.com/p/lz0uva/find-all-files-modified-between-commits-in-git
3+
name: test-pr-${{ github.event.client_payload.pull_request.number }}-${{ github.event.client_payload.pull_request.head.sha) }}
4+
on:
5+
repository_dispatch:
6+
types: [test-command]
7+
env:
8+
AUTHORIZED: ${{ github.actor != github.event.client_payload.pull_request.base.repo.owner.login }}
9+
DETAILS_URL: ${{ format('https://github.com/{0}/actions/runs/{1}', github.repository, github.run_id) }}
10+
DOCKER_REPO: embercsi/ci_images
11+
IMAGE_TAG: ${{ format('{0}-{1}', github.event.client_payload.pull_request.number, github.event.client_payload.pull_request.head.sha) }}
12+
13+
jobs:
14+
15+
build:
16+
name: internal/build-pr-images
17+
env:
18+
JOB_NAME: internal/build-pr-images
19+
TAGS_MISSING: false
20+
21+
# In the future we may want to return embercsi/ember-csi:{master,latest}
22+
outputs:
23+
image_base_name: ${{ format('{0}:{1}-', env.DOCKER_REPO, env.IMAGE_TAG) }}
24+
25+
runs-on: ubuntu-latest
26+
steps:
27+
# Checkout the pull request branch from the repository
28+
- uses: actions/checkout@v2
29+
if: env.AUTHORIZED == 'true'
30+
with:
31+
token: ${{ secrets.TOKEN }}
32+
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
33+
ref: ${{ github.event.client_payload.pull_request.head.ref }}
34+
35+
- name: Write comment
36+
uses: peter-evans/create-or-update-comment@v1
37+
with:
38+
token: ${{ secrets.EMBERIO_ACCESS_TOKEN }}
39+
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
40+
issue-number: ${{ github.event.client_payload.pull_request.number }}
41+
# comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
42+
body: |
43+
[Test workflow has started][1]
44+
45+
[1]: ${{ env.DETAILS_URL }}
46+
47+
- name: Notify in_progress
48+
if: env.AUTHORIZED == 'true'
49+
run: ./tools/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} pending ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }}
50+
#run: |
51+
# curl -X POST -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" -d '{"context": "${{ env.JOB_NAME }}","state": "pending","target_url": "${{ env.DETAILS_URL }}"}' "https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }}"
52+
env:
53+
TOKEN: ${{ secrets.TOKEN }}
54+
55+
- name: Check if images exist
56+
if: env.AUTHORIZED == 'true'
57+
run: |
58+
for i in 7 8; do
59+
if ! curl -L --silent ${{ format('https://hub.docker.com/v2/repositories/{0}/tags/{1}', env.DOCKER_REPO, env.IMAGE_TAG) }}-$i | grep '"name"'; then
60+
echo "::set-env name=TAGS_MISSING::true"
61+
break
62+
fi
63+
done
64+
65+
- name: Build images
66+
if: env.AUTHORIZED == 'true' && env.TAGS_MISSING == 'true'
67+
run: |
68+
echo 'Start'
69+
echo "::add-mask::${{ secrets.DOCKER_PASSWORD }}"
70+
EMBER_VERSION=$IMAGE_TAG SOURCE_BRANCH=master hooks/build
71+
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
72+
docker tag $DOCKER_REPO:master7 $DOCKER_REPO:${IMAGE_TAG}-7
73+
docker tag $DOCKER_REPO:master8 $DOCKER_REPO:${IMAGE_TAG}-8
74+
docker push $DOCKER_REPO:${IMAGE_TAG}-7
75+
docker push $DOCKER_REPO:${IMAGE_TAG}-8
76+
echo 'Done'
77+
78+
# - name: Get result status
79+
# if: always() && env.AUTHORIZED == 'true'
80+
# run: |
81+
# status=`echo "${{ job.status }}" | tr '[:upper:]' '[:lower:]'`
82+
# if [[ "$status" == "cancelled" ]]; then
83+
# echo "::set-env name=JOB_RESULT::error"
84+
# else
85+
# echo "::set-env name=JOB_RESULT::$status"
86+
# fi
87+
88+
- name: Notify result status
89+
if: always() && env.AUTHORIZED == 'true'
90+
run: ./tools/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} ${{ job.status }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }}
91+
# run: |
92+
# curl -X POST -H "Authorization: token ${{ secrets.TOKEN }}" -H "Content-Type: application/json" -d '{"context": "${{ env.JOB_NAME }}","state": "${{ env.JOB_RESULT }}","target_url": "${{ env.DETAILS_URL }}"}' "https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }}"
93+
env:
94+
TOKEN: ${{ secrets.TOKEN }}
95+
96+
97+
functional:
98+
needs: build
99+
strategy:
100+
fail-fast: false
101+
matrix:
102+
centos: [7, 8]
103+
backend: [lvm, ceph]
104+
csi: [v1.1]
105+
include:
106+
- centos: 7
107+
backend: lvm
108+
csi: v1.0
109+
- centos: 7
110+
backend: lvm
111+
csi: v0.3
112+
- centos: 7
113+
backend: lvm
114+
csi: v0.2
115+
name: "3rdparty/${{ matrix.backend }}-functional-centos${{ matrix.centos }}-csi_${{ matrix.csi }}"
116+
runs-on: ${{ matrix.backend }}
117+
# Fails:
118+
# runs-on: [self-hosted, ${{ matrix.backend }}]
119+
# runs-on: "[self-hosted, ${{ matrix.backend }}]"
120+
# runs-on: ${{ format('[ self-hosted, {0} ]', matrix.backend) }}
121+
# These work:
122+
#runs-on: [self-hosted, lvm]
123+
# runs-on: self-hosted
124+
env:
125+
JOB_NAME: "3rdparty/${{ matrix.backend }}-functional-centos${{ matrix.centos }}-csi_${{ matrix.csi }}"
126+
BACKEND_NAME: ${{ matrix.backend }}
127+
steps:
128+
# Checkout the pull request branch from the repository
129+
- uses: actions/checkout@v2
130+
if: env.AUTHORIZED == 'true'
131+
with:
132+
repository: embercsi/3rd-party-ci
133+
ref: gh-actions
134+
135+
- name: Notify in_progress
136+
# run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} pending ${{ env.DETAILS_URL }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }}
137+
run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} pending ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }}
138+
env:
139+
TOKEN: ${{ secrets.TOKEN }}
140+
141+
- name: Testing
142+
run: |
143+
pwd
144+
export HOST_IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
145+
echo Running with backend ${{ matrix.backend }} on a Centos ${{ matrix.centos }} VM
146+
./ci-scripts/vm-run-functional.sh
147+
env:
148+
EMBER_IMAGE: ${{needs.build.outputs.image_base_name}}
149+
CENTOS_VERSION: ${{matrix.centos}}
150+
JOB_ID: ${{github.run_id}}
151+
CSI_SPEC_VERSION: ${{matrix.csi}}
152+
# BACKEND_NAME: ${{matrix.backend}}
153+
154+
- name: Upload artifacts
155+
if: always()
156+
uses: actions/upload-artifact@v2-preview
157+
with:
158+
name: "${{ matrix.backend }}-functional-centos${{ matrix.centos }}-artifacts"
159+
path: 'artifacts/*'
160+
161+
- name: Notify result status
162+
if: always()
163+
# run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ job.status }} ${{ env.DETAILS_URL }} ${{ github.repository }}
164+
run: ./ci-scripts/notify-job-status.py ${{ env.JOB_NAME }} ${{ github.run_id }} ${{ job.status }} ${{ github.repository }} ${{ github.event.client_payload.pull_request.head.sha }}
165+
env:
166+
TOKEN: ${{ secrets.TOKEN }}

tools/notify-job-status.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
import json
3+
import os
4+
import sys
5+
import urllib2
6+
7+
ERNO_NUMBER_ARGS = 1
8+
ERNO_JOB_INFO = 2
9+
ERNO_STATUS = 3
10+
11+
HEADERS = {'Authorization': 'token ' + os.environ['TOKEN'],
12+
'Content-Type': 'application/json',
13+
'User-Agent': 'Ember-CSI_CI'}
14+
15+
16+
def get_job_url(repository, job_name, run_id):
17+
url = 'https://api.github.com/repos/%s/actions/runs/%s/jobs' % (repository,
18+
run_id)
19+
req = urllib2.Request(url, headers=HEADERS)
20+
response = urllib2.urlopen(req)
21+
result = json.loads(response.read())
22+
for job in result['jobs']:
23+
if job['name'] != job_name:
24+
continue
25+
return job['html_url'] + '?check_suite_focus=true'
26+
sys.stderr.write('Could not find the requested job')
27+
exit(ERNO_JOB_INFO)
28+
29+
30+
def set_state(state, repository, job_name, target_url, commit_sha):
31+
url = 'https://api.github.com/repos/%s/statuses/%s' % (repository,
32+
commit_sha)
33+
data = json.dumps({'context': job_name,
34+
'state': state,
35+
'target_url': target_url})
36+
37+
req = urllib2.Request(url, data, HEADERS)
38+
error = None
39+
try:
40+
response = urllib2.urlopen(req)
41+
if response.code != 201:
42+
error = 'Status code is %s' % response.code
43+
except Exception as exc:
44+
error = str(exc)
45+
46+
if error:
47+
sys.stderr.write('Error sending status change: %s\n' % error)
48+
exit(ERNO_STATUS)
49+
50+
51+
if __name__ == '__main__':
52+
if len(sys.argv) != 6:
53+
sys.stderr.write('Wrong number of arguments:\n\t%s job_name run_id '
54+
'state repository commit_sha\n' %
55+
os.path.basename(sys.argv[0]))
56+
exit(ERNO_NUMBER_ARGS)
57+
58+
__, job_name, run_id, state, repository, commit_sha = sys.argv
59+
60+
# Convert gh-actions job status to old checks status
61+
state = state.lower()
62+
if state == 'cancelled':
63+
state = 'error'
64+
65+
target_url = get_job_url(repository, job_name, run_id)
66+
set_state(state, repository, job_name, target_url, commit_sha)

0 commit comments

Comments
 (0)