Skip to content

Commit

Permalink
Qual: .github workflow must exist when included
Browse files Browse the repository at this point in the history
./.github/workflows/gh-travis.yml is included and inactive, but it
must exist for ci.yml.

To keep ci.yml the same accross versions, gh-travis.yml is included.
  • Loading branch information
mdeweerd committed Aug 13, 2024
1 parent 1bbccce commit eb97846
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: "CI"
on: [push, pull_request]
jobs:
pre-commit:
if: false
uses: ./.github/workflows/pre-commit.yml
secrets: inherit
with:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/gh-travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# This runs a travis script inside a github runner
name: Travis
# Controls when the workflow will run
on:
# push:
# pull_request:
workflow_call:
inputs:
gh_event:
required: true
type: string
workflow_dispatch:

concurrency:
group: travis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref
}}
cancel-in-progress: true
env:
gh_event: ${{ inputs.gh_event || github.event_name }}
GITHUB_JSON: ${{ toJSON(github) }} # Helps in debugging Github Action
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job
gh-travis:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: false
# matrix:
# php-version:
# # PHPStan requires PHP >= 7.2.
# #- "7.2"
# - "8.2"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout travis file
uses: actions/checkout@v4
- name: Run .travis.yml build script
uses: ktomk/run-travis-yml@v1
with:
# run-job: travis # name of a job in travis file
allow-failure: false
# file: .travis.yml
# steps: | # Default: setup, before_install, install, before_script, script, after_script, before_deploy
# install
# script
# env:
# TRAVIS_PHP_VERSION: ${{ matrix.php-version }}
Empty file removed .github/workflows/phan.yaml
Empty file.
58 changes: 58 additions & 0 deletions .github/workflows/phan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
on:
# pull_request:
# push:
# schedule:
# # execute once a day, the 1st
# - cron: 10 9 * * *
workflow_call:
inputs:
gh_event:
required: true
type: string
workflow_dispatch:

concurrency:
group: phan-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
gh_event: ${{ inputs.gh_event || github.event_name }}
PHAN_CONFIG: >
${{ 'dev/tools/phan/config.php' }}
PHAN_BASELINE: dev/tools/phan/baseline.txt
PHAN_MIN_PHP: 7.0
PHAN_QUICK: ${{ github.event.schedule && '' || '--quick' }}
GITHUB_JSON: ${{ toJSON(github) }} # Helps in debugging Github Action

name: phan
jobs:
phan:
name: Run phan
runs-on: ubuntu-latest
# Do not run schedule on forks
if: |
github.repository == 'Dolibarr/dolibarr'
|| github.event.schedule == false
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: none # disable xdebug, pcov
tools: cs2pr,phan
- name: Run Phan analysis
run: |
phan $PHAN_QUICK -k $PHAN_CONFIG -B $PHAN_BASELINE --analyze-twice --minimum-target-php-version $PHAN_MIN_PHP --output-mode=checkstyle -o _phan.xml
- name: Add results to PR
if: ${{ always() }}
run: |
cs2pr --prepend-filename --prepend-source --notices-as-warnings _phan.xml
- name: Provide phan log as artifact
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: phan-srcrt
# path: ${{ github.workspace }}/phan.log
path: ${{ github.workspace }}/_phan.xml
retention-days: 2
88 changes: 88 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# This is a basic workflow to check code with PHPSTAN tool
name: PHPStan
# Controls when the workflow will run
on:
# push:
# pull_request:
workflow_call:
inputs:
gh_event:
required: true
type: string
workflow_dispatch:

concurrency:
group: stan-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref
}}
cancel-in-progress: true
env:
gh_event: ${{ inputs.gh_event || github.event_name }}
CACHE_KEY_PART: ${{ ( inputs.gh_event == 'pull_request' || github.event_name == 'pull_request' ) && format('{0}-{1}', github.base_ref, github.head_ref) || github.ref_name }}
GITHUB_JSON: ${{ toJSON(github) }} # Helps in debugging Github Action
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job
php-stan:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
# PHPStan requires PHP >= 7.2.
#- "7.2"
- '8.2'
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Get PHP and addons
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpstan, cs2pr
extensions: calendar, json, imagick, gd, zip, mbstring, intl, opcache, imap,
mysql, pgsql, sqlite3, ldap, xml, mcrypt

# Restore old cache
- name: Restore phpstan cache
id: cache
uses: actions/cache/restore@v4
with:
path: ./.github/tmp
key: phpstan-cache-${{ matrix.php-version }}-${{ env.CACHE_KEY_PART }}-${{
github.run_id }}
restore-keys: |
phpstan-cache-${{ matrix.php-version }}-${{ env.CACHE_KEY_PART }}-
phpstan-cache-${{ matrix.php-version }}-${{ github.head_ref }}-
phpstan-cache-${{ matrix.php-version }}-${{ github.base_ref }}-
phpstan-cache-${{ matrix.php-version }}-
- name: Show debug into
run: cd ./.github/tmp && ls -al

