Skip to content

Commit

Permalink
Merge pull request #32 from KevinBatdorf/add-auto-discovery-ci-script
Browse files Browse the repository at this point in the history
Add auto discovery ci script
  • Loading branch information
jbrooksuk committed Oct 25, 2023
2 parents b8d8ca8 + dd07941 commit d7d1039
Showing 1 changed file with 44 additions and 59 deletions.
103 changes: 44 additions & 59 deletions .github/workflows/process-artisan-commands.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,66 @@
name: Process Artisan Commands

on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
schedule:
- cron: '0 0 * * 3'

jobs:
prepare:
name: Prepare manifest file

fetch_laravel_versions:
name: Fetch Latest Laravel Versions
runs-on: ubuntu-latest

strategy:
matrix:
laravel: [6, 7, 8, 9, 10]

outputs:
matrix: ${{ steps.fetch_versions.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v3

# - name: Import packages
# id: set-packages
# run: |
# packages=`cat ${{ github.workspace }}/manifest.json | jq --compact-output '. | {packages: (.packages | join(" "))}'`
# echo $packages
# echo "::set-output name=packages::$packages"

commands:
needs: prepare

name: Laravel Version ${{ matrix.laravel }}

- name: Get versions from Packagist
id: fetch_versions
run: |
# Fetch the latest Laravel versions from Packagist
# Convert to JSON e.g {v: "8", php: ">=7.3.0"}
# Extract the versions and their PHP requirements
# Remove duplicate lines based on the first column
# Remove v5.x versions as the putput breaks
# Get major v only, dedupe, and combine on one line
# Output the JSON to the step output
curl -s https://packagist.org/packages/laravel/laravel.json \
| jq -r '.package.versions[] | select(.require.php != null) | select(.version_normalized != null) | .version_normalized, .require.php' \
| sed -e '/dev/,+1d' -e '1~2 s/\..*//' -e '2~2 s/|.*$//' -e 's/[^0-9]*//' \
| cut -f1,2 -d'.' \
| awk 'NR%2{printf "%s ",$0;next;}1' \
| sort -Vru -k1,1 \
| sed '/^5 /d' \
| jq -Rcn '[inputs | split(" ") | {v:.[0], php:.[1]}]' \
| tee /tmp/versions.json
echo "matrix=$(cat /tmp/versions.json)" >> "$GITHUB_OUTPUT"
generate:
needs: fetch_laravel_versions
name: Laravel v${{ matrix.laravel.v }} - PHP ${{ matrix.laravel.php }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [7.4]
laravel: [6, 7, 8]
include:
- php: '8.0'
laravel: 9
- php: '8.1'
laravel: 10

matrix:
laravel: ${{ fromJson(needs.fetch_laravel_versions.outputs.matrix) }}
steps:
- name: Check out source code
- name: Check out code
uses: actions/checkout@v3

- name: Set up git user
run: |
git config --global user.name ${GITHUB_ACTOR}
git config --global user.email ${GITHUB_ACTOR}@users.noreply.github.com
- name: Setup PHP, with Composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: ${{ matrix.laravel.php }}
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2

- name: Install Laravel
run: composer create-project --no-progress laravel/laravel="^${{ matrix.laravel }}" /tmp/laravel
run: composer create-project --no-progress laravel/laravel="^${{ matrix.laravel.v }}" /tmp/laravel

# - name: Install Laravel packages
# run: |
# cd /tmp/laravel
# composer require --no-progress --no-interaction --ignore-platform-reqs ${{fromJson(needs.prepare.outputs.packages).packages}}
# continue-on-error: true

- name: Build Generator Command
- name: Run Generator Command
run: |
cd /tmp/laravel
cat ${{ github.workspace }}/build | php artisan tinker > /tmp/${{ matrix.laravel }}.x.json | true
- name: Configure Git Name
run: git config --global user.name ${GITHUB_ACTOR}

- name: Configure Git Email
run: git config --global user.email ${GITHUB_ACTOR}@users.noreply.github.com
cat ${{ github.workspace }}/build | php artisan tinker > /tmp/${{ matrix.laravel.v }}.x.json | true
- name: Commit comand files if needed #it fails if nothing has changed so we allow an error
run: |
Expand All @@ -88,11 +71,13 @@ jobs:
git reset --hard HEAD
git clean -f -d
git pull || true
cp /tmp/${{ matrix.laravel }}.x.json ./assets/
cp /tmp/${{ matrix.laravel.v }}.x.json ./assets/
git add -A || true
git commit -am 'Build Laravel version v${{ matrix.laravel }}' || true
git commit -am 'Build Laravel version v${{ matrix.laravel.v }}' || true
git push --force && break
n=$((n+1))
sleep 15
done
env:
matrix: ${{ needs.fetch_laravel_versions.outputs.matrix }}
continue-on-error: true

1 comment on commit d7d1039

@vercel
Copy link

@vercel vercel bot commented on d7d1039 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.