diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9385eff..978daaa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Tests +name: Lint, Test & Release on: [push, pull_request] @@ -6,9 +6,59 @@ permissions: contents: read jobs: + commitlint: + name: Lint commits + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 16.x + - name: Install dependencies + run: npm i --global @commitlint/{cli,config-conventional} + - name: Lint commit + if: github.event_name == 'push' + run: npx commitlint --from HEAD~1 --to HEAD --verbose --extends @commitlint/config-conventional + - name: Lint commits + if: github.event_name == 'pull_request' + run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose --extends @commitlint/config-conventional + codelint: + name: Lint code + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Use PHP 8.1 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: composer:v2 + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-php8.1-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer-php8.1- + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest --no-interaction --no-scripts --no-plugins + - name: Lint code + run: composer run-script lint test: - name: PHP ${{ matrix.php_version }} + name: Run tests runs-on: ubuntu-latest + needs: + - commitlint + - codelint env: DB: mysql strategy: @@ -25,29 +75,56 @@ jobs: ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - - uses: actions/checkout@v3 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Use PHP ${{ matrix.node_version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php_version }} - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php${{ matrix.php_version }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php${{ matrix.php_version }}- - - - name: Install dependencies - run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader --verbose --profile - - - name: Run test suite - run: vendor/bin/phpunit tests + - name: Checkout code + uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Use PHP 8.1 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: composer:v2 + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-php8.1-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer-php8.1- + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest --no-interaction --no-scripts --no-plugins + - name: Test code + run: composer run-script test + release: + name: Release + concurrency: release + if: ${{ github.event_name == 'push' && github.actor != 'dependabot[bot]' }} + runs-on: ubuntu-latest + needs: + - commitlint + - codelint + - test + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + id-token: write # to enable use of OIDC for npm provenance + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "lts/*" + cache: 'npm' + - name: Install dependencies + run: npm install --global semantic-release@21 @semantic-release/git@10 @semantic-release/changelog@6 + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npx semantic-release diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..167f0ec --- /dev/null +++ b/.releaserc @@ -0,0 +1,7 @@ +preset: conventionalcommits +plugins: + - '@semantic-release/commit-analyzer' + - '@semantic-release/release-notes-generator' + - ['@semantic-release/changelog', {changelogTitle: '# Changelog'}] + - '@semantic-release/github' + - ['@semantic-release/git', {message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"}] diff --git a/composer.json b/composer.json index 1a0e227..9fa44df 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,13 @@ "silverstripe/framework": "^4" }, "require-dev": { - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^3.7" + }, + "scripts": { + "lint": "phpcs src/ tests/php/ tests/behat/src/", + "lint:fix": "phpcbf src/ tests/php/ tests/behat/src/", + "test": "phpunit tests" }, "autoload": { "psr-4": {