Skip to content

Commit 46788fa

Browse files
committed
[git-tool] do not use GITHUB_TOKEN
This commit stops using GITHUB_TOKEN in git-tool for better security.
1 parent 6e1a6ff commit 46788fa

7 files changed

Lines changed: 14 additions & 41 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ jobs:
268268
tar xf gcc-arm
269269
- name: Build
270270
env:
271-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
271+
PR_BODY: "${{ github.event.pull_request.body }}"
272272
run: |
273273
export PATH=/tmp/${{ matrix.gcc_extract_dir }}/bin:$PATH
274274
script/check-arm-build

.github/workflows/otbr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
submodules: true
6868
- name: Build OTBR Docker
6969
env:
70-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
70+
PR_BODY: "${{ github.event.pull_request.body }}"
7171
run: |
7272
./script/test build_otbr_docker
7373
- name: Bootstrap
@@ -183,7 +183,7 @@ jobs:
183183
echo "FIREWALL=0" >> $GITHUB_ENV
184184
- name: Build OTBR Docker
185185
env:
186-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
186+
PR_BODY: "${{ github.event.pull_request.body }}"
187187
TREL: ${{ matrix.otbr_trel }}
188188
run: |
189189
./script/test build_otbr_docker

.github/workflows/otns.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ env:
4646
VIRTUAL_TIME: 1
4747
VIRTUAL_TIME_UART: 1
4848
MAX_NETWORK_SIZE: 999
49-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
49+
PR_BODY: "${{ github.event.pull_request.body }}"
5050

5151
permissions: # added using https://github.com/step-security/secure-workflows
5252
contents: read

.github/workflows/posix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ jobs:
282282
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
283283
- name: Bootstrap
284284
env:
285-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
285+
PR_BODY: "${{ github.event.pull_request.body }}"
286286
run: |
287287
sudo apt-get --no-install-recommends install -y expect ninja-build lcov
288288
sudo bash script/install_socat

.github/workflows/simulation-1.1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ jobs:
318318
cache: pip
319319
- name: Bootstrap
320320
env:
321-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
321+
PR_BODY: "${{ github.event.pull_request.body }}"
322322
run: |
323323
sudo apt-get update
324324
sudo apt-get install -y avahi-daemon avahi-utils lcov

.github/workflows/toranj.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
cache: pip
7373
- name: Bootstrap
7474
env:
75-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
75+
PR_BODY: "${{ github.event.pull_request.body }}"
7676
run: |
7777
sudo apt-get update
7878
sudo apt-get --no-install-recommends install -y ninja-build lcov
@@ -107,7 +107,7 @@ jobs:
107107
cache: pip
108108
- name: Bootstrap
109109
env:
110-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
110+
PR_BODY: "${{ github.event.pull_request.body }}"
111111
run: |
112112
sudo apt-get update
113113
sudo apt-get --no-install-recommends install -y ninja-build lcov
@@ -144,7 +144,7 @@ jobs:
144144
cache: pip
145145
- name: Bootstrap
146146
env:
147-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
147+
PR_BODY: "${{ github.event.pull_request.body }}"
148148
run: |
149149
sudo apt-get update
150150
sudo apt-get --no-install-recommends install -y ninja-build
@@ -182,7 +182,7 @@ jobs:
182182
submodules: true
183183
- name: Bootstrap
184184
env:
185-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
185+
PR_BODY: "${{ github.event.pull_request.body }}"
186186
run: |
187187
brew update
188188
brew install ninja
@@ -204,7 +204,7 @@ jobs:
204204
submodules: true
205205
- name: Bootstrap
206206
env:
207-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
207+
PR_BODY: "${{ github.event.pull_request.body }}"
208208
run: |
209209
sudo apt-get update
210210
sudo apt-get --no-install-recommends install -y ninja-build lcov

script/git-tool

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,14 @@ apply_dependencies()
4747
depends_on_pr="$(echo "${dependency}" | tr -d '\r\n' | cut -d# -f2)"
4848
echo "pr: #${depends_on_pr}"
4949
git pull --no-edit --no-rebase origin "pull/${depends_on_pr}/merge"
50-
done < <(grep -E "^Depends-On: *${project_name}" || true)
51-
}
52-
53-
get_pr_body()
54-
{
55-
local pr
56-
57-
if [[ -z ${PR_BODY+x} ]]; then
58-
echo 'PR_BODY is not set' >&2
59-
else
60-
echo 'PR_BODY is set' >&2
61-
echo "${PR_BODY}"
62-
return 0
63-
fi
64-
65-
[[ ${GITHUB_ACTIONS+x} && ${GITHUB_REF-} =~ ^refs/pull/[0-9]+/merge ]] || {
66-
echo 'Not a pull request.' >&2
67-
return 0
68-
}
69-
70-
pr="$(echo "${GITHUB_REF}" | cut -d/ -f3)"
71-
72-
# do not print GITHUB_TOKEN
73-
set +x
74-
curl -H "authorization: Bearer ${GITHUB_TOKEN}" -H 'content-type: application/json' \
75-
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${pr}" \
76-
| jq -r .body
77-
set -x
50+
done < <(grep -E "^Depends-On: *${project_name}" <<<"${PR_BODY:-}" || true)
7851
}
7952

8053
try_update()
8154
{
8255
cd "$1"
8356

84-
get_pr_body | apply_dependencies
57+
apply_dependencies
8558
}
8659

8760
try_clone()
@@ -95,7 +68,7 @@ try_clone()
9568
dest_dir="$(git clone "$@" 2>&1 | tee | cut -d\' -f2)"
9669

9770
cd "${dest_dir}"
98-
get_pr_body | apply_dependencies
71+
apply_dependencies
9972
fi
10073
}
10174

0 commit comments

Comments
 (0)