chore: refactor lint workflow and add release-please

This commit is contained in:
alistair3149 2024-05-25 18:37:43 -04:00
parent 476af1352b
commit 251c9b932c
No known key found for this signature in database
2 changed files with 137 additions and 119 deletions

View file

@ -1,119 +1,119 @@
name: MediaWiki CI name: Lint
on: on:
push: push:
branches: branches:
- '**' - '**'
pull_request: pull_request:
branches: branches:
- '**' - '**'
jobs: jobs:
test: test:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php-versions: ['8.2', '8.1', '8.0', '7.4'] php-versions: ['8.2', '8.1', '8.0', '7.4']
steps: steps:
- name: Cancel Previous Runs - name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.1 uses: styfle/cancel-workflow-action@0.12.1
with: with:
access_token: ${{ github.token }} access_token: ${{ github.token }}
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
- name: Cache dependencies - name: Cache dependencies
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: /home/runner/cache path: /home/runner/cache
key: ${{ runner.os }}-${{ hashFiles('**/*.lock') }} key: ${{ runner.os }}-${{ hashFiles('**/*.lock') }}
- name: Install dependencies - name: Install dependencies
run: | run: |
composer validate composer validate
composer install --prefer-dist --no-progress composer install --prefer-dist --no-progress
npm install --save-dev npm install --save-dev
# Check for changed files # Check for changed files
- name: Check for PHP changes - name: Check for PHP changes
id: changed-php id: changed-php
uses: tj-actions/changed-files@v44 uses: tj-actions/changed-files@v44
with: with:
since_last_remote_commit: "true" since_last_remote_commit: "true"
files: | files: |
includes/**/*.php includes/**/*.php
- name: Check for script changes - name: Check for script changes
id: changed-script id: changed-script
uses: tj-actions/changed-files@v44 uses: tj-actions/changed-files@v44
with: with:
since_last_remote_commit: "true" since_last_remote_commit: "true"
files: | files: |
modules/**/*.js resources/**/*.js
- name: Check for stylesheet changes - name: Check for stylesheet changes
id: changed-stylesheet id: changed-stylesheet
uses: tj-actions/changed-files@v44 uses: tj-actions/changed-files@v44
with: with:
since_last_remote_commit: "true" since_last_remote_commit: "true"
files: | files: |
modules/**/*.css resources/**/*.css
modules/**/*.less resources/**/*.less
- name: Check for i18n changes - name: Check for i18n changes
id: changed-i18n id: changed-i18n
uses: tj-actions/changed-files@v44 uses: tj-actions/changed-files@v44
with: with:
since_last_remote_commit: "true" since_last_remote_commit: "true"
files: | files: |
i18n/*.json i18n/*.json
# Bypass the phpcbf non-standard exit code # Bypass the phpcbf non-standard exit code
- name: Lint PHP - name: Lint PHP
if: steps.changed-php.outputs.any_changed == 'true' if: steps.changed-php.outputs.any_changed == 'true'
continue-on-error: true continue-on-error: true
run: | run: |
sh ./bin/phpcbf.sh sh ./bin/phpcbf.sh
composer fix composer fix
composer test composer test
- name: Lint script - name: Lint script
if: steps.changed-script.outputs.any_changed == 'true' if: steps.changed-script.outputs.any_changed == 'true'
continue-on-error: true continue-on-error: true
run: | run: |
npm run lint:fix:js npm run lint:fix:js
npm run lint:js npm run lint:js
- name: Lint stylesheet - name: Lint stylesheet
if: steps.changed-stylesheet.outputs.any_changed == 'true' if: steps.changed-stylesheet.outputs.any_changed == 'true'
continue-on-error: true continue-on-error: true
run: | run: |
npm run lint:fix:styles npm run lint:fix:styles
npm run lint:styles npm run lint:styles
- name: Lint i18n - name: Lint i18n
if: steps.changed-i18n.outputs.any_changed == 'true' if: steps.changed-i18n.outputs.any_changed == 'true'
continue-on-error: true continue-on-error: true
run: | run: |
npm run lint:i18n npm run lint:i18n
# Only patch code when it is a push event # Only patch code when it is a push event
- name: Push the changes - name: Push the changes
if: github.event_name == 'push' if: github.event_name == 'push'
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
if ! git diff --exit-code --quiet; then if ! git diff --exit-code --quiet; then
git config --global user.name "github-actions" git config --global user.name "github-actions"
git config --global user.email "github-actions@users.noreply.github.com" git config --global user.email "github-actions@users.noreply.github.com"
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git add . git add .
git commit -am "ci: 👷 lint code to MediaWiki standards" -m "Check commit and GitHub actions for more details" git commit -am "ci: 👷 lint code to MediaWiki standards" -m "Check commit and GitHub actions for more details"
git pull --rebase git pull --rebase
git push git push
else else
echo "No changes to commit" echo "No changes to commit"
fi fi

18
.github/workflows/release-please.yml vendored Normal file
View file

@ -0,0 +1,18 @@
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.WORKFLOW_TOKEN }}