From eb94abda71c81c94c8b5edf26d135b3dc2dc858a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 24 Jan 2022 10:15:09 +0100 Subject: [PATCH] Enhancement: Synchronize with ergebnis/php-package-template --- .../determine-cache-directory/action.yaml | 16 ---- .../composer/composer/install/action.yaml | 22 ----- .../actions/composer/composer/install/run.sh | 25 ------ .github/workflows/integrate.yaml | 56 ++++++++----- .github/workflows/merge.yaml | 80 +++++++++++-------- .github/workflows/release.yaml | 26 +++--- .github/workflows/renew.yaml | 14 ++-- .github/workflows/triage.yaml | 29 ++++--- 8 files changed, 124 insertions(+), 144 deletions(-) delete mode 100644 .github/actions/composer/composer/determine-cache-directory/action.yaml delete mode 100644 .github/actions/composer/composer/install/action.yaml delete mode 100755 .github/actions/composer/composer/install/run.sh diff --git a/.github/actions/composer/composer/determine-cache-directory/action.yaml b/.github/actions/composer/composer/determine-cache-directory/action.yaml deleted file mode 100644 index 4842e88..0000000 --- a/.github/actions/composer/composer/determine-cache-directory/action.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action -# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs -# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions -# https://getcomposer.org/doc/03-cli.md#composer-cache-dir - -name: "Determine composer cache directory" - -description: "Determines the composer cache directory and exports it as COMPOSER_CACHE_DIR environment variable" - -runs: - using: "composite" - - steps: - - name: "Determine composer cache directory" - shell: "bash" - run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV" diff --git a/.github/actions/composer/composer/install/action.yaml b/.github/actions/composer/composer/install/action.yaml deleted file mode 100644 index bab262e..0000000 --- a/.github/actions/composer/composer/install/action.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action -# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs -# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions - -name: "Install dependencies with composer" - -description: "Installs dependencies with composer" - -inputs: - dependencies: - description: "Which dependencies to install, one of \"lowest\", \"locked\", \"highest\"" - required: true - -runs: - using: "composite" - - steps: - - name: "Install ${{ inputs.dependencies }} dependencies with composer" - shell: "bash" - run: "${{ github.action_path }}/run.sh" - env: - COMPOSER_INSTALL_DEPENDENCIES: "${{ inputs.dependencies }}" diff --git a/.github/actions/composer/composer/install/run.sh b/.github/actions/composer/composer/install/run.sh deleted file mode 100755 index 3c614ab..0000000 --- a/.github/actions/composer/composer/install/run.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -dependencies="${COMPOSER_INSTALL_DEPENDENCIES}" - -if [[ ${dependencies} == "lowest" ]]; then - composer update --no-interaction --no-progress --prefer-lowest - - exit $? -fi - -if [[ ${dependencies} == "locked" ]]; then - composer install --no-interaction --no-progress - - exit $? -fi - -if [[ ${dependencies} == "highest" ]]; then - composer update --no-interaction --no-progress - - exit $? -fi - -echo "::error::The value for the \"dependencies\" input needs to be one of \"lowest\", \"locked\", \"highest\" - got \"${dependencies}\" instead." - -exit 1 diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 7cf387f..aa8f947 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -8,9 +8,6 @@ on: # yamllint disable-line rule:truthy branches: - "main" -env: - PHP_EXTENSIONS: "mbstring" - jobs: code-coverage: name: "Code Coverage" @@ -33,14 +30,17 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "xdebug" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Set up problem matchers for phpunit/phpunit" run: "echo \"::add-matcher::${{ runner.tool_cache }}/phpunit.json\"" - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -50,11 +50,13 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" - name: "Collect code coverage with Xdebug and phpunit/phpunit" + env: + XDEBUG_MODE: "coverage" run: "vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml" - name: "Send code coverage report to Codecov.io" @@ -90,14 +92,17 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "none" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Validate composer.json and composer.lock" - run: "composer validate --strict" + run: "composer validate --ansi --strict" - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -107,12 +112,12 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" - name: "Run ergebnis/composer-normalize" - run: "composer normalize --dry-run" + run: "composer normalize --ansi --dry-run" - name: "Create cache directory for friendsofphp/php-cs-fixer" run: "mkdir -p .build/php-cs-fixer" @@ -148,11 +153,14 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "none" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -162,7 +170,7 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" @@ -190,11 +198,14 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "none" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, curl, dom, json, mbstring, pcntl, phar, posix, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -204,7 +215,7 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" @@ -212,7 +223,7 @@ jobs: run: "mkdir -p .build/psalm" - name: "Run vimeo/psalm" - run: "vendor/bin/psalm --config=psalm.xml --diff --shepherd --show-info=false --stats --threads=4" + run: "vendor/bin/psalm --config=psalm.xml --output-format=github --shepherd --show-info=false --stats --threads=4" tests: name: "Tests" @@ -239,14 +250,17 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "none" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Set up problem matchers for phpunit/phpunit" run: "echo \"::add-matcher::${{ runner.tool_cache }}/phpunit.json\"" - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -256,7 +270,7 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml index 6aa0781..41cffc0 100644 --- a/.github/workflows/merge.yaml +++ b/.github/workflows/merge.yaml @@ -29,65 +29,77 @@ jobs: with: github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" script: | - const pullRequest = context.payload.workflow_run.pull_requests[0] - const repository = context.repo + const pullRequest = context.payload.workflow_run.pull_requests[0]; const reviewers = [ "ergebnis-bot", - ] + ]; - await github.rest.pulls.requestReviewers({ - owner: repository.owner, - repo: repository.repo, - pull_number: pullRequest.number, - reviewers: reviewers, - }) + try { + await github.rest.pulls.requestReviewers({ + owner: context.repo.owner, + pull_number: pullRequest.number, + repo: context.repo.repo, + reviewers: reviewers, + }); + } catch (error) { + core.setFailed(error.message); + } - name: "Assign @ergebnis-bot" uses: "actions/github-script@v5" with: github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" script: | - const pullRequest = context.payload.workflow_run.pull_requests[0] - const repository = context.repo + const pullRequest = context.payload.workflow_run.pull_requests[0]; const assignees = [ "ergebnis-bot", - ] + ]; - await github.rest.issues.addAssignees({ - owner: repository.owner, - repo: repository.repo, - assignees: assignees, - issue_number: pullRequest.number - }) + try { + await github.rest.issues.addAssignees({ + assignees: assignees, + issue_number: pullRequest.number + owner: context.repo.owner, + repo: context.repo.repo, + }); + } catch (error) { + core.setFailed(error.message); + } - name: "Approve pull request" uses: "actions/github-script@v5" with: github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" script: | - const pullRequest = context.payload.workflow_run.pull_requests[0] - const repository = context.repo + const pullRequest = context.payload.workflow_run.pull_requests[0]; - await github.rest.pulls.createReview({ - event: "APPROVE", - owner: repository.owner, - repo: repository.repo, - pull_number: pullRequest.number, - }) + try { + await github.rest.pulls.createReview({ + event: "APPROVE", + owner: context.repo.owner, + pull_number: pullRequest.number, + repo: context.repo.repo, + }); + } catch (error) { + core.setFailed(error.message); + } - name: "Merge pull request" uses: "actions/github-script@v5" with: github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" script: | - const pullRequest = context.payload.workflow_run.pull_requests[0] - const repository = context.repo + const pullRequest = context.payload.workflow_run.pull_requests[0]; - await github.rest.pulls.merge({ - merge_method: "merge", - owner: repository.owner, - pull_number: pullRequest.number, - repo: repository.repo, - }) + try { + await github.rest.pulls.merge({ + merge_method: "merge", + owner: context.repo.owner, + pull_number: pullRequest.number, + repo: context.repo.repo, + }); + } catch (error) { + core.setFailed(error.message); + } diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 11ff85a..318dd2d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,15 +15,23 @@ jobs: steps: - name: "Determine tag" - id: "determine-tag" - run: "echo \"::set-output name=tag::${GITHUB_REF#refs/tags/}\"" + run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" - name: "Create release" - uses: "actions/create-release@v1.1.4" - env: - GITHUB_TOKEN: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + uses: "actions/github-script@v5" with: - draft: false - prerelease: false - release_name: "${{ steps.determine-tag.outputs.tag }}" - tag_name: "${{ steps.determine-tag.outputs.tag }}" + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + try { + await github.rest.repos.createRelease({ + draft: false, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: false, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + } catch (error) { + core.setFailed(error.message); + } diff --git a/.github/workflows/renew.yaml b/.github/workflows/renew.yaml index 5c52016..ad9b7b4 100644 --- a/.github/workflows/renew.yaml +++ b/.github/workflows/renew.yaml @@ -6,9 +6,6 @@ on: # yamllint disable-line rule:truthy schedule: - cron: "0 0 1 1 *" -env: - PHP_EXTENSIONS: "mbstring" - jobs: license: name: "License" @@ -33,14 +30,17 @@ jobs: uses: "shivammathur/setup-php@2.16.0" with: coverage: "none" - extensions: "${{ env.PHP_EXTENSIONS }}" + extensions: "none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" php-version: "${{ matrix.php-version }}" + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + - name: "Validate composer.json and composer.lock" - run: "composer validate --strict" + run: "composer validate --ansi --strict" - name: "Determine composer cache directory" - uses: "./.github/actions/composer/composer/determine-cache-directory" + uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.2.1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2.1.7" @@ -50,7 +50,7 @@ jobs: restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install ${{ matrix.dependencies }} dependencies with composer" - uses: "./.github/actions/composer/composer/install" + uses: "ergebnis/.github/actions/composer/install@1.2.1" with: dependencies: "${{ matrix.dependencies }}" diff --git a/.github/workflows/triage.yaml b/.github/workflows/triage.yaml index d606e92..a1ba09b 100644 --- a/.github/workflows/triage.yaml +++ b/.github/workflows/triage.yaml @@ -22,24 +22,33 @@ jobs: const branchPrefixLabels = { feature: "enhancement", fix: "bug", - } + }; - const pullRequest = context.payload.pull_request - const repository = context.repo + const pullRequest = context.payload.pull_request; - const branchName = pullRequest.head.ref + const branchName = pullRequest.head.ref; const matches = branchName.match(new RegExp('^([^/]+)\/')); - if (matches instanceof Array && branchPrefixLabels.hasOwnProperty(matches[1])) { - const label = branchPrefixLabels[matches[1]] + if (!matches instanceof Array) { + return; + } + + if (!branchPrefixLabels.hasOwnProperty(matches[1])) { + return; + } + + const label = branchPrefixLabels[matches[1]]; - github.rest.issues.addLabels({ + try { + await github.rest.issues.addLabels({ issue_number: pullRequest.number, labels: [ - label + label, ], - owner: repository.owner, - repo: repository.repo, + owner: context.repo.owner, + repo: context.repo.repo, }); + } catch (error) { + core.setFailed(error.message); }