diff --git a/.github/actions/deploy/create-version.sh b/.github/actions/deploy/create-version.sh deleted file mode 100755 index 1ee86d528..000000000 --- a/.github/actions/deploy/create-version.sh +++ /dev/null @@ -1,85 +0,0 @@ -#! /bin/bash -e - -# set -x - -if [ $# -lt 1 ]; then - echo "Please provide the name of a file to read the commit message from" - exit 1 -fi - -deploy_path='.github/actions/deploy' - -stable_branch=$(cat "$deploy_path/stable_name") -master_branch=master - -major=$(cat "$deploy_path/major") -minor=$(cat "$deploy_path/minor") -patch=$(cat "$deploy_path/patch") - -# release -message="$(cat "$1")" - -parse_pre_release () { - echo "$1" | grep -E '%PRE-?RELEASE%' | head -n 1 | sed -E 's@.*%PRE-?RELEASE%([^%]+)%.*@\1@' -} - -if echo "$message" | grep '%MAJOR%' > /dev/null ; then - - echo 'Creating major version' - let major=major+1 - minor=0 - patch=0 - -elif echo "$message" | grep '%MINOR%' > /dev/null; then - - echo 'Creating minor version' - let minor=minor+1 - patch=0 - -else - - echo 'Creating patch version' - let patch=patch+1 - -fi - -prerelease="$(parse_pre_release "$message")" -version="$major.$minor.$patch" - -if [ -n "$prerelease" ]; then - # We want to build a pre-release - echo "Not Updating the version files as we are creating a pre-release." - version="$version-$prerelease" -else - echo "Updating bumped version files" - echo $major > "$deploy_path/major" - echo $minor > "$deploy_path/minor" - echo $patch > "$deploy_path/patch" -fi - -echo "The new version is $version." - -echo "Storing new release version in $deploy_path/last_release" -echo "$version" > "$deploy_path/last_release" - -"$deploy_path/update-data.sh" "$version" "$major" "$minor" "$patch" "$prerelease" - -git add "$deploy_path/major" "$deploy_path/minor" "$deploy_path/patch" "$deploy_path/last_release" - -# exit - -git config user.name 'Github actions bot' -git config user.email 'bot@noreply.github.com' - -git commit -s -m "Bump to version $version" -git tag "v$version" - -git checkout $master_branch -git merge --no-ff $stable_branch - -git remote add tokenized "https://nextcloud-cookbook-bot:$BOT_TOKEN@github.com/nextcloud/cookbook.git" - -git -c "http.https://github.com/.extraheader=" push tokenized $stable_branch $master_branch -git push origin "v$version" - -echo "version=$version" >> $GITHUB_OUTPUT diff --git a/.github/actions/php-linter/Dockerfile b/.github/actions/php-linter/Dockerfile new file mode 100644 index 000000000..e920ff9c7 --- /dev/null +++ b/.github/actions/php-linter/Dockerfile @@ -0,0 +1,5 @@ +FROM php:7.4 + +COPY tester.sh /tester.sh + +CMD ["/tester.sh", "/work"] diff --git a/.github/actions/php-linter/tester.sh b/.github/actions/php-linter/tester.sh new file mode 100755 index 000000000..4ae0685e4 --- /dev/null +++ b/.github/actions/php-linter/tester.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +cd "$1" + +ret=0 + +while IFS= read -d '' file +do + php -l "$file" > /tmp/msg + retSingle=$? + + if [ $retSingle -eq 0 ] + then + cat /tmp/msg | sed 's@^@::debug::@' + else + ret=1 + msg="$(cat /tmp/msg)" + echo "$msg" | sed 's@^\s*$@@' | grep -v '^$' > /tmp/msg + line=$(cat /tmp/msg | grep -o ' on line [0-9]*' | sed -E 's@ on line ([0-9]*)$@\1@') + prefix="::error file=$file,line=$line,title=PHP linter failed::" + sed "s@^@$prefix@" /tmp/msg + fi +done < <(find lib -type f -name '*.php' -print0) + +exit $ret diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index b2b794664..b35188a19 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -67,7 +67,7 @@ jobs: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-22.04 - if: github.event.ref == 'refs/heads/master' + if: github.event.ref == 'refs/heads/master' && github.repository == 'nextcloud/cookbook' needs: build steps: - name: Deploy to GitHub Pages diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3455a8c77..fc42f49c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -370,9 +370,6 @@ jobs: source-package: name: Create source code artifacts - needs: - - unit-tests - - code-lint runs-on: ubuntu-22.04 steps: @@ -443,4 +440,30 @@ jobs: path: ${{ github.event_path }} retention-days: 1 + lint-php: + name: "Lint PHP files to be compatible" + runs-on: ubuntu-22.04 + defaults: + run: + shell: bash + steps: + - name: Checkout of the app + uses: actions/checkout@v4 + - name: build docker container image + run: docker build -t php-lint-tester .github/actions/php-linter + - name: Check the code base + run: docker run --rm -v $(pwd):/work:ro php-lint-tester + successful_run: + name: The tests have successfully run + runs-on: ubuntu-22.04 + needs: + - unit-tests + - code-lint + - source-package + - lint-php + - event_file + steps: + - name: Run successfully + shell: bash + run: echo "The tests have been running successfully" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ccddce55..60857645f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Maintenance +- Add PHP lint checker to ensure valid (legacy) PHP syntax + [#1931](https://github.com/nextcloud/cookbook/pull/1931) @christianlupus + ## 0.10.3 - 2023-12-04 diff --git a/lib/Helper/Filter/JSON/AbstractJSONFilter.php b/lib/Helper/Filter/JSON/AbstractJSONFilter.php index 0ffaea89a..352983a7e 100644 --- a/lib/Helper/Filter/JSON/AbstractJSONFilter.php +++ b/lib/Helper/Filter/JSON/AbstractJSONFilter.php @@ -26,7 +26,7 @@ abstract public function apply(array &$json): bool; /** * @param string|int|float|array $value */ - protected function setJSONValue(array &$json, string $key, string|int|float|array $value): bool { + protected function setJSONValue(array &$json, string $key, $value): bool { if (!array_key_exists($key, $json)) { $json[$key] = $value; return true; diff --git a/lib/Helper/Filter/Output/RecipeStubFilter.php b/lib/Helper/Filter/Output/RecipeStubFilter.php index a02df79a2..8e38efcf9 100644 --- a/lib/Helper/Filter/Output/RecipeStubFilter.php +++ b/lib/Helper/Filter/Output/RecipeStubFilter.php @@ -12,7 +12,7 @@ class RecipeStubFilter { public function __construct( RecipeIdTypeFilter $recipeIdTypeFilter, - RecipeIdCopyFilter $recipeIdCopyFilter, + RecipeIdCopyFilter $recipeIdCopyFilter ) { $this->filters = [ $recipeIdCopyFilter, diff --git a/lib/Helper/TimestampHelper.php b/lib/Helper/TimestampHelper.php index 4f19a2287..a9836a3f8 100644 --- a/lib/Helper/TimestampHelper.php +++ b/lib/Helper/TimestampHelper.php @@ -45,7 +45,7 @@ public function parseTimestamp(string $timestamp): string { // For now, we only support the ISO8601 format because it is required in the schema.org standard try { return $this->parseIsoFormat($timestamp); - } catch (InvalidTimestampException) { + } catch (InvalidTimestampException $ex) { // We do nothing here. Check the next format } @@ -65,15 +65,15 @@ public function parseTimestamp(string $timestamp): string { private function parseIsoFormat(string $timestamp): string { try { return $this->parseIsoCalendarDateFormat($timestamp, '-'); - } catch (InvalidTimestampException) { // Check next format + } catch (InvalidTimestampException $ex) { // Check next format } try { return $this->parseIsoCalendarDateFormat($timestamp, ''); - } catch (InvalidTimestampException) { // Check next format + } catch (InvalidTimestampException $ex) { // Check next format } try { return $this->parseIsoWeekDateFormat($timestamp, '-'); - } catch (InvalidTimestampException) { // Check next format + } catch (InvalidTimestampException $ex) { // Check next format } return $this->parseIsoWeekDateFormat($timestamp, '');