Skip to content

Commit 48e9c0a

Browse files
add new step for installing new packages. Validate package list.
1 parent ee99e4c commit 48e9c0a

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

danger/action.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: 'Path to additional dangerfile to run after the main checks'
1212
type: string
1313
required: false
14+
extra-install-packages:
15+
description: 'Additional apt packages to install in the DangerJS container (space-separated package names)'
16+
type: string
17+
required: false
1418

1519
outputs:
1620
outcome:
@@ -32,20 +36,50 @@ runs:
3236
shell: pwsh
3337
run: Get-Content '${{ github.action_path }}/danger.properties' | Tee-Object $env:GITHUB_OUTPUT -Append
3438

39+
# Validate extra-install-packages to prevent code injection
40+
- name: Validate package names
41+
if: ${{ inputs.extra-install-packages }}
42+
shell: bash
43+
run: |
44+
packages="${{ inputs.extra-install-packages }}"
45+
# Only allow alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces
46+
if ! echo "$packages" | grep -E '^[a-zA-Z0-9._+-]+( [a-zA-Z0-9._+-]+)*$' > /dev/null; then
47+
echo "::error::Invalid package names in extra-install-packages. Only alphanumeric characters, hyphens, periods, plus signs, underscores, and spaces are allowed."
48+
exit 1
49+
fi
50+
3551
# Using a pre-built docker image in GitHub container registry instead of NPM to reduce possible attack vectors.
36-
- name: Run DangerJS
37-
id: danger
52+
- name: Setup container
3853
shell: bash
3954
run: |
40-
docker run \
55+
# Start a detached container with all necessary volumes and environment variables
56+
docker run -td --name danger \
4157
--volume ${{ github.workspace }}:/github/workspace \
4258
--volume ${{ github.action_path }}:${{ github.action_path }} \
4359
--volume ${{ github.event_path }}:${{ github.event_path }} \
4460
--workdir /github/workspace \
45-
--user root \
61+
--user $(id -u) \
4662
-e "INPUT_ARGS" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true \
4763
-e GITHUB_TOKEN="${{ inputs.api-token }}" \
4864
-e DANGER_DISABLE_TRANSPILATION="true" \
4965
-e EXTRA_DANGERFILE_INPUT="${{ inputs.extra-dangerfile }}" \
5066
ghcr.io/danger/danger-js:${{ steps.config.outputs.version }} \
51-
--failOnErrors --dangerfile ${{ github.action_path }}/dangerfile.js
67+
/bin/bash
68+
69+
- name: setup additoinal packages
70+
if: ${{ inputs.extra-install-packages }}
71+
shell: bash
72+
run: |
73+
echo "Installing additional packages: ${{ inputs.extra-install-packages }}"
74+
docker exec --user root danger apt-get update -qq
75+
docker exec --user root danger apt-get install -y ${{ inputs.extra-install-packages }}
76+
77+
- name: Run DangerJS
78+
id: danger
79+
shell: bash
80+
run: |
81+
# Ensure container cleanup on exit
82+
trap "docker rm -f danger || true" EXIT
83+
84+
# Run danger with appropriate user
85+
docker exec --user $(id -u) danger danger --failOnErrors --dangerfile ${{ github.action_path }}/dangerfile.js

0 commit comments

Comments
 (0)