Skip to content

Commit

Permalink
iox-eclipse-iceoryx#409 Add Github Action to trigger Axivion analysis…
Browse files Browse the repository at this point in the history
… in private project
  • Loading branch information
Juan Pablo Samper committed Feb 2, 2021
1 parent dbd7913 commit 540b51e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/axivion.yml
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}"
28 changes: 28 additions & 0 deletions tools/axivion/trigger_pipeline
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()
57 changes: 57 additions & 0 deletions tools/axivion/wait_for_pipeline
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])

0 comments on commit 540b51e

Please sign in to comment.