blob: e97b66358ea756bdddd56a1a37c6814d1e48f62f [file] [log] [blame]
Tomás González45c05002025-06-19 13:16:52 +01001- job:
2 name: tf-a-unsafe-tfa-next
3 node: docker-amd64-tf-a-jammy
4 project-type: freestyle
5 concurrent: true
6 disabled: false
7 defaults: global
8 description: Check for Unsafe changes in Trusted Firmware Next
9 properties:
Chris Kay675db4f2025-06-24 14:14:34 +010010 - build-discarder:
11 days-to-keep: 14
Tomás González45c05002025-06-19 13:16:52 +010012 triggers:
Chris Kay675db4f2025-06-24 14:14:34 +010013 - gerrit:
14 server-name: review.trustedfirmware.org
15 projects:
16 - branches:
17 - branch-compare-type: PLAIN
18 branch-pattern: main
19 project-compare-type: PLAIN
20 project-pattern: RF-A/rusted-firmware-a
21 trigger-on:
Tomás González45c05002025-06-19 13:16:52 +010022 - patchset-created-event:
23 exclude-drafts: true
24 exclude-trivial-rebase: false
25 exclude-no-code-change: true
26 exclude-private: true
27 exclude-wip: true
28 - comment-added-contains-event:
Chris Kay675db4f2025-06-24 14:14:34 +010029 comment-contains-value: ^RUN_UNSAFE_CI$
30 override-votes: true
31 # without explicitly setting these values to 0, the plugin will by
32 # default leave Code Review votes
33 gerrit-build-started-codereview-value: 0
34 gerrit-build-successful-codereview-value: 0
35 gerrit-build-failed-codereview-value: 0
36 gerrit-build-unstable-codereview-value: 0
37 gerrit-build-notbuilt-codereview-value: 0
38 silent: false
39 silent-start: false
Tomás González45c05002025-06-19 13:16:52 +010040 parameters:
Chris Kay675db4f2025-06-24 14:14:34 +010041 # GERRIT_{PROJECT,BRANCH,REFSPEC} are set when triggered by a Gerrit
42 # patchset - defaults below are for manual triggers
43 - string:
44 name: GERRIT_PROJECT
45 default: RF-A/rusted-firmware-a
46 - string:
47 name: GERRIT_BRANCH
48 default: refs/heads/main
49 - string:
50 name: GERRIT_REFSPEC
51 default: +refs/heads/main:refs/remotes/origin/main
52 description: |
53 'e.g. refs/changes/13/31138/1'
54 - string:
55 name: RF_GERRIT_REFSPEC
56 default: ${GERRIT_REFSPEC}
57 description: |
58 'do-not-amend: used by scripts/clone.sh to fetch the correct Gerrit patchset - use GERRIT_REFSPEC instead'
59 - string:
60 name: CI_REFSPEC
61 default: +refs/heads/tfa-next:refs/remotes/origin/tfa-next
62 description: |
63 'Refs to fetch for the tf-a-ci-scripts repo e.g. refs/changes/13/31138/1'
64 - string:
65 name: JOBS_REFSPEC
66 default: refs/heads/master
67 description: |
68 tf-a-job-configs refspec to use. The master branch is used by default.
69 - string:
70 name: SHARE_FOLDER
71 default: /srv/shared/${JOB_NAME}/${BUILD_NUMBER}
72 description: Folder containing shared repositories for downstream pipeline jobs
73 - string:
74 name: CLONE_REPOS
75 default: rusted-firmware-a
76 description: |
77 Optional arg to clone only specific projects from default list (tf-a-ci-scripts,rusted-firmware-a,tf-a-tests,spm,tf-m-tests,tf-m-extras)
78 - string:
79 name: FETCH_SSH
80 default: 1
81 description: |
82 Fetch branches with authenticated SSH instead of anonymous HTTPS
Tomás González45c05002025-06-19 13:16:52 +010083 wrappers:
Chris Kay675db4f2025-06-24 14:14:34 +010084 - credentials-binding:
85 - ssh-user-private-key:
86 credential-id: TFA_CI_BOT_USER_SSH_KEY
87 key-file-variable: CI_BOT_KEY
88 username-variable: CI_BOT_USERNAME
89 passphrase-variable: ""
90 - timestamps
91 - timeout:
92 timeout: 240
93 fail: true
Tomás González45c05002025-06-19 13:16:52 +010094 builders:
Chris Kay675db4f2025-06-24 14:14:34 +010095 - shell: !include-raw: scripts/clone.sh
96 - shell: |
97 #!/bin/bash
98 set -ex
99 cat << EOF > tf-a-env.param
100 RF_GERRIT_PROJECT=${GERRIT_PROJECT}
101 RF_GERRIT_REFSPEC=${GERRIT_REFSPEC}
102 SHARE_FOLDER=${SHARE_FOLDER}
103 EOF
Tomás González45c05002025-06-19 13:16:52 +0100104
Chris Kay675db4f2025-06-24 14:14:34 +0100105 cd ${WORKSPACE}/rusted-firmware-a
Tomás González45c05002025-06-19 13:16:52 +0100106
Chris Kay675db4f2025-06-24 14:14:34 +0100107 # Vote Unsafe-Review+1 on patches not touching any unsafe code
Tomás González45c05002025-06-19 13:16:52 +0100108
Chris Kay675db4f2025-06-24 14:14:34 +0100109 # 1. Check if the patch touches unsafe code:
Tomás González45c05002025-06-19 13:16:52 +0100110
Chris Kay675db4f2025-06-24 14:14:34 +0100111 # if the grep command finds nothing, it will exit 1 and because we have set -e the program
112 # will fail. Doing || true makes it so that the final exit command is always 0 so the flow is not
113 # interrupted and we can check `diff` to know if the program was successful or not.
114 diff=$(echo $(git show -U10 --format=) | grep "unsafe" || true)
115 if [ "$diff" != "" ]; then
116 exit 1
117 fi
Tomás González45c05002025-06-19 13:16:52 +0100118
Chris Kay675db4f2025-06-24 14:14:34 +0100119 # 2. Cast the Unsafe-Review +1 vote if the patch does NOT touch unsafe code:
Tomás González45c05002025-06-19 13:16:52 +0100120
Chris Kay675db4f2025-06-24 14:14:34 +0100121 SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
122 GERRIT_URL="review.trustedfirmware.org"
123 SET_SAFE_CMD="${SSH_PARAMS} ${CI_BOT_USERNAME}@${GERRIT_URL} gerrit review --label Unsafe-Review=1 -m Safe"
124 ssh ${SET_SAFE_CMD} ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}