Skip to content

Commit 6918e6f

Browse files
committed
do not trigger workflow automatically for forks
1 parent d25367f commit 6918e6f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/upload-dev-build.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ env:
1818
jobs:
1919
upload:
2020
runs-on: ubuntu-latest
21+
# Only run on manual dispatch,
22+
# OR if the parent run succeeded and was triggered by a PR from
23+
# a branch in the main repo (not a fork)
2124
if: |
2225
github.event_name == 'workflow_dispatch' ||
2326
(
2427
github.event_name == 'workflow_run' &&
2528
github.event.workflow_run.event == 'pull_request' &&
26-
github.event.workflow_run.conclusion == 'success'
29+
github.event.workflow_run.conclusion == 'success' &&
30+
github.event.workflow_run.head_repository.full_name == github.repository
2731
)
2832
steps:
2933
- name: Get required metadata (PR number, commit SHA, workflow run ID containing artifacts)
@@ -49,7 +53,7 @@ jobs:
4953
exit 1
5054
fi
5155
52-
# If PR_NUM is empty (this is the case for forks) get PR number using SHA
56+
# If PR_NUM is empty, get PR number using SHA
5357
if [ -z "${PR_NUM}" ]; then
5458
PR_NUM=$(gh pr list --search "sha:${SHA}" --state open --json number --jq '.[0].number')
5559
fi
@@ -139,15 +143,16 @@ jobs:
139143
run: |
140144
# Move 'pr-NNNN/' directory into upload directory inside repo and cd into repo root
141145
TARGET_DIR="${UPLOAD_DIR_NAME}/pr-${PR_NUM}"
142-
cp -r ${TARGET_DIR} plotly.js-dev-builds/
146+
mkdir -p "plotly.js-dev-builds/${UPLOAD_DIR_NAME}"
147+
cp -r "${TARGET_DIR}" "plotly.js-dev-builds/${UPLOAD_DIR_NAME}"
143148
cd plotly.js-dev-builds
144149
145150
# Configure git
146151
git config user.name "plotly.js-pr-upload"
147152
git config user.email "<>"
148153
149154
# Add files
150-
git add ${TARGET_DIR}/
155+
git add "${TARGET_DIR}/"
151156
152157
# Ensure that only files in upload/pr-NNNN/ are staged
153158
if git diff --name-only --cached | grep -qv "^${TARGET_DIR}/"; then

0 commit comments

Comments
 (0)