Skip to content

Commit

Permalink
ci: replace labeler with prepare workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
  • Loading branch information
feryardiant committed Feb 5, 2024
1 parent d81dcc6 commit c5ad62a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 46 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Prepare

on:
workflow_call:
outputs:
composer-cache:
value: ${{ jobs.configure.outputs.composer-cache }}
should-reports:
value: ${{ jobs.configure.outputs.should-reports }}

jobs:
configure:
name: Configure
runs-on: ubuntu-latest
outputs:
composer-cache: ${{ steps.prepare.outputs.composer-cache }}
should-reports: ${{ steps.prepare.outputs.should-reports }}

permissions:
contents: read
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Labeler
uses: actions/labeler@v5
with:
dot: true

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer:v2
coverage: none

- name: Prepare environment
id: prepare
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
git config user.name "Creasi.HQ" && git config user.email "dev@creasi.co"
echo "composer-cache=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "should-reports=$(if [[ -z \"${CC_TEST_REPORTER_ID}\" ]]; then echo '0'; else echo '1'; fi)" >> $GITHUB_OUTPUT
40 changes: 13 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,20 @@ env:
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
composer-cache: ${{ steps.prepare.outputs.composer-cache }}
enable-reports: ${{ steps.reports.outputs.enabled }}
uses: ./.github/workflows/prepare.yml
secrets: inherit

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare environment
id: prepare
run: |
git config user.name "Creasi.HQ" && git config user.email "dev@creasi.co"
echo "composer-cache=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Should have reports
id: reports
run: |
echo "enabled=$(if [[ -z \"${CC_TEST_REPORTER_ID}\" ]]; then echo '0'; else echo '1'; fi)" >> $GITHUB_OUTPUT
permissions:
contents: read
pull-requests: write

tests:
name: Test on PHP ${{ matrix.php }} with DB ${{ matrix.db }}
runs-on: ubuntu-latest
needs: prepare
outputs:
has-reports: ${{ steps.reports.outputs.has-reports }}

env:
DB_CONNECTION: ${{ matrix.db }}
DB_DATABASE: ${{ github.repository_owner }}
Expand Down Expand Up @@ -106,24 +90,26 @@ jobs:
run: composer test -- --coverage

- name: Generate reports for CodeClimate
if: ${{ github.actor != 'dependabot[bot]' }}
id: reports
if: ${{ github.actor != 'dependabot[bot]' || needs.prepare.outputs.should-reports == '1' }}
env:
COVERAGE_FILE: tests/reports/clover.xml
CODECLIMATE_REPORT: ${{ github.workspace }}/tests/reports/codeclimate.${{ matrix.php }}.json
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t clover -o $CODECLIMATE_REPORT $COVERAGE_FILE
echo "has-reports=1" >> $GITHUB_OUTPUT
- name: Upload tests reports
uses: actions/upload-artifact@v4
if: ${{ github.actor != 'dependabot[bot]' || needs.prepare.outputs.enable-reports }}
if: ${{ github.actor != 'dependabot[bot]' || needs.prepare.outputs.should-reports == '1' }}
with:
name: test-reports-${{ matrix.php }}-${{ matrix.db }}
path: tests/reports

reports:
name: Report Test Coverages
if: ${{ github.actor != 'dependabot[bot]' }}
if: ${{ github.actor != 'dependabot[bot]' && needs.tests.outputs.has-reports == '1' }}
runs-on: ubuntu-latest
needs: tests

Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/triage.yml

This file was deleted.

0 comments on commit c5ad62a

Please sign in to comment.