Skip to content
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

Add CI checks #81

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions .github/workflows/fixup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Block fixup and squash commits

on:
pull_request:
types: [opened, ready_for_review, reopened, synchronize]

permissions:
contents: read

concurrency:
group: fixup-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
commit-message-check:
if: github.event.pull_request.draft == false

permissions:
pull-requests: write
name: Block fixup and squash commits

runs-on: ubuntu-latest

steps:
- name: Run check
uses: skjnldsv/block-fixup-merge-action@42d26e1b536ce61e5cf467d65fb76caf4aa85acf # v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

41 changes: 41 additions & 0 deletions .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Lint php-cs

on: pull_request

permissions:
contents: read

concurrency:
group: lint-php-cs-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: php-cs

steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Set up php
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2
with:
php-version: 8.1
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer i

- name: Lint
run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )

63 changes: 63 additions & 0 deletions .github/workflows/psalm-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Static analysis

on:
pull_request:
push:
branches:
- master
- main
- stable*

concurrency:
group: psalm-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
static-analysis:
runs-on: ubuntu-latest
strategy:
# do not stop on another job's failure
fail-fast: false
matrix:
ocp-version: [ 'dev-master', 'dev-stable27', 'dev-stable26' ]

name: Nextcloud ${{ matrix.ocp-version }}
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Set up php
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2
with:
php-version: 8.0
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer i

- name: Install dependencies
run: composer require --dev nextcloud/ocp:${{ matrix.ocp-version }} --ignore-platform-reqs --with-dependencies

- name: Run coding standards check
run: composer run psalm

summary:
runs-on: ubuntu-latest
needs: static-analysis

if: always()

name: static-psalm-analysis-summary

steps:
- name: Summary status
run: if ${{ needs.static-analysis.result != 'success' }}; then exit 1; fi

6 changes: 3 additions & 3 deletions lib/LoginHookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function matchCidr(string $ip, string $range): bool {
$bits = 128;
}

$binMask = str_repeat("f", $bits / 4);
$binMask = str_repeat("f", (int) ($bits / 4));
switch ($bits % 4) {
case 0:
break;
Expand Down Expand Up @@ -102,8 +102,8 @@ private function matchCidr(string $ip, string $range): bool {
* @return bool
*/
public function isLoginAllowed(): bool {
$allowedRanges = (string) $this->config->getAppValue('limit_login_to_ip', 'whitelisted.ranges', '');
if($allowedRanges === '') {
$allowedRanges = $this->config->getAppValue('limit_login_to_ip', 'whitelisted.ranges', '');
if ($allowedRanges === '') {
return true;
}
$allowedRanges = explode(',', $allowedRanges);
Expand Down
1 change: 1 addition & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

use Behat\Behat\Context\Context;
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/LoginHookListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ protected function setUp(): void {
* @dataProvider ipSubnetProvider
*/
public function testMatchRange(string $ipAddress, ?string $subnet, bool $shouldBeTrue): void {
if (!empty($subnet)) {
$this->config->expects($this->once())
->method('getAppValue')
->with('limit_login_to_ip', 'whitelisted.ranges', null)
->willReturn($subnet);
$this->config->expects($this->once())
->method('getAppValue')
->with('limit_login_to_ip', 'whitelisted.ranges', '')
->willReturn($subnet);
if ($subnet !== '') {
$this->request
->expects($this->once())
->method('getRemoteAddress')
Expand All @@ -77,7 +77,6 @@ public function testMatchRange(string $ipAddress, ?string $subnet, bool $shouldB

public function ipSubnetProvider(): array {
return [
['1.2.3.4', null, true],
['1.2.3.4', '', true],
['1.2.3.4', '1.2.3.4', true],
['1.2.3.4', '1.2.3.4/32', true],
Expand Down