Skip to content

Commit 33b7b78

Browse files
Add logic for handling VCS-type repos/dependencies
Checks composer.json for VCS-type repos before composer install Validates token presence if private deps are found Fails with clear error if token is needed but missing Uses token conditionally - only if it exists Updated documentation in comments about when COMPOSER_GITHUB_TOKEN is needed Note: I made the workflow name generic ("Drupal - Security Review"). If there's a reason we should be more specific, please change it back.
1 parent 6bc1ba7 commit 33b7b78

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

.github/workflows/composer-audit.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: D10 - Security Review
1+
name: Drupal - Security Review
22
# Required Secrets (same across projects):
33
# EMAIL_USERNAME: Gmail address for sending notifications (i.e. [email protected])
44
# EMAIL_PASSWORD: Gmail App Password (no spaces)
5+
# COMPOSER_GITHUB_TOKEN: (Conditional) GitHub Personal Access Token ("PAT") with 'repo' scope - only needed if composer.json has private VCS dependencies. A classic PAT is recommended. More info here: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
56
# **Details are stored in the 1password vault named "Production".**
67
#
78
# Required Variables (unique per project):
@@ -19,6 +20,25 @@ jobs:
1920
- name: "Checkout code"
2021
uses: actions/checkout@v4
2122

23+
- name: Check if private composer dependencies exist
24+
id: check_private_deps
25+
run: |
26+
if grep -q '"type"[[:space:]]*:[[:space:]]*"vcs"' composer.json; then
27+
echo "has_private_deps=true" >> $GITHUB_OUTPUT
28+
echo "⚠️ This project uses private VCS dependencies"
29+
else
30+
echo "has_private_deps=false" >> $GITHUB_OUTPUT
31+
echo "✅ This project uses only public dependencies"
32+
fi
33+
34+
- name: Validate composer authentication
35+
if: steps.check_private_deps.outputs.has_private_deps == 'true' && !secrets.COMPOSER_GITHUB_TOKEN
36+
run: |
37+
echo "::error::This project requires private composer dependencies but COMPOSER_GITHUB_TOKEN secret is not set."
38+
echo "::error::Please add COMPOSER_GITHUB_TOKEN secret with a GitHub Personal Access Token that has 'repo' scope."
39+
echo "::error::Generate at: https://github.com/settings/tokens"
40+
exit 1
41+
2242
- name: Install PHP with extensions
2343
uses: shivammathur/[email protected]
2444
with:
@@ -27,6 +47,8 @@ jobs:
2747
tools: composer:v2
2848

2949
- name: "Composer install"
50+
env:
51+
COMPOSER_AUTH: ${{ secrets.COMPOSER_GITHUB_TOKEN && format('{{"github-oauth":{{"github.com":"{0}"}}}}', secrets.COMPOSER_GITHUB_TOKEN) || '{}' }}
3052
uses: "ramsey/[email protected]"
3153
with:
3254
composer-options: "--prefer-dist"

0 commit comments

Comments
 (0)