From 993cfcd4bc5492c0f3844e46c3341a0efc4af01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 4 May 2020 08:29:18 +0200 Subject: [PATCH] Enhancement: Synchronize with ergebns/php-library-template --- .editorconfig | 2 +- .gitattributes | 12 +- .github/CONTRIBUTING.md | 25 ++- .github/settings.yml | 30 +++- .github/workflows/{deploy.yml => deploy.yaml} | 14 +- .github/workflows/integrate.yaml | 163 ++++++++++++++++++ .github/workflows/integrate.yml | 74 -------- .github/workflows/prune.yaml | 31 ++++ .github/workflows/stale.yml | 26 --- .github/workflows/triage.yaml | 42 +++++ .gitignore | 3 +- .yamllint.yaml | 66 +++++++ LICENSE => LICENSE.md | 6 +- Makefile | 10 +- README.md | 2 + action.yml | 14 +- 16 files changed, 382 insertions(+), 138 deletions(-) rename .github/workflows/{deploy.yml => deploy.yaml} (87%) create mode 100644 .github/workflows/integrate.yaml delete mode 100644 .github/workflows/integrate.yml create mode 100644 .github/workflows/prune.yaml delete mode 100644 .github/workflows/stale.yml create mode 100644 .github/workflows/triage.yaml create mode 100644 .yamllint.yaml rename LICENSE => LICENSE.md (80%) diff --git a/.editorconfig b/.editorconfig index 59fb83d..020231b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ trim_trailing_whitespace = true [*.json] indent_size = 2 -[*.yml] +[*.{yaml,yml}] indent_size = 2 [Makefile] diff --git a/.gitattributes b/.gitattributes index 17a9c90..998b49a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,6 @@ -/.build/ export-ignore -/.github/ export-ignore -/.editorconfig export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/Makefile export-ignore +/.build/ export-ignore +/.github/ export-ignore +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/Makefile export-ignore diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index df7cdbe..a7bc3be 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,8 +1,25 @@ # CONTRIBUTING -We are using [GitHub Actions](https://github.com/features/actions) as continuous integration system. +We are using [GitHub Actions](https://github.com/features/actions) as a continuous integration system. -For details, see [`workflows/continuous-integration.yml`](workflows/continuous-integration.yml). +For details, take a look at the following workflow configuration files: + +- [`workflows/deploy.yaml`](workflows/deploy.yaml) +- [`workflows/integrate.yaml`](workflows/integrate.yaml) +- [`workflows/prune.yaml`](workflows/prune.yaml) +- [`workflows/triage.yaml`](workflows/triage.yaml) + +## Coding Standards + +We are using [`yamllint`](https://github.com/adrienverge/yamllint) to enforce coding standards in YAML files. + +If you do not have `yamllint` installed yet, run + +``` +$ brew install yamllint +``` + +to install `yamllint`. ## Docker Image @@ -22,7 +39,9 @@ Run $ make ``` -to build, tag, and run the Docker image locally. +to enforce coding standards, build, tag, and run the Docker image locally! + +## Help :bulb: Run diff --git a/.github/settings.yml b/.github/settings.yml index ad19a91..afbd72d 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -19,34 +19,48 @@ branches: - "GitHub Action (not-required)" - "GitHub Action (required)" strict: false - restrictions: null + restrictions: + + # https://developer.github.com/v3/repos/branches/#parameters-1 + + # Note: User, app, and team restrictions are only available for organization-owned repositories. + # Set to null to disable when using this configuration for a repository on a personal account. + + apps: [] + teams: [] + users: + - "ergebnis-bot" # https://developer.github.com/v3/issues/labels/#create-a-label # https://developer.github.com/v3/issues/labels/#update-a-label labels: - name: "bug" - color: "#ee0701" + color: "ee0701" description: "" - name: "dependency" - color: "#0366d6" + color: "0366d6" description: "" - name: "enhancement" - color: "#0e8a16" + color: "0e8a16" + description: "" + + - name: "merge" + color: "6f42c1" description: "" - name: "question" - color: "#cc317c" + color: "cc317c" description: "" - name: "security" - color: "#ee0701" + color: "ee0701" description: "" - name: "stale" - color: "#eeeeee" + color: "eeeeee" description: "" # https://developer.github.com/v3/repos/#edit @@ -55,7 +69,9 @@ repository: allow_merge_commit: true allow_rebase_merge: false allow_squash_merge: false + archived: false default_branch: "master" + delete_branch_on_merge: true description: ":octocat: + :musical_note: Provides a GitHub action for running ergebnis/composer-normalize." has_downloads: true has_issues: true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yaml similarity index 87% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy.yaml index bf87791..aba3c1c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yaml @@ -2,26 +2,26 @@ name: "Deploy" -on: +on: # yamllint disable-line rule:truthy push: branches: - "master" tags: - "**" +env: + DOCKER_IMAGE: "ergebnis/composer-normalize-action" + DOCKER_USERNAME: "ergebnis" + jobs: build: - name: "Build and deploy" + name: "Deploy" runs-on: "ubuntu-latest" - env: - DOCKER_IMAGE: "ergebnis/composer-normalize-action" - DOCKER_USERNAME: "ergebnis" - steps: - name: "Checkout" - uses: "actions/checkout@v2.0.0" + uses: "actions/checkout@v2" - name: "Build Docker image" run: "docker build --tag ${{ env.DOCKER_IMAGE }}:latest ." diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml new file mode 100644 index 0000000..704d675 --- /dev/null +++ b/.github/workflows/integrate.yaml @@ -0,0 +1,163 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Integrate" + +on: # yamllint disable-line rule:truthy + pull_request: null + push: + branches: + - "master" + +env: + DOCKER_IMAGE: "ergebnis/composer-normalize-action" + +jobs: + docker-image: + name: "Docker image" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + required: + - "not-required" + - "required" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Build Docker image" + run: "docker build --tag ${DOCKER_IMAGE}:latest ." + + - name: "Run Docker image with default behaviour" + run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}/.build/${{ matrix.required }}:/app ${{ env.DOCKER_IMAGE }}:latest" + + - name: "Run Docker image with custom behaviour, specifying options" + run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}/.build/${{ matrix.required }}:/app ${{ env.DOCKER_IMAGE }}:latest --diff --indent-size=1 --indent-style=space --no-update-lock" + + - name: "Run Docker image with custom behaviour, specifying argument and options" + run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}:/app ${{ env.DOCKER_IMAGE }}:latest .build/${{ matrix.required }}/composer.json --diff --indent-size=2 --indent-style=space --no-update-lock" + + github-action: + name: "GitHub Action" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + required: + - "not-required" + - "required" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Copy composer.json from .build/${{ matrix.required }} into root directory" + run: "cp .build/${{ matrix.required }}/composer.json composer.json" + + - name: "Run GitHub Action with default behavior" + uses: "./" + + - name: "Run GitHub Action with custom behavior, specifying options" + uses: "./" + with: + args: "--diff --indent-size=1 --indent-style=tab --no-update-lock" + + - name: "Remove composer.json from root directory" + run: "rm composer.json" + + - name: "Run GitHub Action with custom behavior, specifying argument and options" + uses: "./" + with: + args: ".build/${{ matrix.required }}/composer.json --diff --indent-size=1 --indent-style=tab --no-update-lock" + + merge: + name: "Merge" + + runs-on: "ubuntu-latest" + + needs: + - "docker-image" + - "github-action" + + if: > + github.event_name == 'pull_request' && + github.event.pull_request.draft == false && ( + github.event.action == 'opened' || + github.event.action == 'reopened' || + github.event.action == 'synchronize' + ) && ( + (github.actor == 'localheinz' && contains(github.event.pull_request.labels.*.name, 'merge')) + ) + + steps: + - name: "Request review from @ergebnis-bot" + uses: "actions/github-script@0.8.0" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.pull_request + const repository = context.repo + + const reviewers = [ + "ergebnis-bot", + ] + + await github.pulls.createReviewRequest({ + owner: repository.owner, + pull_number: pullRequest.number, + repo: repository.repo, + reviewers: reviewers, + }) + + - name: "Assign @ergebnis-bot" + uses: "actions/github-script@0.8.0" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.pull_request + const repository = context.repo + + const reviewers = [ + "ergebnis-bot", + ] + + await github.issues.addAssignees({ + assignees: reviewers, + issue_number: pullRequest.number, + owner: repository.owner, + repo: repository.repo, + }) + + - name: "Approve pull request" + uses: "actions/github-script@0.8.0" + if: "github.actor != 'ergebnis-bot'" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.pull_request + const repository = context.repo + + await github.pulls.createReview({ + event: "APPROVE", + owner: repository.owner, + pull_number: pullRequest.number, + repo: repository.repo, + }) + + - name: "Merge pull request" + uses: "actions/github-script@0.8.0" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const pullRequest = context.payload.pull_request + const repository = context.repo + + await github.pulls.merge({ + merge_method: "merge", + owner: repository.owner, + pull_number: pullRequest.number, + repo: repository.repo, + }) diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml deleted file mode 100644 index 49d6ac1..0000000 --- a/.github/workflows/integrate.yml +++ /dev/null @@ -1,74 +0,0 @@ -# https://help.github.com/en/categories/automating-your-workflow-with-github-actions - -name: "Integrate" - -on: - - "pull_request" - -jobs: - docker-image: - name: "Docker image" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - required: - - "not-required" - - "required" - - env: - DOCKER_IMAGE: "ergebnis/composer-normalize-action" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.0.0" - - - name: "Build Docker image" - run: "docker build --tag ${DOCKER_IMAGE}:latest ." - - - name: "Run Docker image with default behaviour" - run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}/.build/${{ matrix.required }}:/app ${{ env.DOCKER_IMAGE }}:latest" - - - name: "Run Docker image with custom behaviour, specifying options" - run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}/.build/${{ matrix.required }}:/app ${{ env.DOCKER_IMAGE }}:latest --diff --indent-size=1 --indent-style=space --no-update-lock" - - - name: "Run Docker image with custom behaviour, specifying argument and options" - run: "docker run --interactive --rm --workdir=/app --volume ${GITHUB_WORKSPACE}:/app ${{ env.DOCKER_IMAGE }}:latest .build/${{ matrix.required }}/composer.json --diff --indent-size=2 --indent-style=space --no-update-lock" - - github-action: - name: "GitHub Action" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - required: - - "not-required" - - "required" - - env: - DOCKER_IMAGE: "ergebnis/composer-normalize-action" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2.0.0" - - - name: "Copy composer.json from .build/${{ matrix.required }} into root directory" - run: "cp .build/${{ matrix.required }}/composer.json composer.json" - - - name: "Run GitHub Action with default behavior" - uses: "./" - - - name: "Run GitHub Action with custom behavior, specifying options" - uses: "./" - with: - args: "--diff --indent-size=1 --indent-style=tab --no-update-lock" - - - name: "Remove composer.json from root directory" - run: "rm composer.json" - - - name: "Run GitHub Action with custom behavior, specifying argument and options" - uses: "./" - with: - args: ".build/${{ matrix.required }}/composer.json --diff --indent-size=1 --indent-style=tab --no-update-lock" diff --git a/.github/workflows/prune.yaml b/.github/workflows/prune.yaml new file mode 100644 index 0000000..cea3de4 --- /dev/null +++ b/.github/workflows/prune.yaml @@ -0,0 +1,31 @@ +# https://github.com/actions/stale + +name: "Prune" + +on: # yamllint disable-line rule:truthy + schedule: + - cron: "0 12 * * *" + +jobs: + prune: + name: "Issues" + + runs-on: "ubuntu-latest" + + steps: + - name: "Prune issues and pull requests" + uses: "actions/stale@v2" + with: + days-before-close: 5 + days-before-stale: 60 + repo-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + stale-issue-label: "stale" + stale-issue-message: | + Since this issue has not had any activity within the last sixty days, I have marked it as stale. + + I will close it if no further activity occurs within the next five days. + stale-pr-label: "stale" + stale-pr-message: | + Since this pull request has not had any activity within the last sixty days, I have marked it as stale. + + I will close it if no further activity occurs within the next five days. diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index f47e06e..0000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,26 +0,0 @@ -# https://github.com/actions/stale - -name: "Close stale issues and pull requests" -on: - schedule: - - cron: "0 12 * * *" - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - days-before-stale: 60 - days-before-close: 5 - stale-issue-label: 'stale' - stale-issue-message: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. - stale-pr-message: > - This PR has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. - stale-pr-label: 'stale' diff --git a/.github/workflows/triage.yaml b/.github/workflows/triage.yaml new file mode 100644 index 0000000..09671d0 --- /dev/null +++ b/.github/workflows/triage.yaml @@ -0,0 +1,42 @@ +name: "Triage" + +on: # yamllint disable-line rule:truthy + pull_request: null + +jobs: + label: + name: "Label" + + runs-on: "ubuntu-latest" + + steps: + - name: "Add labels based on branch name" + if: "github.event.action == 'opened'" + uses: "actions/github-script@0.8.0" + with: + github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" + script: | + const branchPrefixLabels = { + feature: "enhancement", + fix: "bug", + } + + const pullRequest = context.payload.pull_request + const repository = context.repo + + const branchName = pullRequest.head.ref + + const matches = branchName.match(new RegExp('^([^/]+)\/')); + + if (matches instanceof Array && branchPrefixLabels.hasOwnProperty(matches[1])) { + const label = branchPrefixLabels[matches[1]] + + github.issues.addLabels({ + issue_number: pullRequest.number, + labels: [ + label + ], + owner: repository.owner, + repo: repository.repo, + }); + } diff --git a/.gitignore b/.gitignore index 48b8bf9..127d0e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ +/.notes/ +/vendor/ diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..b2129ac --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,66 @@ +extends: "default" + +ignore: | + .build/ + .notes/ + vendor/ + +rules: + braces: + max-spaces-inside-empty: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + min-spaces-inside: 1 + brackets: + max-spaces-inside-empty: 0 + max-spaces-inside: 0 + min-spaces-inside-empty: 0 + min-spaces-inside: 0 + colons: + max-spaces-after: 1 + max-spaces-before: 0 + commas: + max-spaces-after: 1 + max-spaces-before: 0 + min-spaces-after: 1 + comments: + ignore-shebangs: true + min-spaces-from-content: 1 + require-starting-space: true + comments-indentation: "enable" + document-end: + present: false + document-start: + present: false + indentation: + check-multi-line-strings: false + indent-sequences: true + spaces: 2 + empty-lines: + max-end: 0 + max-start: 0 + max: 1 + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true + hyphens: + max-spaces-after: 2 + key-duplicates: "enable" + key-ordering: "disable" + line-length: "disable" + new-line-at-end-of-file: "enable" + new-lines: + type: "unix" + octal-values: + forbid-implicit-octal: true + quoted-strings: + quote-type: "double" + trailing-spaces: "enable" + truthy: + allowed-values: + - "false" + - "true" + +yaml-files: + - "*.yaml" + - "*.yml" diff --git a/LICENSE b/LICENSE.md similarity index 80% rename from LICENSE rename to LICENSE.md index 6bc0bf4..d6c8aed 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,16 +1,16 @@ -The MIT License (MIT) +# The MIT License (MIT) Copyright (c) 2019 Andreas Möller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +documentation files (the _Software_), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +THE SOFTWARE IS PROVIDED **AS IS**, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile index 01ca640..a444dc7 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ -.PHONY: docker help it - COMPOSER_NORMALIZE_VERSION:=2.5.1 DOCKER_IMAGE:=ergebnis/composer-normalize-action -it: docker ## Runs the docker target +.PHONY: it +it: coding-standards docker ## Runs the coding-standards and docker targets + +.PHONY: coding-standards +coding-standards: ## Lints YAML files with yamllint + yamllint -c .yamllint.yaml --strict . docker: ## Builds, tags, and runs the Docker image docker build --tag ${DOCKER_IMAGE} . @@ -17,5 +20,6 @@ docker: ## Builds, tags, and runs the Docker image docker run --interactive --rm --tty --workdir=/app --volume ${PWD}:/app ${DOCKER_IMAGE}:latest .build/not-required/composer.json --diff --indent-size=2 --indent-style=space --no-update-lock docker run --interactive --rm --tty --workdir=/app --volume ${PWD}:/app ${DOCKER_IMAGE}:latest .build/required/composer.json --diff --indent-size=2 --indent-style=space --no-update-lock +.PHONY: help help: ## Displays this list of targets with descriptions @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index 63c94cc..1d4ea27 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,8 @@ Please have a look at [`CODE_OF_CONDUCT.md`](https://github.com/ergebnis/.github This package is licensed using the MIT License. +Please have a look at [`LICENSE.md`](LICENSE.md). + ## Credits The implementation of this GitHub action is largely inspired by the work of [Oskar Stark](https://github.com/OskarStark) on the GitHub actions [`OskarStark/php-cs-fixer-ga`](https://github.com/OskarStark/php-cs-fixer-ga) and [`OskarStark/phpstan-ga`](https://github.com/OskarStark/phpstan-ga). diff --git a/action.yml b/action.yml index 05c2003..7b71059 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,15 @@ # https://help.github.com/en/articles/metadata-syntax-for-github-actions -author: 'localheinz' +author: "localheinz" branding: - icon: 'box' - color: 'green' + icon: "box" + color: "green" -description: 'Ensure your PHP project has a normalized composer.json.' +description: "Ensure your PHP project has a normalized composer.json." -name: 'composer-normalize-action' +name: "composer-normalize-action" runs: - using: 'docker' - image: 'docker://ergebnis/composer-normalize-action' + using: "docker" + image: "docker://ergebnis/composer-normalize-action"