From 25b77f6c22216ee06478a519d54b5412b8bd927f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 18 Oct 2021 15:53:26 +0200 Subject: [PATCH] Use reusable workflows --- .github/workflows/flex-cleanup.yml | 13 ++ .github/workflows/flex-endpoint.yml | 47 ----- .github/workflows/flex-update.yml | 17 ++ .github/workflows/pr-cleanup.yml | 25 --- .github/workflows/qa.yml | 259 +--------------------------- 5 files changed, 37 insertions(+), 324 deletions(-) create mode 100644 .github/workflows/flex-cleanup.yml delete mode 100644 .github/workflows/flex-endpoint.yml create mode 100644 .github/workflows/flex-update.yml delete mode 100644 .github/workflows/pr-cleanup.yml diff --git a/.github/workflows/flex-cleanup.yml b/.github/workflows/flex-cleanup.yml new file mode 100644 index 00000000..4d675cb6 --- /dev/null +++ b/.github/workflows/flex-cleanup.yml @@ -0,0 +1,13 @@ +name: Cleanup Flex testing endpoint + +on: + pull_request_target: + types: [ closed ] + +defaults: + run: + shell: bash + +jobs: + call-flex-cleanup: + uses: symfony/recipes/.github/workflows/callable-flex-cleanup.yml@main diff --git a/.github/workflows/flex-endpoint.yml b/.github/workflows/flex-endpoint.yml deleted file mode 100644 index ff4581d5..00000000 --- a/.github/workflows/flex-endpoint.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Update Flex endpoint - -on: - push: - branches: - - master - -defaults: - run: - shell: bash - -jobs: - - update: - name: Update Flex endpoint - runs-on: Ubuntu-20.04 - - steps: - - - name: Checkout - uses: actions/checkout@v2 - id: checkout - with: - fetch-depth: 0 - - - - name: Install tools - run: | - git config --global user.email "" - git config --global user.name "github-action bot" - cd .github - wget -q -O recipes-checker.zip https://codeload.github.com/symfony-tools/recipes-checker/zip/refs/heads/main - unzip recipes-checker.zip - cd recipes-checker-main - composer install --ansi --no-dev - - - - name: Update Flex endpoint - run: | - mkdir .github/flex-endpoint - git ls-tree HEAD */*/* | php .github/recipes-checker-main/run generate:flex-endpoint --contrib ${{ github.repository }} master flex/main .github/flex-endpoint - git switch flex/main - git rm -q *.json - mv .github/flex-endpoint/*.json . - git add *.json - git commit -m 'Update Flex endpoint' || true - git push origin -f flex/main diff --git a/.github/workflows/flex-update.yml b/.github/workflows/flex-update.yml new file mode 100644 index 00000000..45d79b51 --- /dev/null +++ b/.github/workflows/flex-update.yml @@ -0,0 +1,17 @@ +name: Update Flex endpoint + +on: + push: + branches: + - master + +defaults: + run: + shell: bash + +jobs: + call-flex-update: + uses: symfony/recipes/.github/workflows/callable-flex-update.yml@main + with: + branch: master + contrib: true diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml deleted file mode 100644 index 69f8e8f3..00000000 --- a/.github/workflows/pr-cleanup.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Cleanup Flex testing endpoint - -on: - pull_request_target: - types: [ closed ] - -defaults: - run: - shell: bash - -jobs: - - cleanup: - name: Cleanup Flex testing endpoint - runs-on: Ubuntu-20.04 - - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - - name: Cleanup Flex testing endpoint - run: | - git push origin :flex/pull-${{ github.event.number }} || true diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 11fe5b24..8dabe8cf 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -8,256 +8,11 @@ defaults: shell: bash jobs: + call-qa: + uses: symfony/recipes/.github/workflows/callable-qa.yml@main + with: + branch: master + contrib: true + find_yaml: -not -wholename 'codeception/codeception/*/tests/*' -not -wholename 'codeception/codeception/*/codeception.yml' + create_project_php: '8.0' - tests: - name: Run checks - runs-on: Ubuntu-20.04 - - steps: - - - name: Checkout - uses: actions/checkout@v2 - id: checkout - with: - fetch-depth: 0 - ref: 'refs/pull/${{ github.event.number }}/merge' - - - - name: Install tools - run: | - git config --global user.email "" - git config --global user.name "github-action bot" - cd .github - wget -q -O recipes-checker.zip https://codeload.github.com/symfony-tools/recipes-checker/zip/refs/heads/main - unzip recipes-checker.zip - cd recipes-checker-main - composer install --ansi --no-dev - - - - name: Check manifest.json files - if: "always() && steps.checkout.outcome == 'success'" - run: | - .github/recipes-checker-main/run lint:manifests --contrib - - - - name: Remove non-patched packages - if: "always() && steps.checkout.outcome == 'success'" - run: | - .github/recipes-checker-main/run list-unpatched-packages $GITHUB_EVENT_PATH ${{ secrets.GITHUB_TOKEN }} | xargs -r -n10 rm -rf - - - - name: Generate Flex testing endpoint - if: "always() && steps.checkout.outcome == 'success' && github.base_ref == 'master'" - run: | - mkdir .github/flex-endpoint - git ls-tree HEAD */*/* | php .github/recipes-checker-main/run generate:flex-endpoint --contrib ${{ github.repository }} master flex/pull-${{ github.event.number }} .github/flex-endpoint - git stash - git switch -c pr - git switch --orphan flex/pull-${{ github.event.number }} - git reset --hard -q - mv .github/flex-endpoint/*.json . - git add *.json - git commit -m 'Create Flex endpoint' || true - git push origin -f flex/pull-${{ github.event.number }} - git switch pr - git stash pop -q - - - - name: Compute diff between recipe versions - if: "always() && steps.checkout.outcome == 'success'" - run: | - find * -mindepth 1 -maxdepth 1 -type d | sort \ - | .github/recipes-checker-main/run diff-recipe-versions 'https://api.github.com/repos/${{ github.repository }}/contents/index.json?ref=flex/pull-${{ github.event.number }}' \ - > .github/diff-recipe-versions.md - - - - name: Post diff between recipe versions - if: "always() && steps.checkout.outcome == 'success'" - uses: marocchino/sticky-pull-request-comment@v2 - with: - path: .github/diff-recipe-versions.md - - - - name: No symlinks - if: "always() && steps.checkout.outcome == 'success'" - run: | - SYMLINKS=$(find * -type l) - - if [[ "" != "$SYMLINKS" ]]; then echo -e "::error::Symlinks are not allowed\nFound $SYMLINKS\n"; exit 1; fi - - - - name: No .yml, use .yaml - if: "always() && steps.checkout.outcome == 'success'" - run: | - YMLS=$(find * -name '*.yml' -not -wholename 'codeception/codeception/*/tests/*' -not -wholename 'codeception/codeception/*/codeception.yml') - - if [[ "" != "$YMLS" ]]; then echo -e "::error::*.yml files should renamed to *.yaml\nFound $YMLS\n"; exit 1; fi - - - - name: No .gitkeep, use .gitignore - if: "always() && steps.checkout.outcome == 'success'" - run: | - GITKEEPS=$(find * -name .gitkeep) - - if [[ "" != "$GITKEEPS" ]]; then echo -e "::error::.gitkeep files should be renamed to .gitignore\nFound $GITKEEPS\n"; exit 1; fi - - - - name: 4 spaces indentation - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find * -name '*.yaml' -or -name '*.json' \ - | xargs -n1 grep -P -H -n -v '^(( )*[^ \t]|$)' \ - | cut -d: -f1-2 \ - | sed 's/\(.*\):\([0-9]*\)$/\\n::error file=\1,line=\2::Indendation must be a multiple of 4 spaces/' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: Text files end with a newline - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find * -name '*.yaml' -or -name '*.yml' -or -name '*.txt' -or -name '*.md' -or -name '*.markdown' \ - -or -name '*.json' -or -name '*.rst' -or -name '*.php' -or -name '*.js' -or -name '*.css' -or -name '*.twig' \ - | xargs -n1 -I{} bash -c '[ -n "$(tail -c1 {})" ] && echo ::error file={},line=$((1 + `wc -l {} | cut -d" " -f1`))::Should end with a newline' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: Use https when referencing symfony.com - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(grep -H -n 'http://.*symfony\.com' * -r \ - | cut -d: -f1-2 \ - | sed 's/\(.*\):\([0-9]*\)$/\\n::error file=\1,line=\2::Use https when referencing symfony.com/' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: manifest.json is found - if: "always() && steps.checkout.outcome == 'success'" - run: | - MISSING=$(find * -mindepth 2 -maxdepth 2 -type d '!' -exec test -f '{}/manifest.json' ';' -print) - - if [[ "" != "$MISSING" ]]; then echo -e "::error::Recipes must define a \"manifest.json\" file\nFile not found in $MISSING\n"; exit 1; fi - - - - name: JSON files are valid - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find * -name '*.json' | parallel -j+3 -i{} -n1 bash -c 'ERR=$(python -mjson.tool {} 2>&1 1> /dev/null) || echo \\n::error file={},line=`echo "${ERR#*: line }" | cut -d" " -f 1`::${ERR%%: line *}') - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: YAML files are valid - if: "always() && steps.checkout.outcome == 'success'" - run: | - find * -name '*.yaml' -or -name '*.yml' | .github/recipes-checker-main/run lint:yaml - - - - name: Packages exist on packagist.org - if: "always() && steps.checkout.outcome == 'success'" - run: | - .github/recipes-checker-main/run lint:packages - - - - name: Contribution is under MIT and has no merge commits - if: "always() && steps.checkout.outcome == 'success'" - run: | - .github/recipes-checker-main/run lint:pull-request $GITHUB_EVENT_PATH ${{ secrets.GITHUB_TOKEN }} - - - - name: Parameters should be defined via the "container" configurator - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find */*/*/config/packages/ -name '*.yaml' -or -name '*.yml' \ - | xargs -n1 grep -P -H -n '^parameters:' \ - | cut -d: -f1-2 \ - | sed 's/\(.*\):\([0-9]*\)$/\\n::error file=\1,line=\2::"parameters" should be defined via the "container" configurator instead/' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: Underscore notation under config/ - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find */*/*/config -type f \ - | grep -v -P '[^/]+/[^/]+/[^/]+/config/[0-9a-z_./]+$' \ - | xargs -n1 -I{} echo "::error file={}::Underscore notation is required for file and directory names under config/" || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: Yaml nulls should not be "~" - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find * -name '*.yaml' -or -name '*.yml' \ - | xargs -n1 grep -F -H -n ': ~'\ - | cut -d: -f1-2 \ - | sed 's/\(.*\):\([0-9]*\)$/\\n::error file=\1,line=\2::"~" should be replaced with "null"/' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - - - name: Symfony commands should not be wrapped in a Makefile - if: "always() && steps.checkout.outcome == 'success'" - run: | - ERRORS=$(find * -name Makefile \ - | xargs -n1 grep -P -H -n 'bin/console|\$\(CONSOLE\)' \ - | cut -d: -f1-2 \ - | sed 's/\(.*\):\([0-9]*\)$/\\n::error file=\1,line=\2::Symfony commands should not be wrapped in a Makefile/' || true) - - if [[ "" != "$ERRORS" ]]; then echo -e "$ERRORS\n"; exit 1; fi - - create-project: - needs: tests - name: Run updated recipes - runs-on: Ubuntu-20.04 - - steps: - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - coverage: "none" - php-version: "8.0" - - - - name: Export configuration - continue-on-error: true - id: config - run: | - PACKAGES=$(curl -s https://raw.githubusercontent.com/${{ github.repository }}/flex/pull-${{ github.event.number }}/index.json | jq -r '.recipes | to_entries | map(.key+":^"+.value[-1]) | join(" ")') - echo PACKAGES=$PACKAGES >> $GITHUB_ENV - [[ "" != "$PACKAGES" ]] - - - - name: Create-project with skeleton ^4 - if: "always() && steps.config.outcome == 'success'" - run: | - set -x - composer create-project --ansi "symfony/skeleton:^4" v4 - cd v4 - composer config extra.symfony.allow-contrib true - composer config minimum-stability dev - export SYMFONY_ENDPOINT=https://api.github.com/repos/${{ github.repository }}/contents/index.json?ref=flex/pull-${{ github.event.number }} - composer require -W --ansi --ignore-platform-reqs $PACKAGES - EXIT_CODE=$? - - if [[ EXIT_CODE -eq 2 ]]; then - echo -e "\n#\n#\n# You can ignore this error if your package does not support Symfony 4\n#\n#\n#\n" - fi - - exit $EXIT_CODE - - - - name: Create-project with skeleton ^5 - if: "always() && steps.config.outcome == 'success'" - run: | - set -x - composer create-project --ansi "symfony/skeleton:^5" v5 - cd v5 - composer config extra.symfony.allow-contrib true - composer config minimum-stability dev - export SYMFONY_ENDPOINT=https://api.github.com/repos/${{ github.repository }}/contents/index.json?ref=flex/pull-${{ github.event.number }} - composer require -W --ansi --ignore-platform-reqs $PACKAGES