Skip to content

Merge pull request #101 from kangketikonlen/dependabot/composer/stabl… #110

Merge pull request #101 from kangketikonlen/dependabot/composer/stabl…

Merge pull request #101 from kangketikonlen/dependabot/composer/stabl… #110

Workflow file for this run

on:
push:
branches:
- "*"
- "!main"
name: πŸ”₯ Test Workflow
jobs:
setup:
name: πŸ› οΈ Set Up
runs-on: ubuntu-latest
steps:
- name: πŸ™ Git checkout
uses: actions/checkout@v4
- name: πŸ“ Make sure repository is latest
run: git fetch --prune --unshallow
- name: πŸ› οΈ Install dependencies
run: composer install --no-interaction
- name: πŸ“¦ Create vendor archive
run: zip -r vendor.zip vendor
- name: πŸ“¦ Upload vendor folder
uses: actions/upload-artifact@v3
with:
name: vendor
path: vendor.zip
phpstan:
needs: setup
name: 🚦 PHPStan analysis
runs-on: ubuntu-latest
steps:
- name: πŸ™ Git checkout
uses: actions/checkout@v4
- name: πŸ“¦ Download vendor folder
uses: actions/download-artifact@v3
with:
name: vendor
- name: πŸ“¦ Extract vendor archive
run: unzip vendor.zip
- name: 🚦 Analyze with PHPStan
run: composer phpstan
phpunit:
needs: setup
name: βœ… Run phpunit
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: testing
MYSQL_DATABASE: larapulse
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: πŸ™ Git checkout
uses: actions/checkout@v4
- name: πŸ“¦ Download vendor folder
uses: actions/download-artifact@v3
with:
name: vendor
- name: πŸ“¦ Extract vendor archive
run: unzip vendor.zip
- name: πŸ“‘ Set up php
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- name: πŸ“„ Create environment
run: cp .env.example .env
- name: πŸ”‘ Generate app key
run: php artisan key:generate
- name: πŸ’½ Running database migrate
run: php artisan migrate --env=testing
- name: 🌱 Run database seeder
run: php artisan db:seed --class='Database\Seeders\TestingSeeder' --env=testing
- name: πŸ—ΊοΈ Check routes
run: php artisan route:clear && php artisan route:list
- name: βœ… Run php tests
run: vendor/bin/phpunit
cleanup:
name: 🧹 Cleaning up artifact
runs-on: ubuntu-latest
needs: [setup, phpstan, phpunit]
steps:
- name: πŸ™ Git checkout
uses: actions/checkout@v4
- name: πŸ“¦ Delete vendor artifact
uses: geekyeggo/delete-artifact@v2
with:
name: vendor
tagging:
needs: [setup, phpstan, phpunit]
name: 🏷️ Tagging the app
runs-on: ubuntu-latest
steps:
- name: πŸ™ Git checkout
uses: actions/checkout@v4
- name: πŸ“ Make sure repository is latest
run: git fetch --prune --unshallow
- name: πŸ”– Create tag
uses: kangketikonlen/base-tagging@main
env:
REPO_NAME: ${{ github.event.repository.name }}
REPO_TYPE: ${{ github.event.repository.owner.type }}
REPO_OWNER: ${{ github.event.repository.owner.name }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
PRESERVE_VERSION: 5
create-pr:
needs: [setup, phpstan, phpunit, cleanup, tagging]
name: πŸ”„ Create Pull Request
runs-on: ubuntu-latest
environment: testing
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸš€ Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: πŸš€ Create PR
run: |
# Set up authentication
echo "${{ secrets.PERSONAL_TOKEN }}" >> token.txt
gh auth login --with-token < token.txt
rm -rf token.txt
# Get the current branch name
CURRENT_BRANCH=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
# Check if a pull request already exists
EXISTING_PR=$(gh pr list --state open --base main --head "${CURRENT_BRANCH}" --json number | jq -r '.[0].number')
# If a pull request exists, exit the workflow
if [[ "$EXISTING_PR" == null ]]; then
# Get the current date and time in the specified format
CURRENT_DATE=$(TZ='Asia/Jakarta' date +'%d-%m-%Y %H:%M')
# Create a pull request with date and time in the title
PR_TITLE="[$CURRENT_DATE] $CURRENT_BRANCH - Request merge $CURRENT_BRANCH to main branch"
gh pr create \
--base main \
--head "${CURRENT_BRANCH}" \
--title "${PR_TITLE}" \
--body "Automated pull request from ${CURRENT_BRANCH} to main branch"
else
echo "Pull request ${CURRENT_BRANCH} already exists ${EXISTING_PR}. Skipping PR creation."
exit 0
fi