diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ef830e3..199a588 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,4 +15,11 @@ updates: interval: daily timezone: Europe/Copenhagen reviewers: - - arnested" + - arnested + - package-ecosystem: docker + directory: / + schedule: + interval: daily + timezone: Europe/Copenhagen + reviewers: + - arnested diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8d05ce3..0437949 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,12 +10,14 @@ permissions: jobs: actionlint: + name: GitHub Actions runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: reviewdog/action-actionlint@v1 + - name: Run actionlint + uses: reviewdog/action-actionlint@v1 markdownlint: - name: markdown + name: Markdown runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -26,11 +28,20 @@ jobs: **/*.md !README.md yamllint: - name: Yamllint + name: YAML runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - name: Run Yamllint + - name: Run yamllint uses: frenck/action-yamllint@v1.5.0 with: strict: true + shellcheck: + name: Shell scripts + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Run shellcheck + uses: ludeeus/action-shellcheck@2.0.0 + env: + SHELLCHECK_OPTS: -o all diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml new file mode 100644 index 0000000..f655d47 --- /dev/null +++ b/.github/workflows/readme.yml @@ -0,0 +1,40 @@ +--- +name: README +on: + - pull_request + - push + +permissions: + contents: read + +jobs: + check-readme: + name: Check README.md is up-to-date + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + tools: composer + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "${GITHUB_OUTPUT}" + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Build README.md + run: | + make README.md + - name: Check README.md + run: | + git diff --exit-code README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d4aafd9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +FROM phpdoc/phpdoc:3@sha256:eede231f3f3f0308cfaba5dd39963c55b8912f4a7cacc81baa95b274c8736ae4 diff --git a/Makefile b/Makefile index db38705..746b339 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test lint fix docs phpunit phpcs phpstan all install clean +.PHONY: test lint fix phpunit phpcs phpstan all install clean export XDEBUG_MODE=coverage @@ -8,11 +8,8 @@ lint: phpcs phpstan fix: phpcbf -docs: src vendor - docker run --user=$(shell id -u) --rm -v ".:/data" "phpdoc/phpdoc:3" - -README.md: src docs - sed 's/\(__construct.*\): mixed/\1/' < docs/classes/Reload/Cpr/CprNumber.md | grep -v '\*\*\*' | grep -v 'Automatically generated on' | sed 's/(\.\/\(.*\)\.md)/(src\/\1.php)/' | cat -s > README.md +README.md: vendor src bin/generate-readme.sh + bin/generate-readme.sh test: phpunit diff --git a/bin/generate-readme.sh b/bin/generate-readme.sh new file mode 100755 index 0000000..d2367a1 --- /dev/null +++ b/bin/generate-readme.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -euo pipefail +set -v + +PHPDOC_IMAGE_ID=$(docker build . 2>&1 >/dev/null | grep 'writing image' | cut -f 2 -d: | cut -f 1 -d ' ') + +# Build phpDoc in ./docs +docker run --user="${UID}" --rm -v ".:/data" "${PHPDOC_IMAGE_ID}" + +# Build README.md from phpDocs CprNumber documentation +( + # Fix phpDoc using mixed as return type of constructor + sed 's/\(__construct.*\): mixed/\1/' | + # Remove heavy horizontal lines + grep -v '\*\*\*' | + # Remove phpDoc "generated on" timestamp + grep -v 'Automatically generated on' | + # Fix links to phpDoc + sed 's/(\.\/\(.*\)\.md)/(src\/\1.php)/' | + # Remove empty lines + cat -s +) README.md diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml index cb5e293..964683c 100644 --- a/phpdoc.dist.xml +++ b/phpdoc.dist.xml @@ -10,16 +10,11 @@ - - NOTICE - public src/CprNumber.php - +