Skip to content

Commit

Permalink
ci: improve CI workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Dec 21, 2023
1 parent a5e41c7 commit 4f5a73d
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 133 deletions.
39 changes: 39 additions & 0 deletions .github/actions/setup-php/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Setup PHP
description: Opiniated PHP setup with composer and extensions
inputs:
php-version:
description: Php version to use
required: true
runs:
using: "composite"
steps:
- name: ⚙️ Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
extensions: none, curl, json, dom, tokenizer, xml, xmlwriter, simplexml, iconv, mbstring, intl, sodium
coverage: pcov

- 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-
38 changes: 28 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,27 +41,22 @@ updates:
docusaurus:
patterns:
- "@docusaurus/*"
- "@tsconfig/docusaurus"
react:
patterns:
- react
- react-*
- "@types/react"
- "@types/react-*"
dev-dependencies:
dependency-type: development

- package-ecosystem: github-actions
directory: "/"
schedule:
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"
- "*"
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@ on:
type: boolean

jobs:
generate-documentation:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: ⚙️ Setup PHP, with composer and extensions
uses: ./.github/actions/setup-php
with:
php-version: 8.3

- 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:
needs: generate-documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: documentation

- uses: actions/[email protected]
with:
node-version-file: ".nvmrc"
Expand All @@ -33,11 +58,8 @@ jobs:
run: yarn build
working-directory: website

- name: 🚀 Deploy to GitHub Pages
- name: 📦 Upload website build artifact
if: inputs.publish
uses: peaceiris/actions-gh-pages@v3
uses: actions/upload-pages-artifact@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build
user_name: ${{ github.actor }}
user_email: ${{ github.actor }}@users.noreply.github.com
path: website/build
51 changes: 51 additions & 0 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Shared - Continuous Integration for common tasks

on:
workflow_call:
inputs:
publish:
default: false
type: boolean

jobs:
checks:
strategy:
matrix:
include:
- php-versions: "8.1"
- php-versions: "8.2"
- php-versions: "8.3"
stable: true

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: ⚙️ Setup PHP, with composer and extensions
uses: ./.github/actions/setup-php
with:
php-version: ${{ matrix.php-versions }}

- name: 👕 Lint
if: matrix.stable
run: composer php-cs-fixer -- --format=checkstyle | tools/vendor/bin/cs2pr

- name: 🔬 Static analysis
if: matrix.stable
run: composer stan -- --error-format=checkstyle | tools/vendor/bin/cs2pr

- name: 🧪 Test
run: composer test:ci

- name: 📊 Upload coverage results to Codecov
if: matrix.stable
uses: codecov/codecov-action@v3
with:
file: ./build/logs/clover.xml

build-website:
name: Check that website is building without errors
uses: ./.github/workflows/__build-website.yml
with:
publish: ${{ inputs.publish }}
90 changes: 0 additions & 90 deletions .github/workflows/continuous-integration.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions .github/workflows/need-fix-to-issue.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
manual-commit-ref: ${{ inputs.manual-commit-ref }}
manual-base-ref: ${{ inputs.manual-base-ref }}
13 changes: 0 additions & 13 deletions .github/workflows/publish.yml

This file was deleted.

Loading

0 comments on commit 4f5a73d

Please sign in to comment.