Skip to content

Commit

Permalink
Add GitHub Actions workflows for caching, dependency updates, linting…
Browse files Browse the repository at this point in the history
…, testing, security audits, and publishing to Packagist
  • Loading branch information
DaggieBlanqx committed Nov 18, 2024
1 parent 8345423 commit 8e3c087
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Cache Composer Dependencies

on: [push, pull_request]

jobs:
cache:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest
34 changes: 34 additions & 0 deletions .github/workflows/dependency-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Dependency Update

on:
schedule:
- cron: '0 3 * * 1' # Runs every Monday at 3:00 AM UTC

jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Update Dependencies
run: composer update --no-progress --no-suggest

- name: Commit Updated Dependencies
run: |
git config --local user.name "Daggie Douglas Mwangi
git config --local user.email "[email protected]"
git add composer.lock
git commit -m "Update Composer dependencies" || echo "No changes to commit"
- name: Push Changes
run: git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Install Composer Dependencies

on: [push, pull_request]

jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0' # Set the PHP version here

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Code Linting

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHP CodeSniffer
run: ./vendor/bin/phpcs --standard=PSR12 src/
39 changes: 39 additions & 0 deletions .github/workflows/packagist-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish SDK Package to Packagist

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
# Step 1: Check out the code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up PHP environment
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0' # Specify the PHP version

# Step 3: Install dependencies
- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction

# Step 4: Run tests (optional, but recommended)
- name: Run Tests
run: ./vendor/bin/phpunit
env:
APP_ENV: testing

# Step 5: Trigger Packagist Update
- name: Publish to Packagist
env:
PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }}
run: |
curl -X POST https://packagist.org/api/update-package?username=africastalking \
-H "Authorization: Bearer $PACKAGIST_TOKEN" \
-d '{"repository":{"url":"https://github.com/AfricasTalkingLtd/africastalking-php"}}'
21 changes: 21 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Security Audit

on: [push, pull_request, schedule]

jobs:
audit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install Composer Dependencies
run: composer install --no-scripts --no-progress --no-suggest

- name: Run Composer Security Audit
run: composer audit
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mbstring, xml # Add other extensions as needed

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPUnit Tests
run: ./vendor/bin/phpunit

0 comments on commit 8e3c087

Please sign in to comment.