forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-eclipse-iceoryx#409 Add Github Action to trigger Axivion analysis…
… in private project
- Loading branch information
Juan Pablo Samper
committed
Feb 2, 2021
1 parent
dbd7913
commit 540b51e
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Axivion | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
axivion: | ||
runs-on: ubuntu-18.04 | ||
|
||
steps: | ||
- name : Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Trigger pipeline | ||
env: | ||
AXIVION_TRIGGER_TOKEN: ${{ secrets.AXIVION_TRIGGER_TOKEN }} | ||
AXIVION_READ_API_TOKEN: ${{ secrets.AXIVION_READ_API_TOKEN }} | ||
run: | | ||
cd $GITHUB_WORKSPACE | ||
pip3 install requests | ||
PIPELINE_ID="$(./tools/axivion/trigger_pipeline)" | ||
./tools/axivion/wait_for_pipeline "${PIPELINE_ID}" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import requests | ||
import sys | ||
import time | ||
|
||
|
||
def main(): | ||
data = { | ||
'token': os.environ['AXIVION_TRIGGER_TOKEN'], | ||
'ref': os.environ.get('AXIVION_REF_NAME', 'master'), | ||
} | ||
commit_sha = os.environ['GITHUB_SHA'] | ||
r = requests.post( | ||
f'https://gitlab.com/api/v4/24081973/trigger/pipeline?variables[ICEORYX_SHA]={commit_sha}', | ||
json=data) | ||
|
||
if r.status_code != 201: | ||
print(f'ERROR: Pipeline trigger failed: {r.status_code}', file=sys.stderr) | ||
sys.exit(1) | ||
|
||
pipeline_id = r.json()['id'] | ||
print(pipeline_id) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import requests | ||
import sys | ||
import time | ||
|
||
TOKEN = { | ||
'PRIVATE-TOKEN': os.environ['AXIVION_READ_API_TOKEN'], | ||
} | ||
|
||
|
||
def get_status(pipeline_id): | ||
r = requests.get(f'https://gitlab.com/api/v4/projects/24081973/pipelines/{pipeline_id}', headers=TOKEN) | ||
|
||
if r.status_code != 200: | ||
print('ERROR: Could not check the status of the pipeline.', file=sys.stderr) | ||
sys.exit(1) | ||
|
||
return r.json()['status'] | ||
|
||
|
||
def print_logs(pipeline_id): | ||
r = requests.get(f'https://gitlab.com/api/v4/projects/24081973/pipelines/{pipeline_id}/jobs', headers=TOKEN) | ||
|
||
if r.status_code != 200: | ||
print('ERROR: Could not get job_id from pipeline.', file=sys.stderr) | ||
sys.exit(1) | ||
|
||
# Assumes pipeline only has one job | ||
job_id = r.json()[0]['id'] | ||
|
||
r = requests.get(f'https://gitlab.com/api/v4/projects/24081973/jobs/{job_id}/trace', headers=TOKEN) | ||
|
||
if r.status_code != 200: | ||
print('ERROR: Could not get job logs.', file=sys.stderr) | ||
sys.exit(1) | ||
|
||
print r.text() | ||
|
||
|
||
def main(pipeline_id): | ||
status = get_status(pipeline_id) | ||
|
||
while status in ['running', 'pending', 'created']: | ||
time.sleep(30) | ||
status = get_status(pipeline_id) | ||
|
||
print_logs(pipeline_id) | ||
|
||
if status in ['failed', 'canceled', 'skipped'] : | ||
print(f'ERROR: Pipeline {status}', file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1]) |