From d162cc9b7f7d51948b0925afc9a1a7f3ee37f949 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Thu, 21 Dec 2023 15:48:59 +0100 Subject: [PATCH] ci: improve CI workflows --- .github/dependabot.yml | 38 +++++--- .github/workflows/__build-website.yml | 89 +++++++++++++++++++ ...inuous-integration.yml => __shared-ci.yml} | 38 +++----- .github/workflows/build-website.yml | 43 --------- .github/workflows/linter.yml | 13 +++ .github/workflows/main-ci.yml | 51 +++++++++++ .github/workflows/need-fix-to-issue.yml | 21 +++++ .github/workflows/publish.yml | 13 --- .github/workflows/pull-request-ci.yml | 18 ++++ .github/workflows/stale.yml | 19 ++-- 10 files changed, 238 insertions(+), 105 deletions(-) create mode 100644 .github/workflows/__build-website.yml rename .github/workflows/{continuous-integration.yml => __shared-ci.yml} (66%) delete mode 100644 .github/workflows/build-website.yml create mode 100644 .github/workflows/linter.yml create mode 100644 .github/workflows/main-ci.yml create mode 100644 .github/workflows/need-fix-to-issue.yml delete mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/pull-request-ci.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0183e756..3871f4b2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,6 +7,29 @@ updates: schedule: interval: weekly day: friday + groups: + laminas: + patterns: + - "laminas/*" + phpunit: + patterns: + - "phpunit/*" + - "spatie/phpunit-snapshot-assertions" + dev-dependencies: + dependency-type: development + + - package-ecosystem: composer + open-pull-requests-limit: 20 + versioning-strategy: widen + directory: "/tools" + schedule: + interval: weekly + day: friday + groups: + tools-dependencies: + patterns: + - "*" + - package-ecosystem: npm open-pull-requests-limit: 20 versioning-strategy: widen @@ -18,12 +41,15 @@ updates: docusaurus: patterns: - "@docusaurus/*" + - "@tsconfig/docusaurus" react: patterns: - react - react-* - "@types/react" - "@types/react-*" + dev-dependencies: + dependency-type: development - package-ecosystem: github-actions directory: "/" @@ -31,14 +57,6 @@ updates: interval: weekly day: friday groups: - laminas: + github-actions-dependencies: patterns: - - "laminas/*" - phpstan: - patterns: - - "phpstan/*" - - "slam/phpstan-laminas-framework" - phpunit: - patterns: - - "phpunit/*" - - "spatie/phpunit-snapshot-assertions" + - "*" diff --git a/.github/workflows/__build-website.yml b/.github/workflows/__build-website.yml new file mode 100644 index 00000000..53f75a15 --- /dev/null +++ b/.github/workflows/__build-website.yml @@ -0,0 +1,89 @@ +on: + workflow_call: + inputs: + publish: + default: false + type: boolean + +jobs: + generate-documentation: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: ⚙️ Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + extensions: none, curl, json, dom, tokenizer, xml, xmlwriter, simplexml, iconv, mbstring, intl, sodium + + - name: ♻️ Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: ♻️ Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: ⚙️ Install dependencies + run: | + composer install --no-progress --prefer-dist --optimize-autoloader + composer --working-dir=tools install --no-progress --prefer-dist --optimize-autoloader + + - name: ♻️ Tools cache + uses: actions/cache@v3 + with: + path: tools/cache + key: ${{ runner.os }}-tools-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-tools- + + - name: 📃 Generate documentation + run: composer generate-docs + + - name: 📦 Upload generated documentation artifact + uses: actions/upload-artifact@v4 + with: + name: documentation + path: website/docs + + build-website: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: documentation + + - uses: actions/setup-node@v4.0.0 + with: + node-version-file: ".nvmrc" + cache: yarn + cache-dependency-path: website/yarn.lock + + - name: ⚙️ Install Dependencies + working-directory: website + run: yarn install --frozen-lockfile + + - name: ♻️ Webpack cache + uses: actions/cache@v3 + with: + path: website/node_modules/.cache/webpack + key: ${{ runner.os }}-webpack-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-webpack- + + - name: 🏗️ Build website + run: yarn build + working-directory: website + + - name: 📦 Upload website build artifact + if: inputs.publish + uses: actions/upload-pages-artifact@v2 + with: + path: website/build diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/__shared-ci.yml similarity index 66% rename from .github/workflows/continuous-integration.yml rename to .github/workflows/__shared-ci.yml index 216c9a46..d1ed4a0f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/__shared-ci.yml @@ -1,14 +1,11 @@ -name: Continuous integration +name: Shared - Continuous Integration for common tasks on: - workflow_dispatch: - push: - branches: - - main - merge_group: - pull_request: - branches: - - main + workflow_call: + inputs: + publish: + default: false + type: boolean jobs: checks: @@ -25,7 +22,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup PHP, with composer and extensions + - name: ⚙️ Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} @@ -40,7 +37,7 @@ jobs: uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - name: ⚙️ Install dependencies @@ -52,7 +49,7 @@ jobs: uses: actions/cache@v3 with: path: tools/cache - key: ${{ runner.os }}-tools-${{ matrix.php-versions }}-${{ github.sha }} + key: ${{ runner.os }}-tools-${{ github.sha }} restore-keys: | ${{ runner.os }}-tools- @@ -73,18 +70,9 @@ jobs: with: file: ./build/logs/clover.xml - - name: 📃 Generate documentation - if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.stable - env: - GITHUB_TOKEN: ${{ secrets.GH_PRIVATE_ACCESS_TOKEN }} - run: | - composer generate-docs - - git config user.email "${{ github.actor }}@users.noreply.github.com" - git config user.name "${{ github.actor }}" - echo `git add -A && git commit -m "docs: update documentation"` - git push --follow-tags origin main - build-website: + needs: checks name: Check that website is building without errors - uses: ./.github/workflows/build-website.yml + uses: ./.github/workflows/__build-website.yml + with: + publish: ${{ inputs.publish }} diff --git a/.github/workflows/build-website.yml b/.github/workflows/build-website.yml deleted file mode 100644 index 009e0488..00000000 --- a/.github/workflows/build-website.yml +++ /dev/null @@ -1,43 +0,0 @@ -on: - workflow_call: - inputs: - publish: - default: false - type: boolean - -jobs: - build-website: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4.0.0 - with: - node-version-file: ".nvmrc" - cache: yarn - cache-dependency-path: website/yarn.lock - - - name: ⚙️ Install Dependencies - working-directory: website - run: yarn install --frozen-lockfile - - - name: ♻️ Webpack cache - uses: actions/cache@v3 - with: - path: website/node_modules/.cache/webpack - key: ${{ runner.os }}-webpack-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-webpack- - - - name: 🏗️ Build website - run: yarn build - working-directory: website - - - name: 🚀 Deploy to GitHub Pages - if: inputs.publish - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./website/build - user_name: ${{ github.actor }} - user_email: ${{ github.actor }}@users.noreply.github.com diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..8cd695d2 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,13 @@ +name: "Linter" + +on: + push: + branches: [main, 4.x] + tags: ["*"] + + pull_request: + branches: [main, 4.x] + +jobs: + main: + uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@0.11.2 diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml new file mode 100644 index 00000000..e1f2810a --- /dev/null +++ b/.github/workflows/main-ci.yml @@ -0,0 +1,51 @@ +name: Main - Continuous Integration + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - main + - 4.x + +jobs: + ci: + name: Continuous Integration + uses: ./.github/workflows/__shared-ci.yml + secrets: inherit + with: + publish: true + + deploy: + name: Deploy website + needs: ci + runs-on: ubuntu-latest + permissions: + contents: write + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: documentation + + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "docs: update documentation" + commit_options: "--no-verify --signoff" + + - name: ⚙️ Setup Pages + if: github.ref == 'refs/heads/main' + uses: actions/configure-pages@v4 + + - name: 🚀 Deploy to GitHub Pages + id: deployment + if: github.ref == 'refs/heads/main' + uses: actions/deploy-pages@v3 diff --git a/.github/workflows/need-fix-to-issue.yml b/.github/workflows/need-fix-to-issue.yml new file mode 100644 index 00000000..a3416b72 --- /dev/null +++ b/.github/workflows/need-fix-to-issue.yml @@ -0,0 +1,21 @@ +name: Need fix to Issue + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + manual-commit-ref: + description: "The SHA of the commit to get the diff for" + required: true + manual-base-ref: + description: "By default, the commit entered above is compared to the one directly before it; to go back further, enter an earlier SHA here" + required: false + +jobs: + main: + uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@0.11.2 + with: + manual-commit-ref: ${{ inputs.manual-commit-ref }} + manual-base-ref: ${{ inputs.manual-base-ref }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 3abd04fe..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Publish - -on: - push: - tags: [v*] - workflow_dispatch: - -jobs: - gh-release: - name: Build and release website - uses: ./.github/workflows/build-website.yml - with: - publish: true diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml new file mode 100644 index 00000000..05d123c7 --- /dev/null +++ b/.github/workflows/pull-request-ci.yml @@ -0,0 +1,18 @@ +name: Pull request - Continuous Integration + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + pull_request: + branches: + - main + - 4.x + merge_group: + +jobs: + ci: + name: Continuous Integration + uses: ./.github/workflows/__shared-ci.yml + secrets: inherit diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index a906c6ce..086f6cdd 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,18 +1,9 @@ -name: "Close stale issues" +name: Mark stale issues and pull requests + on: schedule: - - cron: "0 0 * * *" + - cron: "30 1 * * *" jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: "This issue is stale" - stale-pr-message: "This PR is stale" - stale-issue-label: "no-issue-activity" - exempt-issue-labels: "awaiting-approval,work-in-progress" - stale-pr-label: "no-pr-activity" - exempt-pr-labels: "awaiting-approval,work-in-progress" + main: + uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@0.11.2