-
Notifications
You must be signed in to change notification settings - Fork 179
Behat tests with Github Actions #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,53 +37,74 @@ jobs: | |
| - name: Run tests | ||
| run: composer run phpunit -- --no-coverage | ||
|
|
||
| # This does not work | ||
| # behat: | ||
| # name: Tests (Behat with PHP ${{ matrix.php }}) | ||
| # runs-on: ubuntu-latest | ||
|
|
||
| # services: | ||
| # redmine-6-0: | ||
| # image: redmine:6.0.7 | ||
| # ports: | ||
| # - "5060:3000" | ||
| # env: | ||
| # # Workaround: Remove secret for Rails 7.2 so it will be generated automatically | ||
| # # @see https://github.com/docker-library/redmine/issues/349#issuecomment-2516634932 | ||
| # # REDMINE_SECRET_KEY_BASE: supersecretkey | ||
| # REDMINE_PLUGINS_MIGRATE: true | ||
| # volumes: | ||
| # - /home/runner/work/_temp/redmine-60007_data/files:/usr/src/redmine/files | ||
| # - /home/runner/work/_temp/redmine-60007_data/sqlite:/usr/src/redmine/sqlite | ||
| # options: --health-cmd="wget -O /dev/null http://localhost:3000" --health-start-period=30s --health-interval=30s --health-timeout=30s --health-retries=3 | ||
|
|
||
| # strategy: | ||
| # fail-fast: false | ||
| # matrix: | ||
| # operating-system: ["ubuntu-latest"] | ||
| # php: ["8.3"] | ||
|
|
||
| # steps: | ||
| # - name: Checkout | ||
| # uses: actions/checkout@v4 | ||
| # with: | ||
| # fetch-depth: 2 | ||
|
|
||
| # - name: Setup PHP, with composer and extensions | ||
| # uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php | ||
| # with: | ||
| # php-version: ${{ matrix.php }} | ||
| # tools: phpunit | ||
| # extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite | ||
| # coverage: xdebug | ||
|
|
||
| # # Install composer dependencies and handle caching in one go. | ||
| # # @link https://github.com/marketplace/actions/install-composer-dependencies | ||
| # - name: "Install Composer dependencies" | ||
| # uses: "ramsey/composer-install@v2" | ||
|
|
||
| # - name: Run behat | ||
| # run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --suite=redmine_6_0 | ||
| behat: | ||
| name: Tests (Behat with PHP ${{ matrix.php }}) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| operating-system: ["ubuntu-latest"] | ||
| php: ["8.3"] | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 2 | ||
|
|
||
| - name: Setup PHP, with composer and extensions | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php }} | ||
| tools: phpunit | ||
| extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, curl | ||
| coverage: xdebug | ||
|
|
||
| - name: Install Composer dependencies | ||
| uses: ramsey/composer-install@v2 | ||
|
Comment on lines
+51
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".github/workflows/tests.yml"
echo "Potentially unpinned uses: references (not full 40-char SHA):"
rg -n '^\s*uses:\s*[^@]+@(?![0-9a-fA-F]{40}\b).+$' "$file" || true
echo
echo "Checkout steps missing persist-credentials: false (manual check context shown):"
rg -n -A6 -B1 'uses:\s*actions/checkout@' "$file"Repository: kbsali/php-redmine-api Length of output: 1278 🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".github/workflows/tests.yml"
echo "=== All 'uses:' references in the file ==="
rg -n 'uses:' "$file"
echo
echo "=== Lines 51-65 (target of review) ==="
sed -n '51,65p' "$file" | cat -n
echo
echo "=== Count of unpinned vs pinned actions ==="
echo "Using version tags (unpinned):"
rg 'uses:.*`@v`[0-9]' "$file" | wc -l
echo "Using full SHAs (pinned):"
rg 'uses:.*@[0-9a-fA-F]{40}' "$file" | wc -lRepository: kbsali/php-redmine-api Length of output: 1328 🌐 Web query:
💡 Result: Pinning GitHub Actions to a full-length commit SHA is a critical security best practice to prevent supply chain attacks, such as tag hijacking or malicious code injection [1][2][3]. Why Pinning to SHA is Required GitHub Actions referenced by tags (e.g., Citations:
🌐 Web query:
💡 Result: Setting persist-credentials: false in the actions/checkout GitHub Action is considered a security best practice to minimize the risk of credential exposure [1][2]. By default, actions/checkout configures the local Git environment with the authentication token (such as the GITHUB_TOKEN) used to clone the repository [3][4]. This makes the token available to any subsequent steps or scripts running within the same job, as they can read it from the Git configuration [5][2]. If a workflow step is compromised or if the repository is inadvertently archived and uploaded as an artifact, this token could be exposed [6][2]. To mitigate this risk, you should explicitly disable this behavior when the token is not required for subsequent Git operations [1]: - uses: actions/checkout@v4 with: persist-credentials: false While recent updates to actions/checkout have improved security by moving these credentials to a separate file in $RUNNER_TEMP rather than directly in.git/config [3][7], setting persist-credentials: false remains the recommended approach to follow the principle of least privilege and prevent unnecessary credential persistence [1][2]. If your workflow does not need to perform authenticated Git operations (like git push or git submodule updates) after the initial checkout, there is no reason to keep the credentials active [1]. Citations:
Pin action references to full commit SHAs and add All actions in this workflow use version tags ( 🧰 Tools🪛 zizmor (1.25.2)[warning] 51-54: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) [error] 52-52: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) [error] 57-57: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) [error] 65-65: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) 🤖 Prompt for AI Agents |
||
|
|
||
| - name: Create data directories | ||
| run: | | ||
| mkdir -p .docker/redmine-60101_data/{files,sqlite} | ||
| mkdir -p .docker/redmine-60008_data/{files,sqlite} | ||
| mkdir -p .docker/redmine-50111_data/{files,sqlite} | ||
| chmod -R 777 .docker/redmine-*_data/ | ||
|
|
||
| - name: Start Redmine containers | ||
| run: docker compose up -d redmine-6-1 redmine-6-0 redmine-5-1 | ||
|
|
||
| - name: Wait for Redmine instances to be healthy | ||
| run: | | ||
| for i in $(seq 1 60); do | ||
| if curl -sf http://localhost:5061 > /dev/null 2>&1 && \ | ||
| curl -sf http://localhost:5060 > /dev/null 2>&1 && \ | ||
| curl -sf http://localhost:5051 > /dev/null 2>&1; then | ||
| echo "All Redmine instances are ready" | ||
| exit 0 | ||
| fi | ||
| echo "Waiting for Redmine instances... ($i/60)" | ||
| sleep 5 | ||
| done | ||
| echo "Redmine instances did not become ready in time" | ||
| docker compose logs redmine-6-1 redmine-6-0 redmine-5-1 | ||
| exit 1 | ||
|
|
||
| - name: Fix permissions | ||
| run: sudo chmod -R 777 .docker/redmine-*_data/ | ||
|
|
||
| - name: Run behat [Redmine 6.1] | ||
| run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_6_1 | ||
|
|
||
| - name: Run behat [Redmine 6.0] | ||
| run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_6_0 | ||
|
|
||
| - name: Run behat [Redmine 5.1] | ||
| run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_5_1 | ||
|
|
||
| - name: Cleanup | ||
| if: always() | ||
| run: docker compose down -v | ||
|
|
||
| code-quality: | ||
| name: Check ${{ matrix.tool }} (PHP ${{ matrix.php }}) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restrict token scope for the new
behatjob.Add a
permissionsblock with least privilege so this job doesn’t inherit broad defaultGITHUB_TOKENpermissions.🔧 Proposed fix
behat: name: Tests (Behat with PHP ${{ matrix.php }}) runs-on: ubuntu-latest + permissions: + contents: read📝 Committable suggestion
🧰 Tools
🪛 zizmor (1.25.2)
[warning] 40-107: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block
(excessive-permissions)
🤖 Prompt for AI Agents