Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/trigger-circle-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,37 @@ jobs:
- id: trusted-author
env:
EVENT_NAME: ${{ github.event_name }}
ASSOCIATION: ${{ github.event.pull_request.author_association }}
USER_TYPE: ${{ github.event.pull_request.user.type }}
USER_LOGIN: ${{ github.event.pull_request.user.login }}
GITHUB_API_TOKEN: ${{ secrets.STORYBOOKJS_ORG_MEMBERSHIP_TOKEN }}
run: |
# You can only push to `main` and `next` as a core team member, so the content is trustworthy.
if [ "$EVENT_NAME" = "push" ]; then
echo "result=true" >> "$GITHUB_OUTPUT"
# These commits are made by the release actions, which are gated to core team members.
elif [ "$USER_LOGIN" = "github-actions[bot]" ] && [ "$USER_TYPE" = "Bot" ]; then
echo "result=true" >> "$GITHUB_OUTPUT"
# Trusted members of the organization can also write to cache (core team, DX, and a few maintainers)
elif { [ "$ASSOCIATION" = "OWNER" ] || [ "$ASSOCIATION" = "MEMBER" ]; } && [ "$USER_TYPE" != "Bot" ]; then
echo "result=true" >> "$GITHUB_OUTPUT"
else
echo "result=false" >> "$GITHUB_OUTPUT"
# Explicitly trust only members of specific Storybook teams.
# Team slugs for: Maintainers, Core, Developer Experience.
TRUSTED_TEAMS="maintainers core developer-experience"
IS_TRUSTED=false

for TEAM in $TRUSTED_TEAMS; do
STATE=$(curl -fsSL \
-H "Authorization: Bearer $GITHUB_API_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/storybookjs/teams/$TEAM/memberships/$USER_LOGIN" \
| jq -r '.state' 2>/dev/null || true)

if [ "$STATE" = "active" ]; then
IS_TRUSTED=true
break
fi
done

echo "result=$IS_TRUSTED" >> "$GITHUB_OUTPUT"
fi
outputs:
workflow: ${{ steps.normal.outputs.workflow || steps.docs.outputs.workflow || steps.merged.outputs.workflow || steps.daily.outputs.workflow }}
Expand All @@ -129,12 +145,14 @@ jobs:
WORKFLOW: ${{ needs.get-parameters.outputs.workflow }}
GH_BASE_BRANCH: ${{ needs.get-parameters.outputs.ghBaseBranch }}
GH_PR_NUMBER: ${{ needs.get-parameters.outputs.ghPrNumber }}
GH_TRUSTED_AUTHOR: ${{ needs.get-parameters.outputs.ghTrustedAuthor }}
run: |
PARAMETERS=$(jq -nc \
--arg workflow "$WORKFLOW" \
--arg ghBaseBranch "$GH_BASE_BRANCH" \
--arg ghPrNumber "$GH_PR_NUMBER" \
'{workflow: $workflow, ghBaseBranch: $ghBaseBranch, ghPrNumber: $ghPrNumber}')
--arg ghTrustedAuthor "$GH_TRUSTED_AUTHOR" \
'{workflow: $workflow, ghBaseBranch: $ghBaseBranch, ghPrNumber: $ghPrNumber, ghTrustedAuthor: $ghTrustedAuthor}')
PAYLOAD=$(jq -nc --arg branch "$BRANCH" --argjson parameters "$PARAMETERS" \
'{branch: $branch, parameters: $parameters}')
curl -sS --fail-with-body -X POST \
Expand Down