# Run PHPStan
- name: Run PHPStan
id: phpstan
run: |
phpstan -vvv analyse --error-format=checkstyle --memory-limit 7G -a build/phpstan/bootstrap_action.php | tee _stan.xml | cs2pr --graceful-warnings
# continue-on-error: true

# Save cache
- name: Save phpstan cache
uses: actions/cache/save@v4
if: ${{ success() || ( ! cancelled() && steps.cache.outputs.cache-hit != 'true' ) }}
with:
path: ./.github/tmp
key: phpstan-cache-${{ matrix.php-version }}-${{ env.CACHE_KEY_PART }}-${{
github.run_id }}
- name: Provide phpstan log as artifact
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: phpstan-srcrt
path: ${{ github.workspace }}/_stan.xml
retention-days: 2
54 changes: 37 additions & 17 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
---
name: pre-commit
on:
pull_request:
push:
# pull_request:
# push:
workflow_call:
inputs:
gh_event:
required: true
type: string
workflow_dispatch:

concurrency:
group: pre-commit-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref
}}
cancel-in-progress: true
env:
gh_event: ${{ inputs.gh_event || github.event_name }}
jobs:
pre-commit:
runs-on: ubuntu-latest
Expand All @@ -15,11 +28,12 @@ jobs:
if: false

# The next uses the git API because there is no clone yet.
# It sets the variable steps.changed-php.outputs.all_changed_files for other steps
# This is faster for a big repo.
- name: Get all changed php files (if PR)
id: changed-php
uses: tj-actions/changed-files@v42
if: github.event_name == 'pull_request'
uses: tj-actions/changed-files@v44
if: env.gh_event == 'pull_request'
with:
files: |
**.php
Expand All @@ -37,12 +51,14 @@ jobs:
cache: pip
python-version: "3.11"
- run: python -m pip install pre-commit

# Restore previous cache of precommit
- uses: actions/cache/restore@v4
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
# Run all the precommit tools (defined into pre-commit-config.yaml).

# Run all the precommit tools (defined in pre-commit-config.yaml).
# We can force exclusion of some of them here.
- name: Run pre-commit hooks
env:
Expand All @@ -56,8 +72,8 @@ jobs:
# The next uses git, which is slow for a bit repo.
# - name: Get all changed php files (if PR)
# id: changed-php
# uses: tj-actions/changed-files@v42
# if: github.event_name == 'pull_request'
# uses: tj-actions/changed-files@v44
# if: env.gh_event == 'pull_request'
# with:
# files: |
# **.php
Expand All @@ -66,13 +82,16 @@ jobs:
uses: shivammathur/setup-php@v2
# Install when we're going to run phpcs
if: |
steps.changed-php.outputs.any_changed == 'true'
||
! cancelled() &&
(
github.event_name == 'push'
&& (
github.event.ref == 'refs/heads/develop'
|| endsWith(github.event.ref, '.0')
steps.changed-php.outputs.any_changed == 'true'
||
(
env.gh_event == 'push'
&& (
github.event.ref == 'refs/heads/develop'
|| endsWith(github.event.ref, '.0')
)
)
)
with:
Expand All @@ -81,7 +100,7 @@ jobs:
tools: phpcs

- name: Run some pre-commit hooks on selected changed files only
if: steps.changed-php.outputs.any_changed == 'true'
if: "! cancelled() && steps.changed-php.outputs.any_changed == 'true'"
env:
ALL_CHANGED_FILES: ${{ steps.changed-php.outputs.all_changed_files }}
run: |
Expand All @@ -90,7 +109,7 @@ jobs:
- name: Run some pre-commit hooks on all files on push to "main" branches
if: |
github.event_name == 'push'
env.gh_event == 'push'
&& (
github.event.ref == 'refs/heads/develop'
|| endsWith(github.event.ref, '.0')
Expand All @@ -99,10 +118,11 @@ jobs:
set -o pipefail
ln -sf ~/.cache .cache # Absolute path in .pre-commit-config.yaml
pre-commit run --hook-stage manual -a php-cs-with-cache | tee -a ${RAW_LOG}
# pre-commit run --hook-stage manual -a sqlfluff-lint | tee -a ${RAW_LOG}
ls -l ~/.cache/pre-commit/
- name: Convert Raw Log to Annotations
uses: mdeweerd/logToCheckStyle@v2024.2.9
uses: mdeweerd/logToCheckStyle@v2024.3.5
if: ${{ failure() }}
with:
in: ${{ env.RAW_LOG }}
Expand All @@ -122,4 +142,4 @@ jobs:
path: |
${{ env.RAW_LOG }}
${{ env.CS_XML }}
retention-days: 2
retention-days: 2
Loading

0 comments on commit eb97846

Please sign in to comment.