|
| 1 | +name: Compiler CI PSDB trigger on amd-mainline branch |
| 2 | + |
| 3 | +# Controls when the workflow will run |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + branches: [amd-mainline] |
| 7 | + types: [opened, reopened, synchronize, ready_for_review] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel, below is a single job called invoke jenkins jobs |
| 11 | +jobs: |
| 12 | + # This workflow contains a single job called "invoke_jenkins_PSDB" |
| 13 | + invoke_jenkins_PSDB: |
| 14 | + if: github.event.pull_request.draft == false |
| 15 | + runs-on: |
| 16 | + group: compiler-generic-runners |
| 17 | + env: |
| 18 | + svc_acc_org_secret: ${{secrets.CI_GITHUB_TOKEN}} |
| 19 | + input_sha: ${{ github.event.pull_request.head.sha != '' && github.event.pull_request.head.sha || github.sha }} |
| 20 | + input_pr_num: ${{ github.event.pull_request.number != '' && github.event.pull_request.number || 0 }} |
| 21 | + input_pr_url: ${{ github.event.pull_request.html_url != '' && github.event.pull_request.html_url || '' }} |
| 22 | + input_pr_title: ${{ github.event.pull_request.title != '' && github.event.pull_request.title || '' }} |
| 23 | + # set the pipeline name here based on branch name |
| 24 | + pipeline_name: ${{secrets.CI_JENKINS_MAINLINE_JOB_NAME}} |
| 25 | + JENKINS_URL: ${{secrets.CI_JENKINS_URL}} |
| 26 | + CONTAINER_IMAGE: ${{ secrets.JENKINS_TRIGGER_DOCKER_IMAGE }} |
| 27 | + |
| 28 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 29 | + steps: |
| 30 | + |
| 31 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 32 | + - name: Set environment variable for container image |
| 33 | + run: | |
| 34 | + echo "CONTAINER_IMAGE=${{ secrets.JENKINS_TRIGGER_DOCKER_IMAGE }}" >> $GITHUB_ENV |
| 35 | + echo "CONTAINER_NAME=my_container_${{ github.run_id }}" >> $GITHUB_ENV |
| 36 | +
|
| 37 | +
|
| 38 | + - name: Pull container image |
| 39 | + run: docker pull "${{env.CONTAINER_IMAGE}}" |
| 40 | + |
| 41 | + |
| 42 | + - name: Run container |
| 43 | + run: | |
| 44 | + docker run -d --name "${{env.CONTAINER_NAME}}" $CONTAINER_IMAGE sleep infinity |
| 45 | + #docker exec "${{env.CONTAINER_NAME}}" /bin/bash -c "git clone ${{secrets.CI_UTILS_REPO}} ." |
| 46 | + docker exec "${{env.CONTAINER_NAME}}" /bin/bash -c "echo 'Running commands inside the container'" |
| 47 | + |
| 48 | + - name: Escape pull request title |
| 49 | + run: | |
| 50 | + import json |
| 51 | + import os |
| 52 | + import shlex |
| 53 | + with open('${{ github.event_path }}') as fh: |
| 54 | + event = json.load(fh) |
| 55 | + escaped = event['pull_request']['title'] |
| 56 | + with open(os.environ['GITHUB_ENV'], 'a') as fh: |
| 57 | + print(f'PR_TITLE={escaped}', file=fh) |
| 58 | + shell: python3 {0} |
| 59 | + |
| 60 | + - name: Run Jenkins Cancel Script |
| 61 | + env: |
| 62 | + JENKINS_URL: ${{secrets.CI_JENKINS_URL}} |
| 63 | + JENKINS_USER: ${{secrets.CI_JENKINS_USER}} |
| 64 | + JENKINS_API_TOKEN: ${{secrets.CI_JENKINS_TOKEN}} |
| 65 | + JENKINS_JOB_NAME: ${{secrets.CI_JENKINS_JOB_NAME}} |
| 66 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 67 | + COMMIT_HASH: ${{ github.event.after }} |
| 68 | + run: | |
| 69 | + docker exec -e JENKINS_JOB_NAME=${{secrets.CI_JENKINS_JOB_NAME}} -e PR_NUMBER=${{ github.event.pull_request.number }} -e COMMIT_HASH=${{ github.event.after }} -e JENKINS_URL=${{secrets.CI_JENKINS_URL}} -e JENKINS_USER=${{secrets.CI_JENKINS_USER}} -e JENKINS_API_TOKEN=${{secrets.CI_JENKINS_TOKEN}} "${{env.CONTAINER_NAME}}" /bin/bash -c "PYTHONHTTPSVERIFY=0 python3 cancel_previous_build.py" |
| 70 | +
|
| 71 | + |
| 72 | + # Runs a set of commands using the runners shell |
| 73 | + - name: Getting Event Details |
| 74 | + run: | |
| 75 | + echo $(pwd) |
| 76 | + echo $GITHUB_ENV |
| 77 | + echo $GITHUB_REPOSITORY |
| 78 | + echo $GITHUB_SERVER_URL |
| 79 | + echo "GITHUB_SHA is: $GITHUB_SHA" |
| 80 | + echo "GITHUB_WORKFLOW_SHA is: $GITHUB_WORKFLOW_SHA" |
| 81 | + echo "GITHUB_BASE_REF is: $GITHUB_BASE_REF" |
| 82 | + echo "GITHUB_REF_NAME is: $GITHUB_REF_NAME" |
| 83 | + echo "github.event.pull_request.id is: ${{github.event.pull_request.id}}" |
| 84 | + echo "github.event.pull_request.html_url is: ${{github.event.pull_request.html_url}}" |
| 85 | + echo "github.event.pull_request.number is: ${{github.event.pull_request.number}}" |
| 86 | + echo "github.event.pull_request.url is: ${{github.event.pull_request.url}}" |
| 87 | + echo "github.event.pull_request.issue_url is: ${{github.event.pull_request.issue_url}}" |
| 88 | + echo "github.event.pull_request.head.sha is: ${{github.event.pull_request.head.sha}}" |
| 89 | + echo "github.event.pull_request.base.ref is: ${{github.event.pull_request.base.ref}}" |
| 90 | + echo "github.event.pull_request.merge_commit_sha is: ${{github.event.pull_request.merge_commit_sha}}" |
| 91 | + echo "github.event.pull_request is: ${{github.event.pull_request}}" |
| 92 | + |
| 93 | + |
| 94 | + - name: Trigger Jenkins Pipeline |
| 95 | + if: steps.check_changes.outcome != 'failure' |
| 96 | + run: | |
| 97 | + echo "--Running jenkins_api.py with input sha - $input_sha for pull request - $input_pr_url" |
| 98 | + docker exec -e GITHUB_REPOSITORY="$GITHUB_REPOSITORY" -e svc_acc_org_secret="$svc_acc_org_secret" -e input_sha="$input_sha" -e input_pr_url="$input_pr_url" -e pipeline_name="$pipeline_name" \ |
| 99 | + -e input_pr_num="$input_pr_num" -e PR_TITLE="$PR_TITLE" -e JENKINS_URL="$JENKINS_URL" -e GITHUB_PAT="$svc_acc_org_secret" "${{env.CONTAINER_NAME}}" \ |
| 100 | + /bin/bash -c 'echo \"PR NUM: "$input_pr_num"\" && PYTHONHTTPSVERIFY=0 python3 jenkins_api.py -s \"${JENKINS_URL}\" -jn "$pipeline_name" -ghr "$GITHUB_REPOSITORY" -ghsha "$input_sha" -ghprn "$input_pr_num" -ghpru "$input_pr_url" -ghprt "$PR_TITLE" -ghpat="$svc_acc_org_secret"' |
| 101 | + |
| 102 | + - name: Stop and remove container |
| 103 | + if: always() |
| 104 | + run: | |
| 105 | + docker stop "${{env.CONTAINER_NAME}}" |
| 106 | + docker rm "${{env.CONTAINER_NAME}}" |
0 commit comments