diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cfa60fe96f9..08dc6b970ea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -103,3 +103,63 @@ jobs: uses: docker://oskarstark/doctor-rst with: args: --short --error-format=github --cache-file=/github/workspace/.cache/doctor-rst.cache + + symfony-code-block-checker: + name: Code Blocks + runs-on: Ubuntu-20.04 + continue-on-error: true + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set-up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + coverage: none + + - name: Fetch branch from where the PR started + run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + + - name: Find modified files + id: find-files + run: echo "::set-output name=files::$(git diff --name-only origin/${{ github.base_ref }} HEAD | grep ".rst" | tr '\n' ' ')" + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + if: ${{ steps.find-files.outputs.files }} + run: | + git clone --depth 15 https://github.com/symfony-docs-tools/code-block-checker.git ../_checker + cd ../_checker + composer install + + - name: Install test application + if: ${{ steps.find-files.outputs.files }} + run: | + git clone -b ${{ github.base_ref }} --depth 5 --single-branch https://github.com/symfony-docs-tools/symfony-application.git ../_sf_app + cd ../_sf_app + composer update + + - name: Generate baseline + if: ${{ steps.find-files.outputs.files }} + run: | + CURRENT=$(git rev-parse HEAD) + git checkout -m ${{ github.base_ref }} + ../_checker/code-block-checker.php verify:docs `pwd` ${{ steps.find-files.outputs.files }} --generate-baseline=baseline.json --symfony-application=`realpath ../_sf_app` + git checkout -m $CURRENT + cat baseline.json + + - name: Verify examples + if: ${{ steps.find-files.outputs.files }} + run: | + ../_checker/code-block-checker.php verify:docs `pwd` ${{ steps.find-files.outputs.files }} --baseline=baseline.json --output-format=github --symfony-application=`realpath ../_sf_app`