Merge pull request #102 from kangketikonlen/dependabot/github_actions… #111
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | |
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@v4 | |
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 |